diff --git a/lib/c-api/src/wasm_c_api/unstable/module.rs b/lib/c-api/src/wasm_c_api/unstable/module.rs index ed2e9b9c984..df938e4f742 100644 --- a/lib/c-api/src/wasm_c_api/unstable/module.rs +++ b/lib/c-api/src/wasm_c_api/unstable/module.rs @@ -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 @@ -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 given the configuration +/// in the engine. +/// +/// ## 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> { + 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 })) +}