Skip to content

Commit

Permalink
Add C API function to create module from engine instead of store
Browse files Browse the repository at this point in the history
  • Loading branch information
vapourismo committed Jul 17, 2023
1 parent bb79130 commit 886b6bf
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion lib/c-api/src/wasm_c_api/unstable/module.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
//! Unstable non-standard Wasmer-specific extensions to the Wasm C API.
use super::super::engine::wasm_engine_t;
use super::super::module::wasm_module_t;
use super::super::types::wasm_name_t;
use super::super::types::{wasm_byte_vec_t, wasm_name_t};
use std::ptr;
use std::str;
use wasmer_api::Module;

/// Unstable non-standard Wasmer-specific API to get the module's
/// name, otherwise `out->size` is set to `0` and `out->data` to
Expand Down Expand Up @@ -150,3 +152,30 @@ pub unsafe extern "C" fn wasmer_module_set_name(

module.inner.set_name(name)
}

/// A WebAssembly module contains stateless WebAssembly code that has
/// already been compiled and can be instantiated multiple times.
///
/// Creates a new WebAssembly Module using the provided engine,
/// respecting its configuration.
///
/// ## Security
///
/// Before the code is compiled, it will be validated using the engine
/// features.
///
/// # Example
///
/// See the module's documentation.
#[no_mangle]
pub unsafe extern "C" fn wasmer_module_new(
engine: Option<&mut wasm_engine_t>,
bytes: Option<&wasm_byte_vec_t>,
) -> Option<Box<wasm_module_t>> {
let engine: wasmer_api::Engine = engine?.inner.clone().into();
let bytes = bytes?;

let module = c_try!(Module::from_binary(&engine, bytes.as_slice()));

Some(Box::new(wasm_module_t { inner: module }))
}

0 comments on commit 886b6bf

Please sign in to comment.