Allocates size bytes in the Wasm Memory context, returns the offset into the Memory region
(
&self,
size: usize,
store: impl AsContextMut,
)
| 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( |
no test coverage detected