MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime-go / stringToByteVec

Function stringToByteVec

ffi.go:52–58  ·  view source on GitHub ↗

# What's up with `ptr()` methods? We use `runtime.SetFinalizer` to free all objects we allocate from C. This is intended to make usage of the API much simpler since you don't have to close/free anything. The tricky part here though is laid out in `runtime.SetFinalizer`'s documentation which is that

(s string)

Source from the content-addressed store, hash-verified

50
51// Convert a Go string into an owned `wasm_byte_vec_t`
52func stringToByteVec(s string) C.wasm_byte_vec_t {
53 vec := C.wasm_byte_vec_t{}
54 C.wasm_byte_vec_new_uninitialized(&vec, C.size_t(len(s)))
55 C.memcpy(unsafe.Pointer(vec.data), unsafe.Pointer(C._GoStringPtr(s)), vec.size)
56 runtime.KeepAlive(s)
57 return vec
58}

Callers 2

NewImportTypeFunction · 0.85
NewExportTypeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…