wasmer_c_api/wasm_c_api/externals/
table.rs

1use super::super::store::wasm_store_t;
2use super::super::types::{wasm_ref_t, wasm_table_size_t, wasm_tabletype_t};
3use super::wasm_extern_t;
4use wasmer_api::Extern;
5
6#[allow(non_camel_case_types)]
7#[repr(C)]
8#[derive(Clone)]
9pub struct wasm_table_t {
10    pub(crate) extern_: wasm_extern_t,
11}
12
13impl wasm_table_t {
14    pub(crate) fn try_from(e: &wasm_extern_t) -> Option<&wasm_table_t> {
15        match &e.inner {
16            Extern::Table(_) => Some(unsafe { &*(e as *const _ as *const _) }),
17            _ => None,
18        }
19    }
20}
21
22#[unsafe(no_mangle)]
23pub unsafe extern "C" fn wasm_table_new(
24    _store: Option<&wasm_store_t>,
25    _table_type: Option<&wasm_tabletype_t>,
26    _init: *const wasm_ref_t,
27) -> Option<Box<wasm_table_t>> {
28    todo!("get val from init somehow");
29}
30
31#[unsafe(no_mangle)]
32pub unsafe extern "C" fn wasm_table_delete(_table: Option<Box<wasm_table_t>>) {}
33
34#[unsafe(no_mangle)]
35pub unsafe extern "C" fn wasm_table_copy(table: &wasm_table_t) -> Box<wasm_table_t> {
36    // do shallow copy
37    Box::new(table.clone())
38}
39
40#[unsafe(no_mangle)]
41pub unsafe extern "C" fn wasm_table_size(table: &wasm_table_t) -> usize {
42    let store_ref = unsafe { table.extern_.store.store() };
43    table.extern_.table().size(&store_ref) as _
44}
45
46#[unsafe(no_mangle)]
47pub unsafe extern "C" fn wasm_table_same(
48    wasm_table1: &wasm_table_t,
49    wasm_table2: &wasm_table_t,
50) -> bool {
51    wasm_table1.extern_.table() == wasm_table2.extern_.table()
52}
53
54#[unsafe(no_mangle)]
55pub unsafe extern "C" fn wasm_table_grow(
56    _table: &mut wasm_table_t,
57    _delta: wasm_table_size_t,
58    _init: *mut wasm_ref_t,
59) -> bool {
60    // TODO: maybe need to look at result to return `true`; also maybe report error here
61    //wasm_table.inner.grow(delta, init).is_ok()
62    todo!("Blocked on transforming ExternRef into a val type")
63}