MCPcopy Create free account
hub / github.com/bluejekyll/wasmtime-java / alloc_size

Method alloc_size

wasmtime-jni/src/ty/wasm_alloc.rs:70–88  ·  view source on GitHub ↗

Allocates size bytes in the Wasm Memory context, returns the offset into the Memory region

(
        &self,
        size: usize,
        store: impl AsContextMut,
    )

Source from the content-addressed store, hash-verified

68
69 /// Allocates size bytes in the Wasm Memory context, returns the offset into the Memory region
70 pub unsafe fn alloc_size(
71 &self,
72 size: usize,
73 store: impl AsContextMut,
74 ) -> Result<WasmSliceWrapper<'_>, Error> {
75 let len = size as i32;
76 let mut ptr = [Val::null(); 1];
77 self.alloc.call(store, &[Val::I32(len)], &mut ptr)?;
78
79 let ptr = ptr
80 .get(0)
81 .and_then(|v| v.i32())
82 .ok_or_else(|| anyhow!("i32 was not returned from the alloc"))?;
83
84 debug!("Allocated offset {} len {}", ptr, len);
85
86 let wasm_slice = WasmSlice::new(ptr, len);
87 Ok(WasmSliceWrapper::new(self, wasm_slice))
88 }
89
90 /// Allocates the bytes from the src bytes
91 pub fn alloc_bytes(

Callers 2

alloc_bytesMethod · 0.80
allocMethod · 0.80

Calls 3

I32Class · 0.85
callMethod · 0.80
i32Method · 0.80

Tested by

no test coverage detected