Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add C API function to create Module from Engine instead of Store #4046

Merged
merged 1 commit into from
Jul 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 }))
}