mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-08 05:38:19 +00:00
feat(c-api) Instruct cbindgen to ignore all functions and types defined in wasm.h.
This commit is contained in:
@@ -3,18 +3,21 @@ use std::sync::Arc;
|
||||
use wasmer::Engine;
|
||||
|
||||
/// this can be a wasmer-specific type with wasmer-specific functions for manipulating it
|
||||
#[repr(C)]
|
||||
///
|
||||
/// cbindgen:ignore
|
||||
#[allow(non_camel_case_types)]
|
||||
pub struct wasm_config_t {}
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wasm_config_new() -> *mut wasm_config_t {
|
||||
todo!("wasm_config_new")
|
||||
//ptr::null_mut()
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
pub struct wasm_engine_t {
|
||||
/// cbindgen:ignore
|
||||
#[allow(non_camel_case_types)]
|
||||
pub struct wasm_engine_t {
|
||||
pub(crate) inner: Arc<dyn Engine + Send + Sync>,
|
||||
}
|
||||
|
||||
@@ -36,6 +39,7 @@ cfg_if! {
|
||||
}
|
||||
}
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wasm_engine_new() -> Box<wasm_engine_t> {
|
||||
let compiler_config: Box<dyn CompilerConfig> = get_default_compiler_config();
|
||||
@@ -45,6 +49,7 @@ cfg_if! {
|
||||
}
|
||||
else if #[cfg(feature = "jit")] {
|
||||
// Headless JIT
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wasm_engine_new() -> Box<wasm_engine_t> {
|
||||
let engine: Arc<dyn Engine + Send + Sync> = Arc::new(JIT::headless().engine());
|
||||
@@ -52,6 +57,7 @@ cfg_if! {
|
||||
}
|
||||
}
|
||||
else {
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wasm_engine_new() -> Box<wasm_engine_t> {
|
||||
unimplemented!("The JITEngine is not attached");
|
||||
@@ -59,9 +65,11 @@ cfg_if! {
|
||||
}
|
||||
}
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wasm_engine_delete(_wasm_engine_address: Option<Box<wasm_engine_t>>) {}
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wasm_engine_new_with_config(
|
||||
_config_ptr: *mut wasm_config_t,
|
||||
|
||||
14
lib/c-api/src/wasm_c_api/externals/function.rs
vendored
14
lib/c-api/src/wasm_c_api/externals/function.rs
vendored
@@ -8,19 +8,20 @@ use std::ptr::NonNull;
|
||||
use std::sync::Arc;
|
||||
use wasmer::{Function, Instance, RuntimeError, Store, Val};
|
||||
|
||||
#[repr(C)]
|
||||
/// cbindgen:ignore
|
||||
#[allow(non_camel_case_types)]
|
||||
pub struct wasm_func_t {
|
||||
/// cbindgen:ignore
|
||||
pub(crate) inner: Function,
|
||||
/// cbindgen:ignore
|
||||
// this is how we ensure the instance stays alive
|
||||
pub(crate) instance: Option<Arc<Instance>>,
|
||||
}
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[allow(non_camel_case_types)]
|
||||
pub type wasm_func_callback_t =
|
||||
unsafe extern "C" fn(args: *const wasm_val_t, results: *mut wasm_val_t) -> *mut wasm_trap_t;
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[allow(non_camel_case_types)]
|
||||
pub type wasm_func_callback_with_env_t = unsafe extern "C" fn(
|
||||
*mut c_void,
|
||||
@@ -28,9 +29,11 @@ pub type wasm_func_callback_with_env_t = unsafe extern "C" fn(
|
||||
results: *mut wasm_val_t,
|
||||
) -> *mut wasm_trap_t;
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[allow(non_camel_case_types)]
|
||||
pub type wasm_env_finalizer_t = unsafe extern "C" fn(c_void);
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wasm_func_new(
|
||||
store: Option<NonNull<wasm_store_t>>,
|
||||
@@ -74,6 +77,7 @@ pub unsafe extern "C" fn wasm_func_new(
|
||||
}))
|
||||
}
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wasm_func_new_with_env(
|
||||
store: Option<NonNull<wasm_store_t>>,
|
||||
@@ -120,9 +124,11 @@ pub unsafe extern "C" fn wasm_func_new_with_env(
|
||||
}))
|
||||
}
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wasm_func_delete(_func: Option<Box<wasm_func_t>>) {}
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wasm_func_call(
|
||||
func: &wasm_func_t,
|
||||
@@ -147,11 +153,13 @@ pub unsafe extern "C" fn wasm_func_call(
|
||||
}
|
||||
}
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wasm_func_param_arity(func: &wasm_func_t) -> usize {
|
||||
func.inner.ty().params().len()
|
||||
}
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wasm_func_result_arity(func: &wasm_func_t) -> usize {
|
||||
func.inner.ty().results().len()
|
||||
|
||||
10
lib/c-api/src/wasm_c_api/externals/global.rs
vendored
10
lib/c-api/src/wasm_c_api/externals/global.rs
vendored
@@ -5,13 +5,14 @@ use std::convert::TryInto;
|
||||
use std::ptr::NonNull;
|
||||
use wasmer::{Global, Store, Val};
|
||||
|
||||
#[repr(C)]
|
||||
pub struct wasm_global_t {
|
||||
/// cbindgen:ignore
|
||||
#[allow(non_camel_case_types)]
|
||||
pub struct wasm_global_t {
|
||||
// maybe needs to hold onto instance
|
||||
pub(crate) inner: Global,
|
||||
}
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wasm_global_new(
|
||||
store_ptr: Option<NonNull<wasm_store_t>>,
|
||||
@@ -31,10 +32,12 @@ pub unsafe extern "C" fn wasm_global_new(
|
||||
Some(Box::new(wasm_global_t { inner: global }))
|
||||
}
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wasm_global_delete(_global: Option<Box<wasm_global_t>>) {}
|
||||
|
||||
// TODO: figure out if these should be deep or shallow copies
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wasm_global_copy(wasm_global: &wasm_global_t) -> Box<wasm_global_t> {
|
||||
// do shallow copy
|
||||
@@ -43,18 +46,21 @@ pub unsafe extern "C" fn wasm_global_copy(wasm_global: &wasm_global_t) -> Box<wa
|
||||
})
|
||||
}
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wasm_global_get(wasm_global: &wasm_global_t, out: &mut wasm_val_t) {
|
||||
let value = wasm_global.inner.get();
|
||||
*out = value.try_into().unwrap();
|
||||
}
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wasm_global_set(wasm_global: &mut wasm_global_t, val: &wasm_val_t) {
|
||||
let value: Val = val.try_into().unwrap();
|
||||
wasm_global.inner.set(value);
|
||||
}
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wasm_global_same(
|
||||
wasm_global1: &wasm_global_t,
|
||||
|
||||
13
lib/c-api/src/wasm_c_api/externals/memory.rs
vendored
13
lib/c-api/src/wasm_c_api/externals/memory.rs
vendored
@@ -4,13 +4,14 @@ use std::mem;
|
||||
use std::ptr::NonNull;
|
||||
use wasmer::{Memory, Pages, Store};
|
||||
|
||||
#[repr(C)]
|
||||
pub struct wasm_memory_t {
|
||||
/// cbindgen:ignore
|
||||
#[allow(non_camel_case_types)]
|
||||
pub struct wasm_memory_t {
|
||||
// maybe needs to hold onto instance
|
||||
pub(crate) inner: Memory,
|
||||
}
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wasm_memory_new(
|
||||
store_ptr: Option<NonNull<wasm_store_t>>,
|
||||
@@ -24,10 +25,12 @@ pub unsafe extern "C" fn wasm_memory_new(
|
||||
Some(Box::new(wasm_memory_t { inner: memory }))
|
||||
}
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wasm_memory_delete(_memory: Option<Box<wasm_memory_t>>) {}
|
||||
|
||||
// TODO: figure out if these should be deep or shallow copies
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wasm_memory_copy(wasm_memory: &wasm_memory_t) -> Box<wasm_memory_t> {
|
||||
// do shallow copy
|
||||
@@ -36,12 +39,14 @@ pub unsafe extern "C" fn wasm_memory_copy(wasm_memory: &wasm_memory_t) -> Box<wa
|
||||
})
|
||||
}
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wasm_memory_type(_memory_ptr: &wasm_memory_t) -> *mut wasm_memorytype_t {
|
||||
todo!("wasm_memory_type")
|
||||
}
|
||||
|
||||
// get a raw pointer into bytes
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wasm_memory_data(memory: &mut wasm_memory_t) -> *mut u8 {
|
||||
mem::transmute::<&[std::cell::Cell<u8>], &[u8]>(&memory.inner.view()[..]) as *const [u8]
|
||||
@@ -49,23 +54,27 @@ pub unsafe extern "C" fn wasm_memory_data(memory: &mut wasm_memory_t) -> *mut u8
|
||||
}
|
||||
|
||||
// size in bytes
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wasm_memory_data_size(memory: &wasm_memory_t) -> usize {
|
||||
memory.inner.size().bytes().0
|
||||
}
|
||||
|
||||
// size in pages
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wasm_memory_size(memory: &wasm_memory_t) -> u32 {
|
||||
memory.inner.size().0 as _
|
||||
}
|
||||
|
||||
// delta is in pages
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wasm_memory_grow(memory: &mut wasm_memory_t, delta: u32) -> bool {
|
||||
memory.inner.grow(Pages(delta)).is_ok()
|
||||
}
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wasm_memory_same(
|
||||
wasm_memory1: &wasm_memory_t,
|
||||
|
||||
13
lib/c-api/src/wasm_c_api/externals/mod.rs
vendored
13
lib/c-api/src/wasm_c_api/externals/mod.rs
vendored
@@ -11,17 +11,17 @@ use std::sync::Arc;
|
||||
pub use table::*;
|
||||
use wasmer::{Extern, Instance};
|
||||
|
||||
#[repr(C)]
|
||||
pub struct wasm_extern_t {
|
||||
/// cbindgen:ignore
|
||||
#[allow(non_camel_case_types)]
|
||||
pub struct wasm_extern_t {
|
||||
// this is how we ensure the instance stays alive
|
||||
pub(crate) instance: Option<Arc<Instance>>,
|
||||
/// cbindgen:ignore
|
||||
pub(crate) inner: Extern,
|
||||
}
|
||||
|
||||
wasm_declare_boxed_vec!(extern);
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wasm_func_as_extern(
|
||||
func_ptr: Option<NonNull<wasm_func_t>>,
|
||||
@@ -35,6 +35,7 @@ pub unsafe extern "C" fn wasm_func_as_extern(
|
||||
}))
|
||||
}
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wasm_global_as_extern(
|
||||
global_ptr: Option<NonNull<wasm_global_t>>,
|
||||
@@ -49,6 +50,7 @@ pub unsafe extern "C" fn wasm_global_as_extern(
|
||||
}))
|
||||
}
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wasm_memory_as_extern(
|
||||
memory_ptr: Option<NonNull<wasm_memory_t>>,
|
||||
@@ -63,6 +65,7 @@ pub unsafe extern "C" fn wasm_memory_as_extern(
|
||||
}))
|
||||
}
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wasm_table_as_extern(
|
||||
table_ptr: Option<NonNull<wasm_table_t>>,
|
||||
@@ -77,6 +80,7 @@ pub unsafe extern "C" fn wasm_table_as_extern(
|
||||
}))
|
||||
}
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wasm_extern_as_func(
|
||||
extern_ptr: Option<NonNull<wasm_extern_t>>,
|
||||
@@ -93,6 +97,7 @@ pub unsafe extern "C" fn wasm_extern_as_func(
|
||||
}
|
||||
}
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wasm_extern_as_global(
|
||||
extern_ptr: Option<NonNull<wasm_extern_t>>,
|
||||
@@ -106,6 +111,7 @@ pub unsafe extern "C" fn wasm_extern_as_global(
|
||||
}
|
||||
}
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wasm_extern_as_memory(
|
||||
extern_ptr: Option<NonNull<wasm_extern_t>>,
|
||||
@@ -119,6 +125,7 @@ pub unsafe extern "C" fn wasm_extern_as_memory(
|
||||
}
|
||||
}
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wasm_extern_as_table(
|
||||
extern_ptr: Option<NonNull<wasm_extern_t>>,
|
||||
|
||||
10
lib/c-api/src/wasm_c_api/externals/table.rs
vendored
10
lib/c-api/src/wasm_c_api/externals/table.rs
vendored
@@ -3,13 +3,14 @@ use super::super::types::{wasm_ref_t, wasm_table_size_t, wasm_tabletype_t};
|
||||
use std::ptr::NonNull;
|
||||
use wasmer::{Store, Table};
|
||||
|
||||
#[repr(C)]
|
||||
pub struct wasm_table_t {
|
||||
/// cbindgen:ignore
|
||||
#[allow(non_camel_case_types)]
|
||||
pub struct wasm_table_t {
|
||||
// maybe needs to hold onto instance
|
||||
pub(crate) inner: Table,
|
||||
}
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wasm_table_new(
|
||||
store_ptr: Option<NonNull<wasm_store_t>>,
|
||||
@@ -26,9 +27,11 @@ pub unsafe extern "C" fn wasm_table_new(
|
||||
Some(Box::new(wasm_table_t { inner: table }))
|
||||
}
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wasm_table_delete(_table: Option<Box<wasm_table_t>>) {}
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wasm_table_copy(wasm_table: &wasm_table_t) -> Box<wasm_table_t> {
|
||||
// do shallow copy
|
||||
@@ -37,6 +40,7 @@ pub unsafe extern "C" fn wasm_table_copy(wasm_table: &wasm_table_t) -> Box<wasm_
|
||||
})
|
||||
}
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wasm_table_same(
|
||||
wasm_table1: &wasm_table_t,
|
||||
@@ -45,11 +49,13 @@ pub unsafe extern "C" fn wasm_table_same(
|
||||
wasm_table1.inner.same(&wasm_table2.inner)
|
||||
}
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wasm_table_size(wasm_table: &wasm_table_t) -> usize {
|
||||
wasm_table.inner.size() as _
|
||||
}
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wasm_table_grow(
|
||||
_wasm_table: &mut wasm_table_t,
|
||||
|
||||
@@ -8,9 +8,9 @@ use std::ptr::NonNull;
|
||||
use std::sync::Arc;
|
||||
use wasmer::{Extern, Instance};
|
||||
|
||||
#[repr(C)]
|
||||
pub struct wasm_instance_t {
|
||||
/// cbindgen:ignore
|
||||
#[allow(non_camel_case_types)]
|
||||
pub struct wasm_instance_t {
|
||||
pub(crate) inner: Arc<Instance>,
|
||||
}
|
||||
|
||||
@@ -51,6 +51,7 @@ unsafe fn argument_import_iter(
|
||||
.unwrap_or_else(|| Box::new(std::iter::empty()) as _)
|
||||
}
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wasm_instance_new(
|
||||
store: Option<NonNull<wasm_store_t>>,
|
||||
@@ -73,9 +74,11 @@ pub unsafe extern "C" fn wasm_instance_new(
|
||||
Some(Box::new(wasm_instance_t { inner: instance }))
|
||||
}
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wasm_instance_delete(_instance: Option<Box<wasm_instance_t>>) {}
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wasm_instance_exports(
|
||||
instance: &wasm_instance_t,
|
||||
|
||||
@@ -3,12 +3,14 @@
|
||||
macro_rules! wasm_declare_vec_inner {
|
||||
($name:ident) => {
|
||||
paste::item! {
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn [<wasm_ $name _vec_new_empty>](out: *mut [<wasm_ $name _vec_t>]) {
|
||||
// TODO: actually implement this
|
||||
[<wasm_ $name _vec_new_uninitialized>](out, 0);
|
||||
}
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn [<wasm_ $name _vec_delete>](ptr: *mut [<wasm_ $name _vec_t>]) {
|
||||
let vec = &mut *ptr;
|
||||
@@ -27,6 +29,7 @@ macro_rules! wasm_declare_vec_inner {
|
||||
macro_rules! wasm_declare_vec {
|
||||
($name:ident) => {
|
||||
paste::item! {
|
||||
/// cbindgen:ignore
|
||||
#[repr(C)]
|
||||
pub struct [<wasm_ $name _vec_t>] {
|
||||
pub size: usize,
|
||||
@@ -44,6 +47,7 @@ macro_rules! wasm_declare_vec {
|
||||
}
|
||||
|
||||
// TODO: investigate possible memory leak on `init` (owned pointer)
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn [<wasm_ $name _vec_new>](out: *mut [<wasm_ $name _vec_t>], length: usize, init: *mut [<wasm_ $name _t>]) {
|
||||
let mut bytes: Vec<[<wasm_ $name _t>]> = Vec::with_capacity(length);
|
||||
@@ -57,6 +61,7 @@ macro_rules! wasm_declare_vec {
|
||||
::std::mem::forget(bytes);
|
||||
}
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn [<wasm_ $name _vec_new_uninitialized>](out: *mut [<wasm_ $name _vec_t>], length: usize) {
|
||||
let mut bytes: Vec<[<wasm_ $name _t>]> = Vec::with_capacity(length);
|
||||
@@ -76,6 +81,7 @@ macro_rules! wasm_declare_vec {
|
||||
macro_rules! wasm_declare_boxed_vec {
|
||||
($name:ident) => {
|
||||
paste::item! {
|
||||
/// cbindgen:ignore
|
||||
#[repr(C)]
|
||||
pub struct [<wasm_ $name _vec_t>] {
|
||||
pub size: usize,
|
||||
@@ -94,6 +100,7 @@ macro_rules! wasm_declare_boxed_vec {
|
||||
}
|
||||
|
||||
// TODO: investigate possible memory leak on `init` (owned pointer)
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn [<wasm_ $name _vec_new>](out: *mut [<wasm_ $name _vec_t>], length: usize, init: *const *mut [<wasm_ $name _t>]) {
|
||||
let mut bytes: Vec<*mut [<wasm_ $name _t>]> = Vec::with_capacity(length);
|
||||
@@ -107,6 +114,7 @@ macro_rules! wasm_declare_boxed_vec {
|
||||
::std::mem::forget(bytes);
|
||||
}
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn [<wasm_ $name _vec_new_uninitialized>](out: *mut [<wasm_ $name _vec_t>], length: usize) {
|
||||
let mut bytes: Vec<*mut [<wasm_ $name _t>]> = Vec::with_capacity(length);
|
||||
@@ -128,6 +136,7 @@ macro_rules! wasm_declare_ref_base {
|
||||
wasm_declare_own!($name);
|
||||
|
||||
paste::item! {
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub extern "C" fn [<wasm_ $name _copy>](_arg: *const [<wasm_ $name _t>]) -> *mut [<wasm_ $name _t>] {
|
||||
todo!("in generated declare ref base");
|
||||
@@ -145,9 +154,11 @@ macro_rules! wasm_declare_ref_base {
|
||||
macro_rules! wasm_declare_own {
|
||||
($name:ident) => {
|
||||
paste::item! {
|
||||
/// cbindgen:ignore
|
||||
#[repr(C)]
|
||||
pub struct [<wasm_ $name _t>] {}
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub extern "C" fn [<wasm_ $name _delete>](_arg: *mut [<wasm_ $name _t>]) {
|
||||
todo!("in generated delete")
|
||||
|
||||
@@ -9,12 +9,13 @@ use std::slice;
|
||||
use std::sync::Arc;
|
||||
use wasmer::{Module, Store};
|
||||
|
||||
#[repr(C)]
|
||||
pub struct wasm_module_t {
|
||||
/// cbindgen:ignore
|
||||
#[allow(non_camel_case_types)]
|
||||
pub struct wasm_module_t {
|
||||
pub(crate) inner: Arc<Module>,
|
||||
}
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wasm_module_new(
|
||||
store_ptr: Option<NonNull<wasm_store_t>>,
|
||||
@@ -31,9 +32,11 @@ pub unsafe extern "C" fn wasm_module_new(
|
||||
}))
|
||||
}
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wasm_module_delete(_module: Option<Box<wasm_module_t>>) {}
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wasm_module_exports(
|
||||
module: &wasm_module_t,
|
||||
@@ -53,6 +56,7 @@ pub unsafe extern "C" fn wasm_module_exports(
|
||||
mem::forget(exports);
|
||||
}
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wasm_module_imports(
|
||||
module: &wasm_module_t,
|
||||
@@ -72,6 +76,7 @@ pub unsafe extern "C" fn wasm_module_imports(
|
||||
mem::forget(imports);
|
||||
}
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wasm_module_deserialize(
|
||||
store_ptr: Option<NonNull<wasm_store_t>>,
|
||||
@@ -97,6 +102,7 @@ pub unsafe extern "C" fn wasm_module_deserialize(
|
||||
))))
|
||||
}
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wasm_module_serialize(
|
||||
module: &wasm_module_t,
|
||||
|
||||
@@ -3,9 +3,11 @@ use std::ptr::NonNull;
|
||||
use wasmer::Store;
|
||||
|
||||
/// Opaque wrapper around `Store`
|
||||
#[repr(C)]
|
||||
/// cbindgen:ignore
|
||||
#[allow(non_camel_case_types)]
|
||||
pub struct wasm_store_t {}
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wasm_store_new(
|
||||
wasm_engine_ptr: Option<NonNull<wasm_engine_t>>,
|
||||
@@ -18,6 +20,7 @@ pub unsafe extern "C" fn wasm_store_new(
|
||||
))
|
||||
}
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wasm_store_delete(wasm_store: Option<NonNull<wasm_store_t>>) {
|
||||
if let Some(s_inner) = wasm_store {
|
||||
|
||||
@@ -4,9 +4,11 @@ use std::ptr::NonNull;
|
||||
use wasmer::RuntimeError;
|
||||
|
||||
// opaque type which is a `RuntimeError`
|
||||
#[repr(C)]
|
||||
/// cbindgen:ignore
|
||||
#[allow(non_camel_case_types)]
|
||||
pub struct wasm_trap_t {}
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wasm_trap_delete(trap: Option<NonNull<wasm_trap_t>>) {
|
||||
if let Some(t_inner) = trap {
|
||||
@@ -14,6 +16,7 @@ pub unsafe extern "C" fn wasm_trap_delete(trap: Option<NonNull<wasm_trap_t>>) {
|
||||
}
|
||||
}
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wasm_trap_message(
|
||||
trap: *const wasm_trap_t,
|
||||
|
||||
@@ -2,7 +2,7 @@ use super::{wasm_externtype_t, wasm_name_t};
|
||||
use std::ptr::NonNull;
|
||||
use wasmer::ExportType;
|
||||
|
||||
#[repr(C)]
|
||||
/// cbindgen:ignore
|
||||
#[allow(non_camel_case_types)]
|
||||
pub struct wasm_exporttype_t {
|
||||
name: NonNull<wasm_name_t>,
|
||||
@@ -11,6 +11,7 @@ pub struct wasm_exporttype_t {
|
||||
|
||||
wasm_declare_boxed_vec!(exporttype);
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wasm_exporttype_new(
|
||||
name: NonNull<wasm_name_t>,
|
||||
@@ -19,11 +20,13 @@ pub extern "C" fn wasm_exporttype_new(
|
||||
Box::new(wasm_exporttype_t { name, extern_type })
|
||||
}
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wasm_exporttype_name(et: &'static wasm_exporttype_t) -> &'static wasm_name_t {
|
||||
unsafe { et.name.as_ref() }
|
||||
}
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wasm_exporttype_type(
|
||||
et: &'static wasm_exporttype_t,
|
||||
|
||||
@@ -5,14 +5,14 @@ use std::mem;
|
||||
use thiserror::Error;
|
||||
use wasmer::ExternType;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
#[allow(non_camel_case_types)]
|
||||
#[repr(C)]
|
||||
pub struct wasm_externtype_t {
|
||||
/// cbindgen:ignore
|
||||
#[allow(non_camel_case_types)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct wasm_externtype_t {
|
||||
pub(crate) inner: ExternType,
|
||||
}
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wasm_extern_type(e: &wasm_extern_t) -> Box<wasm_externtype_t> {
|
||||
Box::new(wasm_externtype_t {
|
||||
@@ -20,6 +20,7 @@ pub unsafe extern "C" fn wasm_extern_type(e: &wasm_extern_t) -> Box<wasm_externt
|
||||
})
|
||||
}
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wasm_externtype_delete(_et: Option<Box<wasm_externtype_t>>) {}
|
||||
|
||||
@@ -35,9 +36,11 @@ impl From<&ExternType> for wasm_externtype_t {
|
||||
}
|
||||
}
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[allow(non_camel_case_types)]
|
||||
type wasm_externkind_t = u8;
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[allow(non_camel_case_types)]
|
||||
#[repr(u8)]
|
||||
pub enum wasm_externkind_enum {
|
||||
@@ -47,6 +50,7 @@ pub enum wasm_externkind_enum {
|
||||
WASM_EXTERN_MEMORY = 3,
|
||||
}
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wasm_extern_kind(e: &wasm_extern_t) -> wasm_externkind_t {
|
||||
wasm_externkind_enum::from(e.inner.ty()) as wasm_externkind_t
|
||||
@@ -68,6 +72,7 @@ impl From<&ExternType> for wasm_externkind_enum {
|
||||
}
|
||||
}
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wasm_externtype_kind(et: &wasm_externtype_t) -> wasm_externkind_t {
|
||||
wasm_externkind_enum::from(&et.inner) as wasm_externkind_t
|
||||
@@ -131,6 +136,7 @@ impl TryFrom<&'static wasm_externtype_t> for &'static wasm_tabletype_t {
|
||||
}
|
||||
}
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wasm_externtype_as_functype_const(
|
||||
et: &'static wasm_externtype_t,
|
||||
@@ -138,6 +144,7 @@ pub unsafe extern "C" fn wasm_externtype_as_functype_const(
|
||||
Some(c_try!(et.try_into()))
|
||||
}
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wasm_externtype_as_functype(
|
||||
et: &'static wasm_externtype_t,
|
||||
@@ -145,6 +152,7 @@ pub unsafe extern "C" fn wasm_externtype_as_functype(
|
||||
Some(c_try!(et.try_into()))
|
||||
}
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wasm_functype_as_externtype_const(
|
||||
ft: &'static wasm_functype_t,
|
||||
@@ -152,6 +160,7 @@ pub unsafe extern "C" fn wasm_functype_as_externtype_const(
|
||||
&ft.extern_
|
||||
}
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wasm_functype_as_externtype(
|
||||
ft: &'static wasm_functype_t,
|
||||
@@ -159,6 +168,7 @@ pub unsafe extern "C" fn wasm_functype_as_externtype(
|
||||
&ft.extern_
|
||||
}
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wasm_externtype_as_memorytype_const(
|
||||
et: &'static wasm_externtype_t,
|
||||
@@ -166,6 +176,7 @@ pub unsafe extern "C" fn wasm_externtype_as_memorytype_const(
|
||||
Some(c_try!(et.try_into()))
|
||||
}
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wasm_externtype_as_memorytype(
|
||||
et: &'static wasm_externtype_t,
|
||||
@@ -173,6 +184,7 @@ pub unsafe extern "C" fn wasm_externtype_as_memorytype(
|
||||
Some(c_try!(et.try_into()))
|
||||
}
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wasm_memorytype_as_externtype_const(
|
||||
mt: &'static wasm_memorytype_t,
|
||||
@@ -180,6 +192,7 @@ pub unsafe extern "C" fn wasm_memorytype_as_externtype_const(
|
||||
&mt.extern_
|
||||
}
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wasm_memorytype_as_externtype(
|
||||
mt: &'static wasm_memorytype_t,
|
||||
@@ -187,6 +200,7 @@ pub unsafe extern "C" fn wasm_memorytype_as_externtype(
|
||||
&mt.extern_
|
||||
}
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wasm_externtype_as_globaltype_const(
|
||||
et: &'static wasm_externtype_t,
|
||||
@@ -194,6 +208,7 @@ pub unsafe extern "C" fn wasm_externtype_as_globaltype_const(
|
||||
Some(c_try!(et.try_into()))
|
||||
}
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wasm_externtype_as_globaltype(
|
||||
et: &'static wasm_externtype_t,
|
||||
@@ -201,6 +216,7 @@ pub unsafe extern "C" fn wasm_externtype_as_globaltype(
|
||||
Some(c_try!(et.try_into()))
|
||||
}
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wasm_globaltype_as_externtype_const(
|
||||
gt: &'static wasm_globaltype_t,
|
||||
@@ -208,6 +224,7 @@ pub unsafe extern "C" fn wasm_globaltype_as_externtype_const(
|
||||
>.extern_
|
||||
}
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wasm_globaltype_as_externtype(
|
||||
gt: &'static wasm_globaltype_t,
|
||||
@@ -215,6 +232,7 @@ pub unsafe extern "C" fn wasm_globaltype_as_externtype(
|
||||
>.extern_
|
||||
}
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wasm_externtype_as_tabletype_const(
|
||||
et: &'static wasm_externtype_t,
|
||||
@@ -222,6 +240,7 @@ pub unsafe extern "C" fn wasm_externtype_as_tabletype_const(
|
||||
Some(c_try!(et.try_into()))
|
||||
}
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wasm_externtype_as_tabletype(
|
||||
et: &'static wasm_externtype_t,
|
||||
@@ -229,6 +248,7 @@ pub unsafe extern "C" fn wasm_externtype_as_tabletype(
|
||||
Some(c_try!(et.try_into()))
|
||||
}
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wasm_tabletype_as_externtype_const(
|
||||
tt: &'static wasm_tabletype_t,
|
||||
@@ -236,6 +256,7 @@ pub unsafe extern "C" fn wasm_tabletype_as_externtype_const(
|
||||
&tt.extern_
|
||||
}
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wasm_tabletype_as_externtype(
|
||||
tt: &'static wasm_tabletype_t,
|
||||
|
||||
@@ -3,11 +3,10 @@ use std::mem;
|
||||
use std::ptr::NonNull;
|
||||
use wasmer::{ExternType, FunctionType, ValType};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
#[repr(C)]
|
||||
#[allow(non_camel_case_types)]
|
||||
pub struct wasm_functype_t {
|
||||
/// cbindgen:ignore
|
||||
#[allow(non_camel_case_types)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct wasm_functype_t {
|
||||
pub(crate) extern_: wasm_externtype_t,
|
||||
}
|
||||
|
||||
@@ -23,6 +22,7 @@ impl wasm_functype_t {
|
||||
|
||||
wasm_declare_vec!(functype);
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wasm_functype_new(
|
||||
// own
|
||||
@@ -60,9 +60,11 @@ unsafe fn wasm_functype_new_inner(
|
||||
Some(Box::new(wasm_functype_t { extern_ }))
|
||||
}
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wasm_functype_delete(_ft: Option<Box<wasm_functype_t>>) {}
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wasm_functype_copy(
|
||||
arg: Option<NonNull<wasm_functype_t>>,
|
||||
@@ -73,6 +75,7 @@ pub unsafe extern "C" fn wasm_functype_copy(
|
||||
}
|
||||
|
||||
// TODO: fix memory leak
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wasm_functype_params(ft: &wasm_functype_t) -> *const wasm_valtype_vec_t {
|
||||
let mut valtypes = ft
|
||||
@@ -93,6 +96,7 @@ pub unsafe extern "C" fn wasm_functype_params(ft: &wasm_functype_t) -> *const wa
|
||||
}
|
||||
|
||||
// TODO: fix memory leak
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wasm_functype_results(ft: &wasm_functype_t) -> *const wasm_valtype_vec_t {
|
||||
let mut valtypes = ft
|
||||
|
||||
@@ -4,11 +4,10 @@ use super::{
|
||||
use std::convert::TryInto;
|
||||
use wasmer::{ExternType, GlobalType};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
#[repr(C)]
|
||||
#[allow(non_camel_case_types)]
|
||||
pub struct wasm_globaltype_t {
|
||||
/// cbindgen:ignore
|
||||
#[allow(non_camel_case_types)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct wasm_globaltype_t {
|
||||
pub(crate) extern_: wasm_externtype_t,
|
||||
}
|
||||
|
||||
@@ -26,6 +25,7 @@ impl wasm_globaltype_t {
|
||||
|
||||
wasm_declare_vec!(globaltype);
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wasm_globaltype_new(
|
||||
// own
|
||||
@@ -35,6 +35,7 @@ pub unsafe extern "C" fn wasm_globaltype_new(
|
||||
wasm_globaltype_new_inner(valtype?, mutability)
|
||||
}
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wasm_globaltype_delete(_globaltype: Option<Box<wasm_globaltype_t>>) {}
|
||||
|
||||
@@ -54,6 +55,7 @@ unsafe fn wasm_globaltype_new_inner(
|
||||
Some(gd)
|
||||
}
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wasm_globaltype_mutability(
|
||||
globaltype: &wasm_globaltype_t,
|
||||
@@ -64,6 +66,7 @@ pub unsafe extern "C" fn wasm_globaltype_mutability(
|
||||
|
||||
// TODO: fix memory leak
|
||||
// this function leaks memory because the returned limits pointer is not owned
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wasm_globaltype_content(
|
||||
globaltype: &wasm_globaltype_t,
|
||||
|
||||
@@ -3,7 +3,7 @@ use std::ptr::NonNull;
|
||||
use wasmer::ImportType;
|
||||
|
||||
// TODO: improve ownership in `importtype_t` (can we safely use `Box<wasm_name_t>` here?)
|
||||
#[repr(C)]
|
||||
/// cbindgen:ignore
|
||||
#[allow(non_camel_case_types)]
|
||||
pub struct wasm_importtype_t {
|
||||
pub(crate) module: NonNull<wasm_name_t>,
|
||||
@@ -13,6 +13,7 @@ pub struct wasm_importtype_t {
|
||||
|
||||
wasm_declare_boxed_vec!(importtype);
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wasm_importtype_new(
|
||||
module: NonNull<wasm_name_t>,
|
||||
@@ -26,16 +27,19 @@ pub extern "C" fn wasm_importtype_new(
|
||||
})
|
||||
}
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wasm_importtype_module(et: &'static wasm_importtype_t) -> &'static wasm_name_t {
|
||||
unsafe { et.module.as_ref() }
|
||||
}
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wasm_importtype_name(et: &'static wasm_importtype_t) -> &'static wasm_name_t {
|
||||
unsafe { et.name.as_ref() }
|
||||
}
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wasm_importtype_type(
|
||||
et: &'static wasm_importtype_t,
|
||||
@@ -43,6 +47,7 @@ pub extern "C" fn wasm_importtype_type(
|
||||
unsafe { et.extern_type.as_ref() }
|
||||
}
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wasm_importtype_delete(_importtype: Option<Box<wasm_importtype_t>>) {}
|
||||
|
||||
|
||||
@@ -2,9 +2,9 @@ use super::wasm_externtype_t;
|
||||
use wasmer::{ExternType, MemoryType, Pages};
|
||||
|
||||
// opaque type wrapping `MemoryType`
|
||||
#[derive(Clone, Debug)]
|
||||
#[repr(C)]
|
||||
/// cbindgen:ignore
|
||||
#[allow(non_camel_case_types)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct wasm_memorytype_t {
|
||||
/// cbindgen:ignore
|
||||
pub(crate) extern_: wasm_externtype_t,
|
||||
@@ -24,14 +24,15 @@ impl wasm_memorytype_t {
|
||||
|
||||
wasm_declare_vec!(memorytype);
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[allow(non_camel_case_types)]
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
#[repr(C)]
|
||||
pub struct wasm_limits_t {
|
||||
pub(crate) min: u32,
|
||||
pub(crate) max: u32,
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
/// cbindgen:ignoren#[no_mangle]
|
||||
pub unsafe extern "C" fn wasm_memorytype_new(limits: &wasm_limits_t) -> Box<wasm_memorytype_t> {
|
||||
let min_pages = Pages(limits.min as _);
|
||||
// TODO: investigate if `0` is in fact a sentinel value here
|
||||
@@ -47,12 +48,12 @@ pub unsafe extern "C" fn wasm_memorytype_new(limits: &wasm_limits_t) -> Box<wasm
|
||||
})
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
/// cbindgen:ignoren#[no_mangle]
|
||||
pub unsafe extern "C" fn wasm_memorytype_delete(_memorytype: Option<Box<wasm_memorytype_t>>) {}
|
||||
|
||||
// TODO: fix memory leak
|
||||
// this function leaks memory because the returned limits pointer is not owned
|
||||
#[no_mangle]
|
||||
/// cbindgen:ignoren#[no_mangle]
|
||||
pub unsafe extern "C" fn wasm_memorytype_limits(mt: &wasm_memorytype_t) -> *const wasm_limits_t {
|
||||
let md = mt.as_memorytype();
|
||||
Box::into_raw(Box::new(wasm_limits_t {
|
||||
|
||||
@@ -5,8 +5,6 @@ mod global;
|
||||
mod import;
|
||||
mod memory;
|
||||
mod mutability;
|
||||
mod name;
|
||||
mod reference;
|
||||
mod table;
|
||||
mod value;
|
||||
|
||||
@@ -17,8 +15,6 @@ pub use global::*;
|
||||
pub use import::*;
|
||||
pub use memory::*;
|
||||
pub use mutability::*;
|
||||
pub use name::*;
|
||||
pub use reference::*;
|
||||
pub use table::*;
|
||||
pub use value::*;
|
||||
|
||||
@@ -32,3 +28,12 @@ wasm_declare_vec!(byte);
|
||||
pub struct wasm_frame_t {}
|
||||
|
||||
wasm_declare_vec!(frame);
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[allow(non_camel_case_types)]
|
||||
pub type wasm_name_t = wasm_byte_vec_t;
|
||||
|
||||
// opaque type over `ExternRef`?
|
||||
/// cbindgen:ignore
|
||||
#[allow(non_camel_case_types)]
|
||||
pub struct wasm_ref_t;
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
use std::convert::TryFrom;
|
||||
use wasmer::Mutability;
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[allow(non_camel_case_types)]
|
||||
pub type wasm_mutability_t = u8;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
/// cbindgen:ignore
|
||||
#[allow(non_camel_case_types)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
#[repr(u8)]
|
||||
pub enum wasm_mutability_enum {
|
||||
WASM_CONST = 0,
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
use super::wasm_byte_vec_t;
|
||||
|
||||
#[allow(non_camel_case_types)]
|
||||
pub type wasm_name_t = wasm_byte_vec_t;
|
||||
@@ -1,3 +0,0 @@
|
||||
// opaque type over `ExternRef`?
|
||||
#[allow(non_camel_case_types)]
|
||||
pub struct wasm_ref_t;
|
||||
@@ -1,12 +1,14 @@
|
||||
use super::{wasm_externtype_t, wasm_limits_t, wasm_valtype_delete, wasm_valtype_t};
|
||||
use wasmer::{ExternType, TableType};
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[allow(non_camel_case_types)]
|
||||
pub type wasm_table_size_t = u32;
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[allow(non_camel_case_types)]
|
||||
#[derive(Clone, Debug)]
|
||||
#[repr(C)]
|
||||
#[allow(non_camel_case_types)]
|
||||
pub struct wasm_tabletype_t {
|
||||
/// cbindgen:ignore
|
||||
pub(crate) extern_: wasm_externtype_t,
|
||||
@@ -26,6 +28,7 @@ impl wasm_tabletype_t {
|
||||
}
|
||||
}
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wasm_tabletype_new(
|
||||
// own
|
||||
@@ -54,6 +57,7 @@ pub unsafe extern "C" fn wasm_tabletype_new(
|
||||
|
||||
// TODO: fix memory leak
|
||||
// this function leaks memory because the returned limits pointer is not owned
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wasm_tabletype_limits(
|
||||
tabletype: &wasm_tabletype_t,
|
||||
@@ -67,6 +71,7 @@ pub unsafe extern "C" fn wasm_tabletype_limits(
|
||||
|
||||
// TODO: fix memory leak
|
||||
// this function leaks memory because the returned limits pointer is not owned
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wasm_tabletype_element(
|
||||
tabletype: &wasm_tabletype_t,
|
||||
@@ -76,5 +81,6 @@ pub unsafe extern "C" fn wasm_tabletype_element(
|
||||
Box::into_raw(Box::new(tt.ty.into()))
|
||||
}
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wasm_tabletype_delete(_tabletype: Option<Box<wasm_tabletype_t>>) {}
|
||||
|
||||
@@ -2,8 +2,9 @@ use super::super::value::wasm_valkind_t;
|
||||
use std::convert::TryInto;
|
||||
use wasmer::ValType;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
/// cbindgen:ignore
|
||||
#[allow(non_camel_case_types)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
#[repr(u8)]
|
||||
pub enum wasm_valkind_enum {
|
||||
WASM_I32 = 0,
|
||||
@@ -42,8 +43,9 @@ impl From<wasm_valkind_enum> for ValType {
|
||||
}
|
||||
}
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[allow(non_camel_case_types)]
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
#[repr(C)]
|
||||
pub struct wasm_valtype_t {
|
||||
valkind: wasm_valkind_enum,
|
||||
}
|
||||
@@ -72,6 +74,7 @@ impl From<ValType> for wasm_valtype_t {
|
||||
}
|
||||
}
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wasm_valtype_new(kind: wasm_valkind_t) -> Option<Box<wasm_valtype_t>> {
|
||||
let kind_enum = kind.try_into().ok()?;
|
||||
@@ -79,9 +82,11 @@ pub extern "C" fn wasm_valtype_new(kind: wasm_valkind_t) -> Option<Box<wasm_valt
|
||||
Some(Box::new(valtype))
|
||||
}
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wasm_valtype_delete(_valtype: Option<Box<wasm_valtype_t>>) {}
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wasm_valtype_kind(valtype: *const wasm_valtype_t) -> wasm_valkind_t {
|
||||
if valtype.is_null() {
|
||||
|
||||
@@ -3,10 +3,12 @@ use std::convert::{TryFrom, TryInto};
|
||||
use std::ptr::NonNull;
|
||||
use wasmer::Val;
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[allow(non_camel_case_types)]
|
||||
pub type wasm_valkind_t = u8;
|
||||
|
||||
#[repr(C)]
|
||||
/// cbindgen:ignore
|
||||
#[allow(non_camel_case_types)]
|
||||
#[derive(Clone, Copy)]
|
||||
pub union wasm_val_inner {
|
||||
pub(crate) int32_t: i32,
|
||||
@@ -16,7 +18,8 @@ pub union wasm_val_inner {
|
||||
pub(crate) wref: *mut wasm_ref_t,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
/// cbindgen:ignore
|
||||
#[allow(non_camel_case_types)]
|
||||
pub struct wasm_val_t {
|
||||
pub(crate) kind: wasm_valkind_t,
|
||||
pub(crate) of: wasm_val_inner,
|
||||
@@ -31,6 +34,7 @@ impl Clone for wasm_val_t {
|
||||
}
|
||||
}
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wasm_val_copy(out_ptr: *mut wasm_val_t, val: &wasm_val_t) {
|
||||
(*out_ptr).kind = val.kind;
|
||||
@@ -46,6 +50,7 @@ pub unsafe extern "C" fn wasm_val_copy(out_ptr: *mut wasm_val_t, val: &wasm_val_
|
||||
};
|
||||
}
|
||||
|
||||
/// cbindgen:ignore
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wasm_val_delete(val: Option<NonNull<wasm_val_t>>) {
|
||||
if let Some(v_inner) = val {
|
||||
|
||||
Reference in New Issue
Block a user