mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-07 21:28:21 +00:00
Revert Table::get method to return Option
This commit is contained in:
2
lib/api/src/externals/function.rs
vendored
2
lib/api/src/externals/function.rs
vendored
@@ -950,7 +950,7 @@ mod inner {
|
||||
use std::marker::PhantomData;
|
||||
use std::panic::{self, AssertUnwindSafe};
|
||||
use wasmer_types::{FunctionType, NativeWasmType, Type};
|
||||
use wasmer_vm::{raise_user_trap, resume_panic, VMExternRef, VMFuncRef, VMFunctionBody};
|
||||
use wasmer_vm::{raise_user_trap, resume_panic, VMFunctionBody};
|
||||
|
||||
/// A trait to convert a Rust value to a `WasmNativeType` value,
|
||||
/// or to convert `WasmNativeType` value to a Rust value.
|
||||
|
||||
2
lib/api/src/externals/table.rs
vendored
2
lib/api/src/externals/table.rs
vendored
@@ -71,7 +71,7 @@ impl Table {
|
||||
pub fn get(&self, index: u32) -> Option<Val> {
|
||||
// TODO: review change to make inner table return a trap in Result, maybe we don't
|
||||
// want that
|
||||
let item = self.table.get(index).ok()?;
|
||||
let item = self.table.get(index)?;
|
||||
Some(ValFuncRef::from_table_reference(item, &self.store))
|
||||
}
|
||||
|
||||
|
||||
@@ -578,7 +578,7 @@ impl Instance {
|
||||
&self,
|
||||
table_index: LocalTableIndex,
|
||||
index: u32,
|
||||
) -> Result<TableReference, Trap> {
|
||||
) -> Option<TableReference> {
|
||||
self.tables
|
||||
.get(table_index)
|
||||
.unwrap_or_else(|| panic!("no table for index {}", table_index.index()))
|
||||
@@ -596,7 +596,7 @@ impl Instance {
|
||||
&self,
|
||||
table_index: TableIndex,
|
||||
index: u32,
|
||||
) -> Result<TableReference, Trap> {
|
||||
) -> Option<TableReference> {
|
||||
let import = self.imported_table(table_index);
|
||||
let from = import.from.as_ref();
|
||||
from.get(index)
|
||||
@@ -1261,11 +1261,7 @@ impl InstanceHandle {
|
||||
/// Get table element reference.
|
||||
///
|
||||
/// Returns `None` if index is out of bounds.
|
||||
pub fn table_get(
|
||||
&self,
|
||||
table_index: LocalTableIndex,
|
||||
index: u32,
|
||||
) -> Result<TableReference, Trap> {
|
||||
pub fn table_get(&self, table_index: LocalTableIndex, index: u32) -> Option<TableReference> {
|
||||
self.instance().as_ref().table_get(table_index, index)
|
||||
}
|
||||
|
||||
|
||||
@@ -322,8 +322,8 @@ pub unsafe extern "C" fn wasmer_table_get(
|
||||
|
||||
// TODO: type checking, maybe have specialized accessors
|
||||
match instance.table_get(table_index, elem_index) {
|
||||
Ok(table_ref) => table_ref.into(),
|
||||
Err(trap) => raise_lib_trap(trap),
|
||||
Some(table_ref) => table_ref.into(),
|
||||
None => raise_lib_trap(Trap::new_from_runtime(TrapCode::TableAccessOutOfBounds)),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -342,8 +342,8 @@ pub unsafe extern "C" fn wasmer_imported_table_get(
|
||||
|
||||
// TODO: type checking, maybe have specialized accessors
|
||||
match instance.imported_table_get(table_index, elem_index) {
|
||||
Ok(table_ref) => table_ref.into(),
|
||||
Err(trap) => raise_lib_trap(trap),
|
||||
Some(table_ref) => table_ref.into(),
|
||||
None => raise_lib_trap(Trap::new_from_runtime(TrapCode::TableAccessOutOfBounds)),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ pub trait Table: fmt::Debug + Send + Sync {
|
||||
/// Get reference to the specified element.
|
||||
///
|
||||
/// Returns `None` if the index is out of bounds.
|
||||
fn get(&self, index: u32) -> Result<TableReference, Trap>;
|
||||
fn get(&self, index: u32) -> Option<TableReference>;
|
||||
|
||||
/// Set reference to the specified element.
|
||||
///
|
||||
@@ -332,14 +332,10 @@ impl Table for LinearTable {
|
||||
/// Get reference to the specified element.
|
||||
///
|
||||
/// Returns `None` if the index is out of bounds.
|
||||
fn get(&self, index: u32) -> Result<TableReference, Trap> {
|
||||
fn get(&self, index: u32) -> Option<TableReference> {
|
||||
let vec_guard = self.vec.lock().unwrap();
|
||||
let raw_data = vec_guard
|
||||
.borrow()
|
||||
.get(index as usize)
|
||||
.cloned()
|
||||
.ok_or_else(|| Trap::new_from_runtime(TrapCode::TableAccessOutOfBounds))?;
|
||||
Ok(match self.table.ty {
|
||||
let raw_data = vec_guard.borrow().get(index as usize).cloned()?;
|
||||
Some(match self.table.ty {
|
||||
ValType::ExternRef => {
|
||||
// TODO: there is no matching `drop` for this `clone` implemented yet.
|
||||
// thus extern refs will always leak memory if this path is touched.
|
||||
|
||||
Reference in New Issue
Block a user