Skip to content

Commit c3e8a04

Browse files
authored
Merge pull request #2026 from yurydelendik/fix-c-module-new
Fix signature of wasmtime_module_new
2 parents 6a01b32 + a817470 commit c3e8a04

File tree

12 files changed

+20
-18
lines changed

12 files changed

+20
-18
lines changed

crates/c-api/include/wasmtime.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,7 @@ WASM_API_EXTERN own wasmtime_error_t *wasmtime_instance_new(
740740
* returned error and module are owned by the caller.
741741
*/
742742
WASM_API_EXTERN own wasmtime_error_t *wasmtime_module_new(
743-
wasm_store_t *store,
743+
wasm_engine_t *engine,
744744
const wasm_byte_vec_t *binary,
745745
own wasm_module_t **ret
746746
);

crates/c-api/src/module.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::{
2-
handle_result, wasm_byte_vec_t, wasm_exporttype_t, wasm_exporttype_vec_t, wasm_importtype_t,
3-
wasm_importtype_vec_t, wasm_store_t, wasmtime_error_t,
2+
handle_result, wasm_byte_vec_t, wasm_engine_t, wasm_exporttype_t, wasm_exporttype_vec_t,
3+
wasm_importtype_t, wasm_importtype_vec_t, wasm_store_t, wasmtime_error_t,
44
};
55
use std::ptr;
66
use wasmtime::{Engine, Module};
@@ -29,7 +29,10 @@ pub extern "C" fn wasm_module_new(
2929
binary: &wasm_byte_vec_t,
3030
) -> Option<Box<wasm_module_t>> {
3131
let mut ret = ptr::null_mut();
32-
match wasmtime_module_new(store, binary, &mut ret) {
32+
let engine = wasm_engine_t {
33+
engine: store.store.engine().clone(),
34+
};
35+
match wasmtime_module_new(&engine, binary, &mut ret) {
3336
Some(_err) => None,
3437
None => {
3538
assert!(!ret.is_null());
@@ -40,13 +43,12 @@ pub extern "C" fn wasm_module_new(
4043

4144
#[no_mangle]
4245
pub extern "C" fn wasmtime_module_new(
43-
store: &wasm_store_t,
46+
engine: &wasm_engine_t,
4447
binary: &wasm_byte_vec_t,
4548
ret: &mut *mut wasm_module_t,
4649
) -> Option<Box<wasmtime_error_t>> {
4750
let binary = binary.as_slice();
48-
let store = &store.store;
49-
handle_result(Module::from_binary(store.engine(), binary), |module| {
51+
handle_result(Module::from_binary(&engine.engine, binary), |module| {
5052
let imports = module
5153
.imports()
5254
.map(|i| wasm_importtype_t::new(i.module().to_owned(), i.name().to_owned(), i.ty()))

examples/externref.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ int main() {
6666
// Now that we've got our binary webassembly we can compile our module.
6767
printf("Compiling module...\n");
6868
wasm_module_t *module = NULL;
69-
error = wasmtime_module_new(store, &wasm, &module);
69+
error = wasmtime_module_new(engine, &wasm, &module);
7070
wasm_byte_vec_delete(&wasm);
7171
if (error != NULL)
7272
exit_with_error("failed to compile module", error, NULL);

examples/fib-debug/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ int main(int argc, const char* argv[]) {
4343
// Compile.
4444
printf("Compiling module...\n");
4545
wasm_module_t *module = NULL;
46-
wasmtime_error_t* error = wasmtime_module_new(store, &binary, &module);
46+
wasmtime_error_t* error = wasmtime_module_new(engine, &binary, &module);
4747
if (!module)
4848
exit_with_error("failed to compile module", error, NULL);
4949
wasm_byte_vec_delete(&binary);

examples/gcd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ int main() {
5959

6060
// Compile and instantiate our module
6161
wasm_module_t *module = NULL;
62-
error = wasmtime_module_new(store, &wasm, &module);
62+
error = wasmtime_module_new(engine, &wasm, &module);
6363
if (module == NULL)
6464
exit_with_error("failed to compile module", error, NULL);
6565
wasm_byte_vec_delete(&wasm);

examples/hello.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ int main() {
6767
// Now that we've got our binary webassembly we can compile our module.
6868
printf("Compiling module...\n");
6969
wasm_module_t *module = NULL;
70-
error = wasmtime_module_new(store, &wasm, &module);
70+
error = wasmtime_module_new(engine, &wasm, &module);
7171
wasm_byte_vec_delete(&wasm);
7272
if (error != NULL)
7373
exit_with_error("failed to compile module", error, NULL);

examples/hello.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ int main() {
6767
// Now that we've got our binary webassembly we can compile our module.
6868
printf("Compiling module...\n");
6969
wasm_module_t *module = NULL;
70-
error = wasmtime_module_new(store, &wasm, &module);
70+
error = wasmtime_module_new(engine, &wasm, &module);
7171
wasm_byte_vec_delete(&wasm);
7272
if (error != NULL)
7373
exit_with_error("failed to compile module", error, NULL);

examples/interrupt.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ int main() {
8989
wasm_module_t *module = NULL;
9090
wasm_trap_t *trap = NULL;
9191
wasm_instance_t *instance = NULL;
92-
error = wasmtime_module_new(store, &wasm, &module);
92+
error = wasmtime_module_new(engine, &wasm, &module);
9393
wasm_byte_vec_delete(&wasm);
9494
if (error != NULL)
9595
exit_with_error("failed to compile module", error, NULL);

examples/linking.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ int main() {
4545
wasmtime_error_t *error;
4646
wasm_module_t *linking1_module = NULL;
4747
wasm_module_t *linking2_module = NULL;
48-
error = wasmtime_module_new(store, &linking1_wasm, &linking1_module);
48+
error = wasmtime_module_new(engine, &linking1_wasm, &linking1_module);
4949
if (error != NULL)
5050
exit_with_error("failed to compile linking1", error, NULL);
51-
error = wasmtime_module_new(store, &linking2_wasm, &linking2_module);
51+
error = wasmtime_module_new(engine, &linking2_wasm, &linking2_module);
5252
if (error != NULL)
5353
exit_with_error("failed to compile linking2", error, NULL);
5454
wasm_byte_vec_delete(&linking1_wasm);

examples/memory.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ int main(int argc, const char* argv[]) {
158158
// Compile.
159159
printf("Compiling module...\n");
160160
wasm_module_t* module = NULL;
161-
error = wasmtime_module_new(store, &binary, &module);
161+
error = wasmtime_module_new(engine, &binary, &module);
162162
if (error)
163163
exit_with_error("failed to compile module", error, NULL);
164164
wasm_byte_vec_delete(&binary);

examples/multi.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ int main(int argc, const char* argv[]) {
9191
// Compile.
9292
printf("Compiling module...\n");
9393
wasm_module_t* module = NULL;
94-
error = wasmtime_module_new(store, &binary, &module);
94+
error = wasmtime_module_new(engine, &binary, &module);
9595
if (error)
9696
exit_with_error("failed to compile module", error, NULL);
9797

examples/wasi/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ int main() {
5454

5555
// Compile our modules
5656
wasm_module_t *module = NULL;
57-
wasmtime_error_t *error = wasmtime_module_new(store, &wasm, &module);
57+
wasmtime_error_t *error = wasmtime_module_new(engine, &wasm, &module);
5858
if (!module)
5959
exit_with_error("failed to compile module", error, NULL);
6060
wasm_byte_vec_delete(&wasm);

0 commit comments

Comments
 (0)