mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-08 21:58:20 +00:00
More bug fixes
This commit is contained in:
@@ -63,7 +63,8 @@ int main(int argc, const char* argv[]) {
|
|||||||
|
|
||||||
printf("Instantiating module...\n");
|
printf("Instantiating module...\n");
|
||||||
wasm_instance_t* instance = wasm_instance_new(store, module, &import_object, NULL);
|
wasm_instance_t* instance = wasm_instance_new(store, module, &import_object, NULL);
|
||||||
wasm_extern_vec_delete(&import_object);
|
wasm_func_delete(host_func);
|
||||||
|
wasm_global_delete(host_global);
|
||||||
|
|
||||||
if (!instance) {
|
if (!instance) {
|
||||||
printf("> Error instantiating module!\n");
|
printf("> Error instantiating module!\n");
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ macro_rules! wasm_declare_vec_inner {
|
|||||||
name: $name:ident,
|
name: $name:ident,
|
||||||
ty: $elem_ty:ty,
|
ty: $elem_ty:ty,
|
||||||
c_ty: $c_ty:expr,
|
c_ty: $c_ty:expr,
|
||||||
|
c_val: $c_val:expr,
|
||||||
new: $new:ident,
|
new: $new:ident,
|
||||||
empty: $empty:ident,
|
empty: $empty:ident,
|
||||||
uninit: $uninit:ident,
|
uninit: $uninit:ident,
|
||||||
@@ -21,10 +22,8 @@ Read the documentation of [`", $c_ty, "`] to see more concrete examples.
|
|||||||
# (assert_c! {
|
# (assert_c! {
|
||||||
# #include \"tests/wasmer.h\"
|
# #include \"tests/wasmer.h\"
|
||||||
#
|
#
|
||||||
int main() {
|
void example(", $c_ty, " x, ", $c_ty, " y) {
|
||||||
// Create a vector of 2 `", $c_ty, "`.
|
// Create a vector of 2 `", $c_ty, "`.
|
||||||
", $c_ty, " x;
|
|
||||||
", $c_ty, " y;
|
|
||||||
", $c_ty, " items[2] = {x, y};
|
", $c_ty, " items[2] = {x, y};
|
||||||
|
|
||||||
", stringify!($name), " vector;
|
", stringify!($name), " vector;
|
||||||
@@ -36,6 +35,8 @@ int main() {
|
|||||||
// Free it.
|
// Free it.
|
||||||
", stringify!($delete), "(&vector);
|
", stringify!($delete), "(&vector);
|
||||||
}
|
}
|
||||||
|
#
|
||||||
|
# int main() { example(", $c_val, ", ", $c_val, "); return 0; }
|
||||||
# })
|
# })
|
||||||
# .success();
|
# .success();
|
||||||
# }
|
# }
|
||||||
@@ -134,6 +135,8 @@ int main() {
|
|||||||
|
|
||||||
// Free it.
|
// Free it.
|
||||||
", stringify!($delete), "(&vector);
|
", stringify!($delete), "(&vector);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
# })
|
# })
|
||||||
# .success();
|
# .success();
|
||||||
@@ -165,6 +168,8 @@ int main() {
|
|||||||
|
|
||||||
// Free it.
|
// Free it.
|
||||||
", stringify!($delete), "(&vector);
|
", stringify!($delete), "(&vector);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
# })
|
# })
|
||||||
# .success();
|
# .success();
|
||||||
@@ -215,6 +220,11 @@ macro_rules! wasm_declare_vec {
|
|||||||
name: [<$prefix _ $name _vec_t>],
|
name: [<$prefix _ $name _vec_t>],
|
||||||
ty: [<$prefix _ $name _t>],
|
ty: [<$prefix _ $name _t>],
|
||||||
c_ty: stringify!([<$prefix _ $name _t>]),
|
c_ty: stringify!([<$prefix _ $name _t>]),
|
||||||
|
c_val: concat!("({ ",
|
||||||
|
stringify!([<$prefix _ $name _t>]), " foo;\n",
|
||||||
|
"memset(&foo, 0, sizeof(foo));\n",
|
||||||
|
"foo;\n",
|
||||||
|
"})"),
|
||||||
new: [<$prefix _ $name _vec_new>],
|
new: [<$prefix _ $name _vec_new>],
|
||||||
empty: [<$prefix _ $name _vec_new_empty>],
|
empty: [<$prefix _ $name _vec_new_empty>],
|
||||||
uninit: [<$prefix _ $name _vec_new_uninitialized>],
|
uninit: [<$prefix _ $name _vec_new_uninitialized>],
|
||||||
@@ -236,6 +246,7 @@ macro_rules! wasm_declare_boxed_vec {
|
|||||||
name: [<$prefix _ $name _vec_t>],
|
name: [<$prefix _ $name _vec_t>],
|
||||||
ty: Option<Box<[<$prefix _ $name _t>]>>,
|
ty: Option<Box<[<$prefix _ $name _t>]>>,
|
||||||
c_ty: stringify!([<$prefix _ $name _t>] *),
|
c_ty: stringify!([<$prefix _ $name _t>] *),
|
||||||
|
c_val: "NULL",
|
||||||
new: [<$prefix _ $name _vec_new>],
|
new: [<$prefix _ $name _vec_new>],
|
||||||
empty: [<$prefix _ $name _vec_new_empty>],
|
empty: [<$prefix _ $name _vec_new_empty>],
|
||||||
uninit: [<$prefix _ $name _vec_new_uninitialized>],
|
uninit: [<$prefix _ $name _vec_new_uninitialized>],
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ use wasmer_api::ExportType;
|
|||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct wasm_exporttype_t {
|
pub struct wasm_exporttype_t {
|
||||||
name: wasm_name_t,
|
name: wasm_name_t,
|
||||||
extern_type: Box<wasm_externtype_t>,
|
extern_type: wasm_externtype_t,
|
||||||
}
|
}
|
||||||
|
|
||||||
wasm_declare_boxed_vec!(exporttype);
|
wasm_declare_boxed_vec!(exporttype);
|
||||||
@@ -18,7 +18,7 @@ pub extern "C" fn wasm_exporttype_new(
|
|||||||
) -> Box<wasm_exporttype_t> {
|
) -> Box<wasm_exporttype_t> {
|
||||||
Box::new(wasm_exporttype_t {
|
Box::new(wasm_exporttype_t {
|
||||||
name: name.clone(),
|
name: name.clone(),
|
||||||
extern_type,
|
extern_type: *extern_type,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -29,7 +29,7 @@ pub extern "C" fn wasm_exporttype_name(export_type: &wasm_exporttype_t) -> &wasm
|
|||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn wasm_exporttype_type(export_type: &wasm_exporttype_t) -> &wasm_externtype_t {
|
pub extern "C" fn wasm_exporttype_type(export_type: &wasm_exporttype_t) -> &wasm_externtype_t {
|
||||||
export_type.extern_type.as_ref()
|
&export_type.extern_type
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<ExportType> for wasm_exporttype_t {
|
impl From<ExportType> for wasm_exporttype_t {
|
||||||
@@ -41,7 +41,7 @@ impl From<ExportType> for wasm_exporttype_t {
|
|||||||
impl From<&ExportType> for wasm_exporttype_t {
|
impl From<&ExportType> for wasm_exporttype_t {
|
||||||
fn from(other: &ExportType) -> Self {
|
fn from(other: &ExportType) -> Self {
|
||||||
let name: wasm_name_t = other.name().to_string().into();
|
let name: wasm_name_t = other.name().to_string().into();
|
||||||
let extern_type: Box<wasm_externtype_t> = Box::new(other.ty().into());
|
let extern_type: wasm_externtype_t = other.ty().into();
|
||||||
|
|
||||||
wasm_exporttype_t { name, extern_type }
|
wasm_exporttype_t { name, extern_type }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,12 +8,12 @@ use wasmer_api::{ExternType, GlobalType};
|
|||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub(crate) struct WasmGlobalType {
|
pub(crate) struct WasmGlobalType {
|
||||||
pub(crate) global_type: GlobalType,
|
pub(crate) global_type: GlobalType,
|
||||||
content: Box<wasm_valtype_t>,
|
content: wasm_valtype_t,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WasmGlobalType {
|
impl WasmGlobalType {
|
||||||
pub(crate) fn new(global_type: GlobalType) -> Self {
|
pub(crate) fn new(global_type: GlobalType) -> Self {
|
||||||
let content = Box::new(global_type.ty.into());
|
let content = global_type.ty.into();
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
global_type,
|
global_type,
|
||||||
@@ -79,5 +79,5 @@ pub unsafe extern "C" fn wasm_globaltype_mutability(
|
|||||||
pub unsafe extern "C" fn wasm_globaltype_content(
|
pub unsafe extern "C" fn wasm_globaltype_content(
|
||||||
global_type: &wasm_globaltype_t,
|
global_type: &wasm_globaltype_t,
|
||||||
) -> &wasm_valtype_t {
|
) -> &wasm_valtype_t {
|
||||||
global_type.inner().content.as_ref()
|
&global_type.inner().content
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ use wasmer_api::ImportType;
|
|||||||
pub struct wasm_importtype_t {
|
pub struct wasm_importtype_t {
|
||||||
module: wasm_name_t,
|
module: wasm_name_t,
|
||||||
name: wasm_name_t,
|
name: wasm_name_t,
|
||||||
extern_type: Box<wasm_externtype_t>,
|
extern_type: wasm_externtype_t,
|
||||||
}
|
}
|
||||||
|
|
||||||
wasm_declare_boxed_vec!(importtype);
|
wasm_declare_boxed_vec!(importtype);
|
||||||
@@ -21,7 +21,7 @@ pub extern "C" fn wasm_importtype_new(
|
|||||||
Some(Box::new(wasm_importtype_t {
|
Some(Box::new(wasm_importtype_t {
|
||||||
name: *name?,
|
name: *name?,
|
||||||
module: *module?,
|
module: *module?,
|
||||||
extern_type: extern_type?,
|
extern_type: *extern_type?,
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -37,7 +37,7 @@ pub extern "C" fn wasm_importtype_name(import_type: &wasm_importtype_t) -> &wasm
|
|||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn wasm_importtype_type(import_type: &wasm_importtype_t) -> &wasm_externtype_t {
|
pub extern "C" fn wasm_importtype_type(import_type: &wasm_importtype_t) -> &wasm_externtype_t {
|
||||||
import_type.extern_type.as_ref()
|
&import_type.extern_type
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
@@ -53,7 +53,7 @@ impl From<&ImportType> for wasm_importtype_t {
|
|||||||
fn from(other: &ImportType) -> Self {
|
fn from(other: &ImportType) -> Self {
|
||||||
let module: wasm_name_t = other.module().to_string().into();
|
let module: wasm_name_t = other.module().to_string().into();
|
||||||
let name: wasm_name_t = other.name().to_string().into();
|
let name: wasm_name_t = other.name().to_string().into();
|
||||||
let extern_type: Box<wasm_externtype_t> = Box::new(other.ty().into());
|
let extern_type: wasm_externtype_t = other.ty().into();
|
||||||
|
|
||||||
wasm_importtype_t {
|
wasm_importtype_t {
|
||||||
module,
|
module,
|
||||||
|
|||||||
@@ -4,18 +4,18 @@ use wasmer_api::{ExternType, MemoryType, Pages};
|
|||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub(crate) struct WasmMemoryType {
|
pub(crate) struct WasmMemoryType {
|
||||||
pub(crate) memory_type: MemoryType,
|
pub(crate) memory_type: MemoryType,
|
||||||
limits: Box<wasm_limits_t>,
|
limits: wasm_limits_t,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WasmMemoryType {
|
impl WasmMemoryType {
|
||||||
pub(crate) fn new(memory_type: MemoryType) -> Self {
|
pub(crate) fn new(memory_type: MemoryType) -> Self {
|
||||||
let limits = Box::new(wasm_limits_t {
|
let limits = wasm_limits_t {
|
||||||
min: memory_type.minimum.0 as _,
|
min: memory_type.minimum.0 as _,
|
||||||
max: memory_type
|
max: memory_type
|
||||||
.maximum
|
.maximum
|
||||||
.map(|max| max.0 as _)
|
.map(|max| max.0 as _)
|
||||||
.unwrap_or(LIMITS_MAX_SENTINEL),
|
.unwrap_or(LIMITS_MAX_SENTINEL),
|
||||||
});
|
};
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
memory_type,
|
memory_type,
|
||||||
@@ -79,5 +79,5 @@ const LIMITS_MAX_SENTINEL: u32 = u32::max_value();
|
|||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn wasm_memorytype_limits(memory_type: &wasm_memorytype_t) -> &wasm_limits_t {
|
pub unsafe extern "C" fn wasm_memorytype_limits(memory_type: &wasm_memorytype_t) -> &wasm_limits_t {
|
||||||
memory_type.inner().limits.as_ref()
|
&memory_type.inner().limits
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,21 +10,21 @@ const LIMITS_MAX_SENTINEL: u32 = u32::max_value();
|
|||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub(crate) struct WasmTableType {
|
pub(crate) struct WasmTableType {
|
||||||
pub(crate) table_type: TableType,
|
pub(crate) _table_type: TableType,
|
||||||
limits: Box<wasm_limits_t>,
|
limits: wasm_limits_t,
|
||||||
content: Box<wasm_valtype_t>,
|
content: wasm_valtype_t,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WasmTableType {
|
impl WasmTableType {
|
||||||
pub(crate) fn new(table_type: TableType) -> Self {
|
pub(crate) fn new(table_type: TableType) -> Self {
|
||||||
let limits = Box::new(wasm_limits_t {
|
let limits = wasm_limits_t {
|
||||||
min: table_type.minimum as _,
|
min: table_type.minimum as _,
|
||||||
max: table_type.maximum.unwrap_or(LIMITS_MAX_SENTINEL),
|
max: table_type.maximum.unwrap_or(LIMITS_MAX_SENTINEL),
|
||||||
});
|
};
|
||||||
let content = Box::new(table_type.ty.into());
|
let content = table_type.ty.into();
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
table_type,
|
_table_type: table_type,
|
||||||
limits,
|
limits,
|
||||||
content,
|
content,
|
||||||
}
|
}
|
||||||
@@ -79,12 +79,12 @@ pub unsafe extern "C" fn wasm_tabletype_new(
|
|||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn wasm_tabletype_limits(table_type: &wasm_tabletype_t) -> &wasm_limits_t {
|
pub unsafe extern "C" fn wasm_tabletype_limits(table_type: &wasm_tabletype_t) -> &wasm_limits_t {
|
||||||
table_type.inner().limits.as_ref()
|
&table_type.inner().limits
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn wasm_tabletype_element(table_type: &wasm_tabletype_t) -> &wasm_valtype_t {
|
pub unsafe extern "C" fn wasm_tabletype_element(table_type: &wasm_tabletype_t) -> &wasm_valtype_t {
|
||||||
table_type.inner().content.as_ref()
|
&table_type.inner().content
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ pub unsafe extern "C" fn wasmer_module_name(
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
*out = name.as_bytes().to_vec().into();
|
out.set_buffer(name.as_bytes().to_vec());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Unstable non-standard Wasmer-specific API to set the module's
|
/// Unstable non-standard Wasmer-specific API to set the module's
|
||||||
|
|||||||
Reference in New Issue
Block a user