c-api: Add wasm_*_same functions to global,memory,table

This commit is contained in:
Manos Pitsidianakis
2022-07-01 23:17:06 +03:00
parent 274aa3e167
commit 62f07efb08
7 changed files with 56 additions and 0 deletions

View File

@@ -222,6 +222,14 @@ impl Global {
} }
} }
impl std::cmp::PartialEq for Global {
fn eq(&self, other: &Self) -> bool {
self.handle == other.handle
}
}
impl std::cmp::Eq for Global {}
impl<'a> Exportable<'a> for Global { impl<'a> Exportable<'a> for Global {
fn get_self_from_extern(_extern: &'a Extern) -> Result<&'a Self, ExportError> { fn get_self_from_extern(_extern: &'a Extern) -> Result<&'a Self, ExportError> {
match _extern { match _extern {

View File

@@ -239,6 +239,14 @@ impl Memory {
} }
} }
impl std::cmp::PartialEq for Memory {
fn eq(&self, other: &Self) -> bool {
self.handle == other.handle
}
}
impl std::cmp::Eq for Memory {}
impl<'a> Exportable<'a> for Memory { impl<'a> Exportable<'a> for Memory {
fn get_self_from_extern(_extern: &'a Extern) -> Result<&'a Self, ExportError> { fn get_self_from_extern(_extern: &'a Extern) -> Result<&'a Self, ExportError> {
match _extern { match _extern {

View File

@@ -196,6 +196,14 @@ impl Table {
} }
} }
impl std::cmp::PartialEq for Table {
fn eq(&self, other: &Self) -> bool {
self.handle == other.handle
}
}
impl std::cmp::Eq for Table {}
impl<'a> Exportable<'a> for Table { impl<'a> Exportable<'a> for Table {
fn get_self_from_extern(_extern: &'a Extern) -> Result<&'a Self, ExportError> { fn get_self_from_extern(_extern: &'a Extern) -> Result<&'a Self, ExportError> {
match _extern { match _extern {

View File

@@ -99,6 +99,14 @@ pub unsafe extern "C" fn wasm_global_set(global: &mut wasm_global_t, val: &wasm_
} }
} }
#[no_mangle]
pub unsafe extern "C" fn wasm_global_same(
wasm_global1: &wasm_global_t,
wasm_global2: &wasm_global_t,
) -> bool {
wasm_global1.inner == wasm_global2.inner
}
#[no_mangle] #[no_mangle]
pub extern "C" fn wasm_global_type( pub extern "C" fn wasm_global_type(
global: Option<&wasm_global_t>, global: Option<&wasm_global_t>,

View File

@@ -53,6 +53,14 @@ pub unsafe extern "C" fn wasm_memory_copy(memory: &wasm_memory_t) -> Box<wasm_me
Box::new(wasm_memory_t::new((&*memory.inner).clone())) Box::new(wasm_memory_t::new((&*memory.inner).clone()))
} }
#[no_mangle]
pub unsafe extern "C" fn wasm_memory_same(
wasm_memory1: &wasm_memory_t,
wasm_memory2: &wasm_memory_t,
) -> bool {
wasm_memory1.inner == wasm_memory2.inner
}
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn wasm_memory_type( pub unsafe extern "C" fn wasm_memory_type(
memory: Option<&wasm_memory_t>, memory: Option<&wasm_memory_t>,

View File

@@ -53,6 +53,14 @@ pub unsafe extern "C" fn wasm_table_size(table: &wasm_table_t) -> usize {
table.inner.size(&ctx.inner) as _ table.inner.size(&ctx.inner) as _
} }
#[no_mangle]
pub unsafe extern "C" fn wasm_table_same(
wasm_table1: &wasm_table_t,
wasm_table2: &wasm_table_t,
) -> bool {
wasm_table1.inner == wasm_table2.inner
}
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn wasm_table_grow( pub unsafe extern "C" fn wasm_table_grow(
_table: &mut wasm_table_t, _table: &mut wasm_table_t,

View File

@@ -123,6 +123,14 @@ impl<T: ContextObject> fmt::Debug for ContextHandle<T> {
} }
} }
impl<T: ContextObject> PartialEq for ContextHandle<T> {
fn eq(&self, other: &Self) -> bool {
self.id == other.id && self.internal == other.internal
}
}
impl<T: ContextObject> Eq for ContextHandle<T> {}
impl<T: ContextObject> ContextHandle<T> { impl<T: ContextObject> ContextHandle<T> {
/// Moves the given object into a context and returns a handle to it. /// Moves the given object into a context and returns a handle to it.
pub fn new(ctx: &mut ContextObjects, val: T) -> Self { pub fn new(ctx: &mut ContextObjects, val: T) -> Self {