diff --git a/examples/allocation/tinygo/testdata/greet.go b/examples/allocation/tinygo/testdata/greet.go index c74ad0f8..b0b0ed12 100644 --- a/examples/allocation/tinygo/testdata/greet.go +++ b/examples/allocation/tinygo/testdata/greet.go @@ -56,13 +56,14 @@ func _greeting(ptr, size uint32) (ptrSize uint64) { // ptrToString returns a string from WebAssembly compatible numeric types // representing its pointer and length. -func ptrToString(ptr uint32, size uint32) (ret string) { - // Here, we want to get a string represented by the ptr and size. If we - // wanted a []byte, we'd use reflect.SliceHeader instead. - strHdr := (*reflect.StringHeader)(unsafe.Pointer(&ret)) - strHdr.Data = uintptr(ptr) - strHdr.Len = uintptr(size) - return +func ptrToString(ptr uint32, size uint32) string { + // Get a slice view of the underlying bytes in the stream. We use SliceHeader, not StringHeader + // as it allows us to fix the capacity to what was allocated. + return *(*string)(unsafe.Pointer(&reflect.SliceHeader{ + Data: uintptr(ptr), + Len: uintptr(size), // Tinygo requires these as uintptrs even if they are int fields. + Cap: uintptr(size), // ^^ See https://github.com/tinygo-org/tinygo/issues/1284 + })) } // stringToPtr returns a pointer and size pair for the given string in a way diff --git a/examples/allocation/tinygo/testdata/greet.wasm b/examples/allocation/tinygo/testdata/greet.wasm index 0353986c..ae418c48 100755 Binary files a/examples/allocation/tinygo/testdata/greet.wasm and b/examples/allocation/tinygo/testdata/greet.wasm differ diff --git a/experimental/listener_test.go b/experimental/listener_test.go index 4a92f84c..d40a91f1 100644 --- a/experimental/listener_test.go +++ b/experimental/listener_test.go @@ -15,7 +15,7 @@ import ( // loggerFactory implements experimental.FunctionListenerFactory to log all function calls to the console. type loggerFactory struct{} -// Size implements the same method as documented on api.Memory. +// NewListener implements the same method as documented on experimental.FunctionListener. func (f *loggerFactory) NewListener(fnd experimental.FunctionDefinition) experimental.FunctionListener { return &logger{funcName: []byte(fnd.ModuleName() + "." + funcName(fnd))} }