diff --git a/CHANGELOG.md b/CHANGELOG.md index 57c4907378b..767d6cbee26 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ ### Added +- [#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. - [#1725](https://github.com/wasmerio/wasmer/pull/1725) Implement `wasm_func_type` in the Wasm C API. diff --git a/lib/c-api/src/wasm_c_api/externals/global.rs b/lib/c-api/src/wasm_c_api/externals/global.rs index aa04bf6f6e7..bf0837bd3d4 100644 --- a/lib/c-api/src/wasm_c_api/externals/global.rs +++ b/lib/c-api/src/wasm_c_api/externals/global.rs @@ -59,3 +59,8 @@ pub unsafe extern "C" fn wasm_global_same( ) -> bool { wasm_global1.inner.same(&wasm_global2.inner) } + +#[no_mangle] +pub extern "C" fn wasm_global_type(wasm_global: &wasm_global_t) -> Box { + Box::new(wasm_globaltype_t::new(wasm_global.inner.ty().clone())) +} diff --git a/lib/c-api/src/wasm_c_api/types/global.rs b/lib/c-api/src/wasm_c_api/types/global.rs index 78ed193f4b5..ee259650e45 100644 --- a/lib/c-api/src/wasm_c_api/types/global.rs +++ b/lib/c-api/src/wasm_c_api/types/global.rs @@ -20,6 +20,14 @@ impl wasm_globaltype_t { ); } } + + pub(crate) fn new(global_type: GlobalType) -> Self { + Self { + extern_: wasm_externtype_t { + inner: ExternType::Global(global_type), + }, + } + } } wasm_declare_vec!(globaltype); @@ -42,11 +50,10 @@ unsafe fn wasm_globaltype_new_inner( mutability: wasm_mutability_t, ) -> Option> { let me: wasm_mutability_enum = mutability.try_into().ok()?; - let gd = Box::new(wasm_globaltype_t { - extern_: wasm_externtype_t { - inner: ExternType::Global(GlobalType::new((*valtype).into(), me.into())), - }, - }); + let gd = Box::new(wasm_globaltype_t::new(GlobalType::new( + (*valtype).into(), + me.into(), + ))); wasm_valtype_delete(Some(valtype)); Some(gd)