-
Notifications
You must be signed in to change notification settings - Fork 824
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1709: feat(c-api) Implement `wasm_module_name` and `wasm_module_set_name` r=Hywan a=Hywan Until my official proposal made here, WebAssembly/wasm-c-api#157 is accepted or rejected, I implement those functions as “wasmer-specific” API. Co-authored-by: Ivan Enderlin <[email protected]>
- Loading branch information
Showing
4 changed files
with
43 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,42 @@ | ||
//! Wasmer-specific extensions to the Wasm C API. | ||
use crate::wasm_c_api::instance::wasm_instance_t; | ||
use super::instance::wasm_instance_t; | ||
use super::module::wasm_module_t; | ||
use super::types::wasm_name_t; | ||
use std::ffi::c_void; | ||
use std::str; | ||
use std::sync::Arc; | ||
|
||
#[no_mangle] | ||
pub unsafe extern "C" fn wasm_instance_get_vmctx_ptr(instance: &wasm_instance_t) -> *mut c_void { | ||
instance.inner.vmctx_ptr() as _ | ||
} | ||
|
||
#[no_mangle] | ||
pub unsafe extern "C" fn wasm_module_name(module: &wasm_module_t, out: &mut wasm_name_t) { | ||
let name = match module.inner.name() { | ||
Some(name) => name, | ||
None => return, | ||
}; | ||
|
||
*out = name.as_bytes().to_vec().into(); | ||
} | ||
|
||
#[no_mangle] | ||
pub unsafe extern "C" fn wasm_module_set_name( | ||
module: &mut wasm_module_t, | ||
name: &wasm_name_t, | ||
) -> bool { | ||
let name = match name.into_slice() { | ||
Some(name) => match str::from_utf8(name) { | ||
Ok(name) => name, | ||
Err(_) => return false, // not ideal! | ||
}, | ||
None => return false, | ||
}; | ||
|
||
match Arc::get_mut(&mut module.inner) { | ||
Some(module) => module.set_name(name), | ||
None => false, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters