From 7214b98165649c1f6fac52e811186f605aa08586 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Tue, 20 Oct 2020 15:49:34 +0200 Subject: [PATCH 1/2] feat(c-api) Implement `wasm_memory_type`. --- lib/c-api/src/wasm_c_api/externals/memory.rs | 8 ++++---- lib/c-api/src/wasm_c_api/types/memory.rs | 16 +++++++++++----- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/lib/c-api/src/wasm_c_api/externals/memory.rs b/lib/c-api/src/wasm_c_api/externals/memory.rs index 2976f2e521b..e8982866999 100644 --- a/lib/c-api/src/wasm_c_api/externals/memory.rs +++ b/lib/c-api/src/wasm_c_api/externals/memory.rs @@ -25,16 +25,16 @@ pub unsafe extern "C" fn wasm_memory_delete(_memory: Option>) // TODO: figure out if these should be deep or shallow copies #[no_mangle] -pub unsafe extern "C" fn wasm_memory_copy(wasm_memory: &wasm_memory_t) -> Box { +pub unsafe extern "C" fn wasm_memory_copy(memory: &wasm_memory_t) -> Box { // do shallow copy Box::new(wasm_memory_t { - inner: wasm_memory.inner.clone(), + inner: memory.inner.clone(), }) } #[no_mangle] -pub unsafe extern "C" fn wasm_memory_type(_memory_ptr: &wasm_memory_t) -> *mut wasm_memorytype_t { - todo!("wasm_memory_type") +pub unsafe extern "C" fn wasm_memory_type(memory: &wasm_memory_t) -> Box { + Box::new(wasm_memorytype_t::new(memory.inner.ty().clone())) } // get a raw pointer into bytes diff --git a/lib/c-api/src/wasm_c_api/types/memory.rs b/lib/c-api/src/wasm_c_api/types/memory.rs index 9edd5bf37e5..43211ca9df8 100644 --- a/lib/c-api/src/wasm_c_api/types/memory.rs +++ b/lib/c-api/src/wasm_c_api/types/memory.rs @@ -18,6 +18,14 @@ impl wasm_memorytype_t { ); } } + + pub(crate) fn new(memory_type: MemoryType) -> Self { + Self { + extern_: wasm_externtype_t { + inner: ExternType::Memory(memory_type), + }, + } + } } wasm_declare_vec!(memorytype); @@ -42,11 +50,9 @@ pub unsafe extern "C" fn wasm_memorytype_new(limits: &wasm_limits_t) -> Box Date: Tue, 20 Oct 2020 15:51:38 +0200 Subject: [PATCH 2/2] doc(changelog) Add #1741. --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 767d6cbee26..d4511d11819 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ ### Added +- [#1741](https://github.com/wasmerio/wasmer/pull/1741) Implement `wasm_memory_type` in the Wasm C API. - [#1736](https://github.com/wasmerio/wasmer/pull/1736) Implement `wasm_global_type` in the Wasm C API. - [#1699](https://github.com/wasmerio/wasmer/pull/1699) Update `wasm.h` to its latest version. - [#1685](https://github.com/wasmerio/wasmer/pull/1685) Implement `wasm_exporttype_delete` in the Wasm C API.