Skip to content

Commit a1ccfe2

Browse files
bors[bot]jubianchi
andauthored
Merge #1736
1736: feat(c-api): Implement `wasm_global_type` r=Hywan a=jubianchi This patch adds a `wasm_globaltype_t::new` constructor for use by the new `wasm_global_type` function and the existing `wasm_globaltype_new_inner` function. Note: `wasm_global_type` is defined here: https://github.com/wasmerio/wasmer/blob/193d7c8ce1b744e6078269ac7a77dd53d1e4cbd6/lib/c-api/tests/wasm_c_api/wasm-c-api/include/wasm.h#L436 # Review - [x] Add a short description of the the change to the CHANGELOG.md file Co-authored-by: jubianchi <[email protected]>
2 parents a20d215 + 5c26a81 commit a1ccfe2

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
### Added
1111

12+
- [#1736](https://github.com/wasmerio/wasmer/pull/1736) Implement `wasm_global_type` in the Wasm C API.
1213
- [#1699](https://github.com/wasmerio/wasmer/pull/1699) Update `wasm.h` to its latest version.
1314
- [#1685](https://github.com/wasmerio/wasmer/pull/1685) Implement `wasm_exporttype_delete` in the Wasm C API.
1415
- [#1725](https://github.com/wasmerio/wasmer/pull/1725) Implement `wasm_func_type` in the Wasm C API.

lib/c-api/src/wasm_c_api/externals/global.rs

+5
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,8 @@ pub unsafe extern "C" fn wasm_global_same(
5959
) -> bool {
6060
wasm_global1.inner.same(&wasm_global2.inner)
6161
}
62+
63+
#[no_mangle]
64+
pub extern "C" fn wasm_global_type(wasm_global: &wasm_global_t) -> Box<wasm_globaltype_t> {
65+
Box::new(wasm_globaltype_t::new(wasm_global.inner.ty().clone()))
66+
}

lib/c-api/src/wasm_c_api/types/global.rs

+12-5
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ impl wasm_globaltype_t {
2020
);
2121
}
2222
}
23+
24+
pub(crate) fn new(global_type: GlobalType) -> Self {
25+
Self {
26+
extern_: wasm_externtype_t {
27+
inner: ExternType::Global(global_type),
28+
},
29+
}
30+
}
2331
}
2432

2533
wasm_declare_vec!(globaltype);
@@ -42,11 +50,10 @@ unsafe fn wasm_globaltype_new_inner(
4250
mutability: wasm_mutability_t,
4351
) -> Option<Box<wasm_globaltype_t>> {
4452
let me: wasm_mutability_enum = mutability.try_into().ok()?;
45-
let gd = Box::new(wasm_globaltype_t {
46-
extern_: wasm_externtype_t {
47-
inner: ExternType::Global(GlobalType::new((*valtype).into(), me.into())),
48-
},
49-
});
53+
let gd = Box::new(wasm_globaltype_t::new(GlobalType::new(
54+
(*valtype).into(),
55+
me.into(),
56+
)));
5057
wasm_valtype_delete(Some(valtype));
5158

5259
Some(gd)

0 commit comments

Comments
 (0)