From 8f627d98347ffeb0631f8ebed40110a12ef4a24f Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Mon, 28 Sep 2020 14:49:44 +0200 Subject: [PATCH] feat(c-api) Instruct cbindgen to ignore all functions and types defined in `wasm.h`. --- lib/c-api/src/wasm_c_api/engine.rs | 14 +++++++--- .../src/wasm_c_api/externals/function.rs | 14 +++++++--- lib/c-api/src/wasm_c_api/externals/global.rs | 10 +++++-- lib/c-api/src/wasm_c_api/externals/memory.rs | 13 +++++++-- lib/c-api/src/wasm_c_api/externals/mod.rs | 13 ++++++--- lib/c-api/src/wasm_c_api/externals/table.rs | 10 +++++-- lib/c-api/src/wasm_c_api/instance.rs | 7 +++-- lib/c-api/src/wasm_c_api/macros.rs | 11 ++++++++ lib/c-api/src/wasm_c_api/module.rs | 10 +++++-- lib/c-api/src/wasm_c_api/store.rs | 5 +++- lib/c-api/src/wasm_c_api/trap.rs | 5 +++- lib/c-api/src/wasm_c_api/types/export.rs | 5 +++- lib/c-api/src/wasm_c_api/types/extern_.rs | 27 ++++++++++++++++--- lib/c-api/src/wasm_c_api/types/function.rs | 10 ++++--- lib/c-api/src/wasm_c_api/types/global.rs | 9 ++++--- lib/c-api/src/wasm_c_api/types/import.rs | 7 ++++- lib/c-api/src/wasm_c_api/types/memory.rs | 13 ++++----- lib/c-api/src/wasm_c_api/types/mod.rs | 13 ++++++--- lib/c-api/src/wasm_c_api/types/mutability.rs | 4 ++- lib/c-api/src/wasm_c_api/types/name.rs | 4 --- lib/c-api/src/wasm_c_api/types/reference.rs | 3 --- lib/c-api/src/wasm_c_api/types/table.rs | 8 +++++- lib/c-api/src/wasm_c_api/types/value.rs | 9 +++++-- lib/c-api/src/wasm_c_api/value.rs | 9 +++++-- 24 files changed, 178 insertions(+), 55 deletions(-) delete mode 100644 lib/c-api/src/wasm_c_api/types/name.rs delete mode 100644 lib/c-api/src/wasm_c_api/types/reference.rs diff --git a/lib/c-api/src/wasm_c_api/engine.rs b/lib/c-api/src/wasm_c_api/engine.rs index 1d16d50f2..eb11c3e6e 100644 --- a/lib/c-api/src/wasm_c_api/engine.rs +++ b/lib/c-api/src/wasm_c_api/engine.rs @@ -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)] +/// cbindgen:ignore +#[allow(non_camel_case_types)] pub struct wasm_engine_t { - /// cbindgen:ignore pub(crate) inner: Arc, } @@ -36,6 +39,7 @@ cfg_if! { } } + /// cbindgen:ignore #[no_mangle] pub extern "C" fn wasm_engine_new() -> Box { let compiler_config: Box = 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 { let engine: Arc = Arc::new(JIT::headless().engine()); @@ -52,6 +57,7 @@ cfg_if! { } } else { + /// cbindgen:ignore #[no_mangle] pub extern "C" fn wasm_engine_new() -> Box { 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>) {} +/// cbindgen:ignore #[no_mangle] pub extern "C" fn wasm_engine_new_with_config( _config_ptr: *mut wasm_config_t, diff --git a/lib/c-api/src/wasm_c_api/externals/function.rs b/lib/c-api/src/wasm_c_api/externals/function.rs index 2512c475c..22366809f 100644 --- a/lib/c-api/src/wasm_c_api/externals/function.rs +++ b/lib/c-api/src/wasm_c_api/externals/function.rs @@ -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>, } +/// 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>, @@ -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>, @@ -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>) {} +/// 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() diff --git a/lib/c-api/src/wasm_c_api/externals/global.rs b/lib/c-api/src/wasm_c_api/externals/global.rs index 575670c19..ba148aa21 100644 --- a/lib/c-api/src/wasm_c_api/externals/global.rs +++ b/lib/c-api/src/wasm_c_api/externals/global.rs @@ -5,13 +5,14 @@ use std::convert::TryInto; use std::ptr::NonNull; use wasmer::{Global, Store, Val}; -#[repr(C)] +/// cbindgen:ignore +#[allow(non_camel_case_types)] pub struct wasm_global_t { - /// cbindgen:ignore // 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>, @@ -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>) {} // 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 { // do shallow copy @@ -43,18 +46,21 @@ pub unsafe extern "C" fn wasm_global_copy(wasm_global: &wasm_global_t) -> Box>, @@ -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>) {} // 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 { // do shallow copy @@ -36,12 +39,14 @@ pub unsafe extern "C" fn wasm_memory_copy(wasm_memory: &wasm_memory_t) -> Box *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]>(&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, diff --git a/lib/c-api/src/wasm_c_api/externals/mod.rs b/lib/c-api/src/wasm_c_api/externals/mod.rs index 604651e1a..6f04a94d1 100644 --- a/lib/c-api/src/wasm_c_api/externals/mod.rs +++ b/lib/c-api/src/wasm_c_api/externals/mod.rs @@ -11,17 +11,17 @@ use std::sync::Arc; pub use table::*; use wasmer::{Extern, Instance}; -#[repr(C)] +/// cbindgen:ignore +#[allow(non_camel_case_types)] pub struct wasm_extern_t { - /// cbindgen:ignore // this is how we ensure the instance stays alive pub(crate) instance: Option>, - /// 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>, @@ -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>, @@ -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>, @@ -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>, @@ -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>, @@ -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>, @@ -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>, @@ -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>, diff --git a/lib/c-api/src/wasm_c_api/externals/table.rs b/lib/c-api/src/wasm_c_api/externals/table.rs index 3ebef63f4..44600035d 100644 --- a/lib/c-api/src/wasm_c_api/externals/table.rs +++ b/lib/c-api/src/wasm_c_api/externals/table.rs @@ -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)] +/// cbindgen:ignore +#[allow(non_camel_case_types)] pub struct wasm_table_t { - /// cbindgen:ignore // 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>, @@ -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>) {} +/// cbindgen:ignore #[no_mangle] pub unsafe extern "C" fn wasm_table_copy(wasm_table: &wasm_table_t) -> Box { // do shallow copy @@ -37,6 +40,7 @@ pub unsafe extern "C" fn wasm_table_copy(wasm_table: &wasm_table_t) -> Box usize { wasm_table.inner.size() as _ } +/// cbindgen:ignore #[no_mangle] pub unsafe extern "C" fn wasm_table_grow( _wasm_table: &mut wasm_table_t, diff --git a/lib/c-api/src/wasm_c_api/instance.rs b/lib/c-api/src/wasm_c_api/instance.rs index 7bcd1de03..139de7fd2 100644 --- a/lib/c-api/src/wasm_c_api/instance.rs +++ b/lib/c-api/src/wasm_c_api/instance.rs @@ -8,9 +8,9 @@ use std::ptr::NonNull; use std::sync::Arc; use wasmer::{Extern, Instance}; -#[repr(C)] +/// cbindgen:ignore +#[allow(non_camel_case_types)] pub struct wasm_instance_t { - /// cbindgen:ignore pub(crate) inner: Arc, } @@ -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>, @@ -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>) {} +/// cbindgen:ignore #[no_mangle] pub unsafe extern "C" fn wasm_instance_exports( instance: &wasm_instance_t, diff --git a/lib/c-api/src/wasm_c_api/macros.rs b/lib/c-api/src/wasm_c_api/macros.rs index f37d9b71a..9a022ce38 100644 --- a/lib/c-api/src/wasm_c_api/macros.rs +++ b/lib/c-api/src/wasm_c_api/macros.rs @@ -3,12 +3,14 @@ macro_rules! wasm_declare_vec_inner { ($name:ident) => { paste::item! { + /// cbindgen:ignore #[no_mangle] pub unsafe extern "C" fn [](out: *mut []) { // TODO: actually implement this [](out, 0); } + /// cbindgen:ignore #[no_mangle] pub unsafe extern "C" fn [](ptr: *mut []) { 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 [] { 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 [](out: *mut [], length: usize, init: *mut []) { let mut bytes: Vec<[]> = 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 [](out: *mut [], length: usize) { let mut bytes: Vec<[]> = 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 [] { 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 [](out: *mut [], length: usize, init: *const *mut []) { let mut bytes: Vec<*mut []> = 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 [](out: *mut [], length: usize) { let mut bytes: Vec<*mut []> = 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 [](_arg: *const []) -> *mut [] { 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 [] {} + /// cbindgen:ignore #[no_mangle] pub extern "C" fn [](_arg: *mut []) { todo!("in generated delete") diff --git a/lib/c-api/src/wasm_c_api/module.rs b/lib/c-api/src/wasm_c_api/module.rs index 3f7efb116..bca743268 100644 --- a/lib/c-api/src/wasm_c_api/module.rs +++ b/lib/c-api/src/wasm_c_api/module.rs @@ -9,12 +9,13 @@ use std::slice; use std::sync::Arc; use wasmer::{Module, Store}; -#[repr(C)] +/// cbindgen:ignore +#[allow(non_camel_case_types)] pub struct wasm_module_t { - /// cbindgen:ignore pub(crate) inner: Arc, } +/// cbindgen:ignore #[no_mangle] pub unsafe extern "C" fn wasm_module_new( store_ptr: Option>, @@ -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>) {} +/// 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>, @@ -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, diff --git a/lib/c-api/src/wasm_c_api/store.rs b/lib/c-api/src/wasm_c_api/store.rs index 6eaa78bd8..32b241d84 100644 --- a/lib/c-api/src/wasm_c_api/store.rs +++ b/lib/c-api/src/wasm_c_api/store.rs @@ -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>, @@ -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>) { if let Some(s_inner) = wasm_store { diff --git a/lib/c-api/src/wasm_c_api/trap.rs b/lib/c-api/src/wasm_c_api/trap.rs index d2503a636..104cabe97 100644 --- a/lib/c-api/src/wasm_c_api/trap.rs +++ b/lib/c-api/src/wasm_c_api/trap.rs @@ -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>) { if let Some(t_inner) = trap { @@ -14,6 +16,7 @@ pub unsafe extern "C" fn wasm_trap_delete(trap: Option>) { } } +/// cbindgen:ignore #[no_mangle] pub unsafe extern "C" fn wasm_trap_message( trap: *const wasm_trap_t, diff --git a/lib/c-api/src/wasm_c_api/types/export.rs b/lib/c-api/src/wasm_c_api/types/export.rs index 237256039..81b8039f7 100644 --- a/lib/c-api/src/wasm_c_api/types/export.rs +++ b/lib/c-api/src/wasm_c_api/types/export.rs @@ -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, @@ -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, @@ -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, diff --git a/lib/c-api/src/wasm_c_api/types/extern_.rs b/lib/c-api/src/wasm_c_api/types/extern_.rs index b02e337fb..3d537e59e 100644 --- a/lib/c-api/src/wasm_c_api/types/extern_.rs +++ b/lib/c-api/src/wasm_c_api/types/extern_.rs @@ -5,14 +5,14 @@ use std::mem; use thiserror::Error; use wasmer::ExternType; -#[derive(Clone, Debug)] +/// cbindgen:ignore #[allow(non_camel_case_types)] -#[repr(C)] +#[derive(Clone, Debug)] pub struct wasm_externtype_t { - /// cbindgen:ignore pub(crate) inner: ExternType, } +/// cbindgen:ignore #[no_mangle] pub unsafe extern "C" fn wasm_extern_type(e: &wasm_extern_t) -> Box { Box::new(wasm_externtype_t { @@ -20,6 +20,7 @@ pub unsafe extern "C" fn wasm_extern_type(e: &wasm_extern_t) -> Box>) {} @@ -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, diff --git a/lib/c-api/src/wasm_c_api/types/function.rs b/lib/c-api/src/wasm_c_api/types/function.rs index f00bdda67..35f4674e8 100644 --- a/lib/c-api/src/wasm_c_api/types/function.rs +++ b/lib/c-api/src/wasm_c_api/types/function.rs @@ -3,11 +3,10 @@ use std::mem; use std::ptr::NonNull; use wasmer::{ExternType, FunctionType, ValType}; -#[derive(Clone, Debug)] -#[repr(C)] +/// cbindgen:ignore #[allow(non_camel_case_types)] +#[derive(Clone, Debug)] pub struct wasm_functype_t { - /// cbindgen:ignore 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>) {} +/// cbindgen:ignore #[no_mangle] pub unsafe extern "C" fn wasm_functype_copy( arg: Option>, @@ -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 diff --git a/lib/c-api/src/wasm_c_api/types/global.rs b/lib/c-api/src/wasm_c_api/types/global.rs index 2f590cea8..9547430cc 100644 --- a/lib/c-api/src/wasm_c_api/types/global.rs +++ b/lib/c-api/src/wasm_c_api/types/global.rs @@ -4,11 +4,10 @@ use super::{ use std::convert::TryInto; use wasmer::{ExternType, GlobalType}; -#[derive(Clone, Debug)] -#[repr(C)] +/// cbindgen:ignore #[allow(non_camel_case_types)] +#[derive(Clone, Debug)] pub struct wasm_globaltype_t { - /// cbindgen:ignore 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>) {} @@ -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, diff --git a/lib/c-api/src/wasm_c_api/types/import.rs b/lib/c-api/src/wasm_c_api/types/import.rs index a45b1644b..8e45570e7 100644 --- a/lib/c-api/src/wasm_c_api/types/import.rs +++ b/lib/c-api/src/wasm_c_api/types/import.rs @@ -3,7 +3,7 @@ use std::ptr::NonNull; use wasmer::ImportType; // TODO: improve ownership in `importtype_t` (can we safely use `Box` here?) -#[repr(C)] +/// cbindgen:ignore #[allow(non_camel_case_types)] pub struct wasm_importtype_t { pub(crate) module: NonNull, @@ -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, @@ -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>) {} diff --git a/lib/c-api/src/wasm_c_api/types/memory.rs b/lib/c-api/src/wasm_c_api/types/memory.rs index 5a1fa3a2f..cc2cfa39b 100644 --- a/lib/c-api/src/wasm_c_api/types/memory.rs +++ b/lib/c-api/src/wasm_c_api/types/memory.rs @@ -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 { 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>) {} // 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 { diff --git a/lib/c-api/src/wasm_c_api/types/mod.rs b/lib/c-api/src/wasm_c_api/types/mod.rs index be015a110..65bd9e6d3 100644 --- a/lib/c-api/src/wasm_c_api/types/mod.rs +++ b/lib/c-api/src/wasm_c_api/types/mod.rs @@ -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; diff --git a/lib/c-api/src/wasm_c_api/types/mutability.rs b/lib/c-api/src/wasm_c_api/types/mutability.rs index 23f52959c..6611843d7 100644 --- a/lib/c-api/src/wasm_c_api/types/mutability.rs +++ b/lib/c-api/src/wasm_c_api/types/mutability.rs @@ -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, diff --git a/lib/c-api/src/wasm_c_api/types/name.rs b/lib/c-api/src/wasm_c_api/types/name.rs deleted file mode 100644 index aedee66cb..000000000 --- a/lib/c-api/src/wasm_c_api/types/name.rs +++ /dev/null @@ -1,4 +0,0 @@ -use super::wasm_byte_vec_t; - -#[allow(non_camel_case_types)] -pub type wasm_name_t = wasm_byte_vec_t; diff --git a/lib/c-api/src/wasm_c_api/types/reference.rs b/lib/c-api/src/wasm_c_api/types/reference.rs deleted file mode 100644 index f3e6424ca..000000000 --- a/lib/c-api/src/wasm_c_api/types/reference.rs +++ /dev/null @@ -1,3 +0,0 @@ -// opaque type over `ExternRef`? -#[allow(non_camel_case_types)] -pub struct wasm_ref_t; diff --git a/lib/c-api/src/wasm_c_api/types/table.rs b/lib/c-api/src/wasm_c_api/types/table.rs index 3718958df..73455bede 100644 --- a/lib/c-api/src/wasm_c_api/types/table.rs +++ b/lib/c-api/src/wasm_c_api/types/table.rs @@ -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>) {} diff --git a/lib/c-api/src/wasm_c_api/types/value.rs b/lib/c-api/src/wasm_c_api/types/value.rs index c7f0fa549..60dff16b0 100644 --- a/lib/c-api/src/wasm_c_api/types/value.rs +++ b/lib/c-api/src/wasm_c_api/types/value.rs @@ -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 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 for wasm_valtype_t { } } +/// cbindgen:ignore #[no_mangle] pub extern "C" fn wasm_valtype_new(kind: wasm_valkind_t) -> Option> { let kind_enum = kind.try_into().ok()?; @@ -79,9 +82,11 @@ pub extern "C" fn wasm_valtype_new(kind: wasm_valkind_t) -> Option>) {} +/// cbindgen:ignore #[no_mangle] pub unsafe extern "C" fn wasm_valtype_kind(valtype: *const wasm_valtype_t) -> wasm_valkind_t { if valtype.is_null() { diff --git a/lib/c-api/src/wasm_c_api/value.rs b/lib/c-api/src/wasm_c_api/value.rs index 03cc48e52..2102bbb1e 100644 --- a/lib/c-api/src/wasm_c_api/value.rs +++ b/lib/c-api/src/wasm_c_api/value.rs @@ -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>) { if let Some(v_inner) = val {