mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-13 22:08:45 +00:00
Merge branch 'master' into feature/wasmer-create-exe
This commit is contained in:
@@ -31,4 +31,5 @@ pub mod wasi;
|
||||
|
||||
pub mod wasmer;
|
||||
|
||||
#[cfg(feature = "wat")]
|
||||
pub mod wat;
|
||||
|
||||
@@ -6,6 +6,10 @@ use wasmer::ExportType;
|
||||
pub struct wasm_exporttype_t {
|
||||
name: NonNull<wasm_name_t>,
|
||||
extern_type: NonNull<wasm_externtype_t>,
|
||||
|
||||
/// If `true`, `name` and `extern_type` will be dropped by
|
||||
/// `wasm_exporttype_t::drop`.
|
||||
owns_fields: bool,
|
||||
}
|
||||
|
||||
wasm_declare_boxed_vec!(exporttype);
|
||||
@@ -15,7 +19,11 @@ pub extern "C" fn wasm_exporttype_new(
|
||||
name: NonNull<wasm_name_t>,
|
||||
extern_type: NonNull<wasm_externtype_t>,
|
||||
) -> Box<wasm_exporttype_t> {
|
||||
Box::new(wasm_exporttype_t { name, extern_type })
|
||||
Box::new(wasm_exporttype_t {
|
||||
name,
|
||||
extern_type,
|
||||
owns_fields: false,
|
||||
})
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
@@ -30,6 +38,23 @@ pub extern "C" fn wasm_exporttype_type(
|
||||
unsafe { et.extern_type.as_ref() }
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wasm_exporttype_delete(_exporttype: Option<Box<wasm_exporttype_t>>) {}
|
||||
|
||||
impl Drop for wasm_exporttype_t {
|
||||
fn drop(&mut self) {
|
||||
if self.owns_fields {
|
||||
// SAFETY: `owns_fields` is set to `true` only in
|
||||
// `wasm_exporttype_t::from(&ExportType)`, where the data
|
||||
// are leaked properly and won't be freed somewhere else.
|
||||
unsafe {
|
||||
let _ = Box::from_raw(self.name.as_ptr());
|
||||
let _ = Box::from_raw(self.extern_type.as_ptr());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ExportType> for wasm_exporttype_t {
|
||||
fn from(other: ExportType) -> Self {
|
||||
(&other).into()
|
||||
@@ -56,6 +81,10 @@ impl From<&ExportType> for wasm_exporttype_t {
|
||||
unsafe { NonNull::new_unchecked(Box::into_raw(Box::new(extern_type))) }
|
||||
};
|
||||
|
||||
wasm_exporttype_t { name, extern_type }
|
||||
wasm_exporttype_t {
|
||||
name,
|
||||
extern_type,
|
||||
owns_fields: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,15 @@ pub unsafe extern "C" fn wasm_extern_type(e: &wasm_extern_t) -> Box<wasm_externt
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wasm_externtype_delete(_et: Option<Box<wasm_externtype_t>>) {}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wasm_externtype_copy(
|
||||
wasm_externtype: &wasm_externtype_t,
|
||||
) -> Box<wasm_externtype_t> {
|
||||
Box::new(wasm_externtype_t {
|
||||
inner: wasm_externtype.inner.clone(),
|
||||
})
|
||||
}
|
||||
|
||||
impl From<ExternType> for wasm_externtype_t {
|
||||
fn from(other: ExternType) -> Self {
|
||||
Self { inner: other }
|
||||
|
||||
Reference in New Issue
Block a user