More bug fixes

This commit is contained in:
Amanieu d'Antras
2021-11-17 00:03:28 +00:00
parent 75cb5ab788
commit 724c59c751
8 changed files with 41 additions and 29 deletions

View File

@@ -63,7 +63,8 @@ int main(int argc, const char* argv[]) {
printf("Instantiating module...\n");
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) {
printf("> Error instantiating module!\n");

View File

@@ -3,6 +3,7 @@ macro_rules! wasm_declare_vec_inner {
name: $name:ident,
ty: $elem_ty:ty,
c_ty: $c_ty:expr,
c_val: $c_val:expr,
new: $new:ident,
empty: $empty:ident,
uninit: $uninit:ident,
@@ -21,10 +22,8 @@ Read the documentation of [`", $c_ty, "`] to see more concrete examples.
# (assert_c! {
# #include \"tests/wasmer.h\"
#
int main() {
void example(", $c_ty, " x, ", $c_ty, " y) {
// Create a vector of 2 `", $c_ty, "`.
", $c_ty, " x;
", $c_ty, " y;
", $c_ty, " items[2] = {x, y};
", stringify!($name), " vector;
@@ -36,6 +35,8 @@ int main() {
// Free it.
", stringify!($delete), "(&vector);
}
#
# int main() { example(", $c_val, ", ", $c_val, "); return 0; }
# })
# .success();
# }
@@ -134,6 +135,8 @@ int main() {
// Free it.
", stringify!($delete), "(&vector);
return 0;
}
# })
# .success();
@@ -165,6 +168,8 @@ int main() {
// Free it.
", stringify!($delete), "(&vector);
return 0;
}
# })
# .success();
@@ -215,6 +220,11 @@ macro_rules! wasm_declare_vec {
name: [<$prefix _ $name _vec_t>],
ty: [<$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>],
empty: [<$prefix _ $name _vec_new_empty>],
uninit: [<$prefix _ $name _vec_new_uninitialized>],
@@ -236,6 +246,7 @@ macro_rules! wasm_declare_boxed_vec {
name: [<$prefix _ $name _vec_t>],
ty: Option<Box<[<$prefix _ $name _t>]>>,
c_ty: stringify!([<$prefix _ $name _t>] *),
c_val: "NULL",
new: [<$prefix _ $name _vec_new>],
empty: [<$prefix _ $name _vec_new_empty>],
uninit: [<$prefix _ $name _vec_new_uninitialized>],

View File

@@ -5,7 +5,7 @@ use wasmer_api::ExportType;
#[derive(Clone)]
pub struct wasm_exporttype_t {
name: wasm_name_t,
extern_type: Box<wasm_externtype_t>,
extern_type: wasm_externtype_t,
}
wasm_declare_boxed_vec!(exporttype);
@@ -18,7 +18,7 @@ pub extern "C" fn wasm_exporttype_new(
) -> Box<wasm_exporttype_t> {
Box::new(wasm_exporttype_t {
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]
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 {
@@ -41,7 +41,7 @@ impl From<ExportType> for wasm_exporttype_t {
impl From<&ExportType> for wasm_exporttype_t {
fn from(other: &ExportType) -> Self {
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 }
}

View File

@@ -8,12 +8,12 @@ use wasmer_api::{ExternType, GlobalType};
#[derive(Debug, Clone)]
pub(crate) struct WasmGlobalType {
pub(crate) global_type: GlobalType,
content: Box<wasm_valtype_t>,
content: wasm_valtype_t,
}
impl WasmGlobalType {
pub(crate) fn new(global_type: GlobalType) -> Self {
let content = Box::new(global_type.ty.into());
let content = global_type.ty.into();
Self {
global_type,
@@ -79,5 +79,5 @@ pub unsafe extern "C" fn wasm_globaltype_mutability(
pub unsafe extern "C" fn wasm_globaltype_content(
global_type: &wasm_globaltype_t,
) -> &wasm_valtype_t {
global_type.inner().content.as_ref()
&global_type.inner().content
}

View File

@@ -7,7 +7,7 @@ use wasmer_api::ImportType;
pub struct wasm_importtype_t {
module: wasm_name_t,
name: wasm_name_t,
extern_type: Box<wasm_externtype_t>,
extern_type: wasm_externtype_t,
}
wasm_declare_boxed_vec!(importtype);
@@ -21,7 +21,7 @@ pub extern "C" fn wasm_importtype_new(
Some(Box::new(wasm_importtype_t {
name: *name?,
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]
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]
@@ -53,7 +53,7 @@ impl From<&ImportType> for wasm_importtype_t {
fn from(other: &ImportType) -> Self {
let module: wasm_name_t = other.module().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 {
module,

View File

@@ -4,18 +4,18 @@ use wasmer_api::{ExternType, MemoryType, Pages};
#[derive(Debug, Clone)]
pub(crate) struct WasmMemoryType {
pub(crate) memory_type: MemoryType,
limits: Box<wasm_limits_t>,
limits: wasm_limits_t,
}
impl WasmMemoryType {
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 _,
max: memory_type
.maximum
.map(|max| max.0 as _)
.unwrap_or(LIMITS_MAX_SENTINEL),
});
};
Self {
memory_type,
@@ -79,5 +79,5 @@ const LIMITS_MAX_SENTINEL: u32 = u32::max_value();
#[no_mangle]
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
}

View File

@@ -10,21 +10,21 @@ const LIMITS_MAX_SENTINEL: u32 = u32::max_value();
#[derive(Debug, Clone)]
pub(crate) struct WasmTableType {
pub(crate) table_type: TableType,
limits: Box<wasm_limits_t>,
content: Box<wasm_valtype_t>,
pub(crate) _table_type: TableType,
limits: wasm_limits_t,
content: wasm_valtype_t,
}
impl WasmTableType {
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 _,
max: table_type.maximum.unwrap_or(LIMITS_MAX_SENTINEL),
});
let content = Box::new(table_type.ty.into());
};
let content = table_type.ty.into();
Self {
table_type,
_table_type: table_type,
limits,
content,
}
@@ -79,12 +79,12 @@ pub unsafe extern "C" fn wasm_tabletype_new(
#[no_mangle]
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]
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]

View File

@@ -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