mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-06 20:58:28 +00:00
feat(c-api) Update wasm_instance_new.
The `CArrayIter` type is no longer needed. This patch removes it.
This commit is contained in:
@@ -12,56 +12,21 @@ pub struct wasm_instance_t {
|
||||
pub(crate) inner: Arc<Instance>,
|
||||
}
|
||||
|
||||
struct CArrayIter<T: Sized + 'static> {
|
||||
cur_entry: *const *const T,
|
||||
}
|
||||
|
||||
impl<T: Sized + 'static> CArrayIter<T> {
|
||||
fn new(array: *const *const T) -> Option<Self> {
|
||||
if array.is_null() {
|
||||
None
|
||||
} else {
|
||||
Some(CArrayIter { cur_entry: array })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Sized + 'static> Iterator for CArrayIter<T> {
|
||||
type Item = &'static T;
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
let next_entry_candidate = unsafe { *self.cur_entry };
|
||||
if next_entry_candidate.is_null() {
|
||||
None
|
||||
} else {
|
||||
self.cur_entry = unsafe { self.cur_entry.add(1) };
|
||||
Some(unsafe { &*next_entry_candidate })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// reads from null-terminated array of `wasm_extern_t`s
|
||||
unsafe fn argument_import_iter(
|
||||
imports: *const *const wasm_extern_t,
|
||||
) -> Box<dyn Iterator<Item = &'static wasm_extern_t>> {
|
||||
CArrayIter::new(imports)
|
||||
.map(|it| Box::new(it) as _)
|
||||
.unwrap_or_else(|| Box::new(std::iter::empty()) as _)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wasm_instance_new(
|
||||
_store: &wasm_store_t,
|
||||
module: &wasm_module_t,
|
||||
imports: *const *const wasm_extern_t,
|
||||
imports: &wasm_extern_vec_t,
|
||||
// own
|
||||
_traps: *mut *mut wasm_trap_t,
|
||||
) -> Option<Box<wasm_instance_t>> {
|
||||
let wasm_module = &module.inner;
|
||||
let module_imports = wasm_module.imports();
|
||||
let module_import_count = module_imports.len();
|
||||
let imports = argument_import_iter(imports);
|
||||
let resolver: OrderedResolver = imports
|
||||
.into_slice()
|
||||
.map(|imports| imports.iter())
|
||||
.unwrap_or_else(|| [].iter())
|
||||
.map(|imp| &imp.inner)
|
||||
.take(module_import_count)
|
||||
.cloned()
|
||||
|
||||
Reference in New Issue
Block a user