Browse Source

Merge pull request #2026 from yurydelendik/fix-c-module-new

Fix signature of wasmtime_module_new
pull/2028/head
Nick Fitzgerald 4 years ago
committed by GitHub
parent
commit
c3e8a04c90
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      crates/c-api/include/wasmtime.h
  2. 14
      crates/c-api/src/module.rs
  3. 2
      examples/externref.c
  4. 2
      examples/fib-debug/main.c
  5. 2
      examples/gcd.c
  6. 2
      examples/hello.c
  7. 2
      examples/hello.cc
  8. 2
      examples/interrupt.c
  9. 4
      examples/linking.c
  10. 2
      examples/memory.c
  11. 2
      examples/multi.c
  12. 2
      examples/wasi/main.c

2
crates/c-api/include/wasmtime.h

@ -740,7 +740,7 @@ WASM_API_EXTERN own wasmtime_error_t *wasmtime_instance_new(
* returned error and module are owned by the caller. * returned error and module are owned by the caller.
*/ */
WASM_API_EXTERN own wasmtime_error_t *wasmtime_module_new( WASM_API_EXTERN own wasmtime_error_t *wasmtime_module_new(
wasm_store_t *store, wasm_engine_t *engine,
const wasm_byte_vec_t *binary, const wasm_byte_vec_t *binary,
own wasm_module_t **ret own wasm_module_t **ret
); );

14
crates/c-api/src/module.rs

@ -1,6 +1,6 @@
use crate::{ use crate::{
handle_result, wasm_byte_vec_t, wasm_exporttype_t, wasm_exporttype_vec_t, wasm_importtype_t, handle_result, wasm_byte_vec_t, wasm_engine_t, wasm_exporttype_t, wasm_exporttype_vec_t,
wasm_importtype_vec_t, wasm_store_t, wasmtime_error_t, wasm_importtype_t, wasm_importtype_vec_t, wasm_store_t, wasmtime_error_t,
}; };
use std::ptr; use std::ptr;
use wasmtime::{Engine, Module}; use wasmtime::{Engine, Module};
@ -29,7 +29,10 @@ pub extern "C" fn wasm_module_new(
binary: &wasm_byte_vec_t, binary: &wasm_byte_vec_t,
) -> Option<Box<wasm_module_t>> { ) -> Option<Box<wasm_module_t>> {
let mut ret = ptr::null_mut(); let mut ret = ptr::null_mut();
match wasmtime_module_new(store, binary, &mut ret) { let engine = wasm_engine_t {
engine: store.store.engine().clone(),
};
match wasmtime_module_new(&engine, binary, &mut ret) {
Some(_err) => None, Some(_err) => None,
None => { None => {
assert!(!ret.is_null()); assert!(!ret.is_null());
@ -40,13 +43,12 @@ pub extern "C" fn wasm_module_new(
#[no_mangle] #[no_mangle]
pub extern "C" fn wasmtime_module_new( pub extern "C" fn wasmtime_module_new(
store: &wasm_store_t, engine: &wasm_engine_t,
binary: &wasm_byte_vec_t, binary: &wasm_byte_vec_t,
ret: &mut *mut wasm_module_t, ret: &mut *mut wasm_module_t,
) -> Option<Box<wasmtime_error_t>> { ) -> Option<Box<wasmtime_error_t>> {
let binary = binary.as_slice(); let binary = binary.as_slice();
let store = &store.store; handle_result(Module::from_binary(&engine.engine, binary), |module| {
handle_result(Module::from_binary(store.engine(), binary), |module| {
let imports = module let imports = module
.imports() .imports()
.map(|i| wasm_importtype_t::new(i.module().to_owned(), i.name().to_owned(), i.ty())) .map(|i| wasm_importtype_t::new(i.module().to_owned(), i.name().to_owned(), i.ty()))

2
examples/externref.c

@ -66,7 +66,7 @@ int main() {
// Now that we've got our binary webassembly we can compile our module. // Now that we've got our binary webassembly we can compile our module.
printf("Compiling module...\n"); printf("Compiling module...\n");
wasm_module_t *module = NULL; wasm_module_t *module = NULL;
error = wasmtime_module_new(store, &wasm, &module); error = wasmtime_module_new(engine, &wasm, &module);
wasm_byte_vec_delete(&wasm); wasm_byte_vec_delete(&wasm);
if (error != NULL) if (error != NULL)
exit_with_error("failed to compile module", error, NULL); exit_with_error("failed to compile module", error, NULL);

2
examples/fib-debug/main.c

@ -43,7 +43,7 @@ int main(int argc, const char* argv[]) {
// Compile. // Compile.
printf("Compiling module...\n"); printf("Compiling module...\n");
wasm_module_t *module = NULL; wasm_module_t *module = NULL;
wasmtime_error_t* error = wasmtime_module_new(store, &binary, &module); wasmtime_error_t* error = wasmtime_module_new(engine, &binary, &module);
if (!module) if (!module)
exit_with_error("failed to compile module", error, NULL); exit_with_error("failed to compile module", error, NULL);
wasm_byte_vec_delete(&binary); wasm_byte_vec_delete(&binary);

2
examples/gcd.c

@ -59,7 +59,7 @@ int main() {
// Compile and instantiate our module // Compile and instantiate our module
wasm_module_t *module = NULL; wasm_module_t *module = NULL;
error = wasmtime_module_new(store, &wasm, &module); error = wasmtime_module_new(engine, &wasm, &module);
if (module == NULL) if (module == NULL)
exit_with_error("failed to compile module", error, NULL); exit_with_error("failed to compile module", error, NULL);
wasm_byte_vec_delete(&wasm); wasm_byte_vec_delete(&wasm);

2
examples/hello.c

@ -67,7 +67,7 @@ int main() {
// Now that we've got our binary webassembly we can compile our module. // Now that we've got our binary webassembly we can compile our module.
printf("Compiling module...\n"); printf("Compiling module...\n");
wasm_module_t *module = NULL; wasm_module_t *module = NULL;
error = wasmtime_module_new(store, &wasm, &module); error = wasmtime_module_new(engine, &wasm, &module);
wasm_byte_vec_delete(&wasm); wasm_byte_vec_delete(&wasm);
if (error != NULL) if (error != NULL)
exit_with_error("failed to compile module", error, NULL); exit_with_error("failed to compile module", error, NULL);

2
examples/hello.cc

@ -67,7 +67,7 @@ int main() {
// Now that we've got our binary webassembly we can compile our module. // Now that we've got our binary webassembly we can compile our module.
printf("Compiling module...\n"); printf("Compiling module...\n");
wasm_module_t *module = NULL; wasm_module_t *module = NULL;
error = wasmtime_module_new(store, &wasm, &module); error = wasmtime_module_new(engine, &wasm, &module);
wasm_byte_vec_delete(&wasm); wasm_byte_vec_delete(&wasm);
if (error != NULL) if (error != NULL)
exit_with_error("failed to compile module", error, NULL); exit_with_error("failed to compile module", error, NULL);

2
examples/interrupt.c

@ -89,7 +89,7 @@ int main() {
wasm_module_t *module = NULL; wasm_module_t *module = NULL;
wasm_trap_t *trap = NULL; wasm_trap_t *trap = NULL;
wasm_instance_t *instance = NULL; wasm_instance_t *instance = NULL;
error = wasmtime_module_new(store, &wasm, &module); error = wasmtime_module_new(engine, &wasm, &module);
wasm_byte_vec_delete(&wasm); wasm_byte_vec_delete(&wasm);
if (error != NULL) if (error != NULL)
exit_with_error("failed to compile module", error, NULL); exit_with_error("failed to compile module", error, NULL);

4
examples/linking.c

@ -45,10 +45,10 @@ int main() {
wasmtime_error_t *error; wasmtime_error_t *error;
wasm_module_t *linking1_module = NULL; wasm_module_t *linking1_module = NULL;
wasm_module_t *linking2_module = NULL; wasm_module_t *linking2_module = NULL;
error = wasmtime_module_new(store, &linking1_wasm, &linking1_module); error = wasmtime_module_new(engine, &linking1_wasm, &linking1_module);
if (error != NULL) if (error != NULL)
exit_with_error("failed to compile linking1", error, NULL); exit_with_error("failed to compile linking1", error, NULL);
error = wasmtime_module_new(store, &linking2_wasm, &linking2_module); error = wasmtime_module_new(engine, &linking2_wasm, &linking2_module);
if (error != NULL) if (error != NULL)
exit_with_error("failed to compile linking2", error, NULL); exit_with_error("failed to compile linking2", error, NULL);
wasm_byte_vec_delete(&linking1_wasm); wasm_byte_vec_delete(&linking1_wasm);

2
examples/memory.c

@ -158,7 +158,7 @@ int main(int argc, const char* argv[]) {
// Compile. // Compile.
printf("Compiling module...\n"); printf("Compiling module...\n");
wasm_module_t* module = NULL; wasm_module_t* module = NULL;
error = wasmtime_module_new(store, &binary, &module); error = wasmtime_module_new(engine, &binary, &module);
if (error) if (error)
exit_with_error("failed to compile module", error, NULL); exit_with_error("failed to compile module", error, NULL);
wasm_byte_vec_delete(&binary); wasm_byte_vec_delete(&binary);

2
examples/multi.c

@ -91,7 +91,7 @@ int main(int argc, const char* argv[]) {
// Compile. // Compile.
printf("Compiling module...\n"); printf("Compiling module...\n");
wasm_module_t* module = NULL; wasm_module_t* module = NULL;
error = wasmtime_module_new(store, &binary, &module); error = wasmtime_module_new(engine, &binary, &module);
if (error) if (error)
exit_with_error("failed to compile module", error, NULL); exit_with_error("failed to compile module", error, NULL);

2
examples/wasi/main.c

@ -54,7 +54,7 @@ int main() {
// Compile our modules // Compile our modules
wasm_module_t *module = NULL; wasm_module_t *module = NULL;
wasmtime_error_t *error = wasmtime_module_new(store, &wasm, &module); wasmtime_error_t *error = wasmtime_module_new(engine, &wasm, &module);
if (!module) if (!module)
exit_with_error("failed to compile module", error, NULL); exit_with_error("failed to compile module", error, NULL);
wasm_byte_vec_delete(&wasm); wasm_byte_vec_delete(&wasm);

Loading…
Cancel
Save