Skip to content

Commit 74769e3

Browse files
committed
address review feedback
Signed-off-by: Joel Dice <joel.dice@fermyon.com>
1 parent 5771bb3 commit 74769e3

File tree

2 files changed

+11
-14
lines changed

2 files changed

+11
-14
lines changed

crates/go/src/wit_future.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,16 @@ func (f *FutureReader[T]) Read() T {
4242
code, _ := wit_async.FutureOrStreamWait(f.vtable.Read(handle, buffer), handle)
4343

4444
switch code {
45-
case wit_async.RETURN_CODE_COMPLETED, wit_async.RETURN_CODE_DROPPED:
45+
case wit_async.RETURN_CODE_COMPLETED:
4646
if f.vtable.Lift == nil {
4747
return unsafe.Slice((*T)(buffer), 1)[0]
4848
} else {
4949
return f.vtable.Lift(buffer)
5050
}
5151

52+
case wit_async.RETURN_CODE_DROPPED:
53+
panic("unreachable")
54+
5255
default:
5356
panic("todo: handle cancellation")
5457
}

crates/go/src/wit_runtime.go

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,30 +12,24 @@ func Allocate(pinner *runtime.Pinner, size, align uintptr) unsafe.Pointer {
1212
return pointer
1313
}
1414

15-
func ceiling(n, d uintptr) uintptr {
16-
var hasRemainder uintptr
17-
if n%d == 0 {
18-
hasRemainder = 0
19-
} else {
20-
hasRemainder = 1
21-
}
22-
return n/d + hasRemainder
23-
}
24-
2515
func allocateRaw(size, align uintptr) unsafe.Pointer {
2616
if size == 0 {
2717
return unsafe.Pointer(uintptr(0))
2818
}
2919

20+
if size%align != 0 {
21+
panic(fmt.Sprintf("size %v is not compatible with alignment %v", size, align))
22+
}
23+
3024
switch align {
3125
case 1:
3226
return unsafe.Pointer(unsafe.SliceData(make([]uint8, size)))
3327
case 2:
34-
return unsafe.Pointer(unsafe.SliceData(make([]uint16, ceiling(size, align))))
28+
return unsafe.Pointer(unsafe.SliceData(make([]uint16, size/align)))
3529
case 4:
36-
return unsafe.Pointer(unsafe.SliceData(make([]uint32, ceiling(size, align))))
30+
return unsafe.Pointer(unsafe.SliceData(make([]uint32, size/align)))
3731
case 8:
38-
return unsafe.Pointer(unsafe.SliceData(make([]uint64, ceiling(size, align))))
32+
return unsafe.Pointer(unsafe.SliceData(make([]uint64, size/align)))
3933
default:
4034
panic(fmt.Sprintf("unsupported alignment: %v", align))
4135
}

0 commit comments

Comments
 (0)