Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ext/src/ruby_api/component/func.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,12 @@ impl Func {
args: &[Value],
) -> Result<Value, Error> {
let store_context_value = StoreContextValue::from(store);
let func_ty = func.ty(store.context_mut());
let func_ty = func.ty(store.context_mut()?);
let results_ty = func_ty.results();
let mut results = vec![wasmtime::component::Val::Bool(false); results_ty.len()];
let params = convert_params(ruby, &store_context_value, func_ty.params(), args)?;

func.call(store.context_mut(), &params, &mut results)
func.call(store.context_mut()?, &params, &mut results)
.map_err(|e| store_context_value.handle_wasm_error(ruby, e))?;

// Check for any errors stored during execution (e.g., from socket checks)
Expand Down
11 changes: 7 additions & 4 deletions ext/src/ruby_api/component/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,12 @@ impl Instance {
/// @example Retrieve an +add+ export nested under an +adder+ instance top-level export:
/// instance.get_func(["adder", "add"])
pub fn get_func(rb_self: Obj<Self>, handle: Value) -> Result<Option<Func>, Error> {
let Some(index) = rb_self.export_index(handle)? else {
return Ok(None);
};
let func = rb_self
.export_index(handle)?
.and_then(|index| rb_self.inner.get_func(rb_self.store.context_mut(), index))
.inner
.get_func(rb_self.store.context_mut()?, index)
.map(|inner| Func::from_inner(inner, rb_self, rb_self.store));

Ok(func)
Expand All @@ -76,7 +79,7 @@ impl Instance {

let index = if let Some(name) = RString::from_value(handle) {
self.inner
.get_export(self.store.context_mut(), None, unsafe { name.as_str()? })
.get_export(self.store.context_mut()?, None, unsafe { name.as_str()? })
.map(|(_, index)| index)
} else if let Some(names) = RArray::from_value(handle) {
unsafe { names.as_slice() }
Expand All @@ -86,7 +89,7 @@ impl Instance {

Ok(self
.inner
.get_export(self.store.context_mut(), index.as_ref(), unsafe {
.get_export(self.store.context_mut()?, index.as_ref(), unsafe {
name.as_str()?
})
.map(|(_, index)| index))
Expand Down
4 changes: 2 additions & 2 deletions ext/src/ruby_api/component/linker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,13 @@ impl Linker {
store: Obj<Store>,
component: &Component,
) -> Result<Instance, Error> {
if *rb_self.has_wasi.borrow() && !store.context().data().has_wasi_ctx() {
if *rb_self.has_wasi.borrow() && !store.context()?.data().has_wasi_ctx() {
return err!("{}", errors::missing_wasi_ctx_error("linker.instantiate"));
}

let inner = rb_self.inner.borrow();
inner
.instantiate(store.context_mut(), component.get())
.instantiate(store.context_mut()?, component.get())
.map(|instance| {
rb_self
.refs
Expand Down
6 changes: 3 additions & 3 deletions ext/src/ruby_api/component/wasi_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ impl WasiCommand {
/// @param linker [Linker]
/// @return [WasiCommand]
pub fn new(store: &Store, component: &Component, linker: &Linker) -> Result<Self, Error> {
if linker.has_wasi() && !store.context().data().has_wasi_ctx() {
if linker.has_wasi() && !store.context()?.data().has_wasi_ctx() {
return err!("{}", errors::missing_wasi_ctx_error("WasiCommand.new"));
}
let command =
Command::instantiate(store.context_mut(), component.get(), &linker.inner_mut())
Command::instantiate(store.context_mut()?, component.get(), &linker.inner_mut())
.map_err(|e| error!("{e}"))?;
Ok(Self { command })
}
Expand All @@ -45,7 +45,7 @@ impl WasiCommand {
rb_self
.command
.wasi_cli_run()
.call_run(store.context_mut())
.call_run(store.context_mut()?)
.map_err(|err| error!("{err}"))?
.map_err(|_| error!("Error running `run`"))?;

Expand Down
2 changes: 1 addition & 1 deletion ext/src/ruby_api/func.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ impl<'a> Func<'a> {

store.retain(callable.as_value());

let context = store.context_mut();
let context = store.context_mut()?;
let engine = context.engine();
let ty = wasmtime::FuncType::new(
engine,
Expand Down
2 changes: 1 addition & 1 deletion ext/src/ruby_api/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ impl<'a> Global<'a> {
let wasm_type = value_type.to_val_type()?;
let wasm_default = default.to_wasm_val(&store.into(), wasm_type.clone())?;
let inner = GlobalImpl::new(
store.context_mut(),
store.context_mut()?,
wasmtime::GlobalType::new(wasm_type, mutability),
wasm_default,
)
Expand Down
8 changes: 4 additions & 4 deletions ext/src/ruby_api/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl Instance {
let args =
scan_args::scan_args::<(Obj<Store>, &Module), (Option<Value>,), (), (), (), ()>(args)?;
let (wrapped_store, module) = args.required;
let mut context = wrapped_store.context_mut();
let mut context = wrapped_store.context_mut()?;
let imports = args
.optional
.0
Expand Down Expand Up @@ -87,7 +87,7 @@ impl Instance {
/// @def exports
/// @return [Hash{String => Extern}]
pub fn exports(ruby: &Ruby, rb_self: Obj<Self>) -> Result<RHash, Error> {
let mut ctx = rb_self.store.context_mut();
let mut ctx = rb_self.store.context_mut()?;
let hash = ruby.hash_new();

for export in rb_self.inner.exports(&mut ctx) {
Expand All @@ -111,7 +111,7 @@ impl Instance {
pub fn export(&self, str: RString) -> Result<Option<super::externals::Extern<'_>>, Error> {
let export = self
.inner
.get_export(self.store.context_mut(), unsafe { str.as_str()? });
.get_export(self.store.context_mut()?, unsafe { str.as_str()? });
let ruby = Ruby::get_with(str);
match export {
Some(export) => export
Expand All @@ -138,7 +138,7 @@ impl Instance {
)
})?)?;

let func = rb_self.get_func(rb_self.store.context_mut(), unsafe { name.as_str()? })?;
let func = rb_self.get_func(rb_self.store.context_mut()?, unsafe { name.as_str()? })?;
Func::invoke(ruby, &rb_self.store.into(), &func, true, &args[1..])
}

Expand Down
18 changes: 11 additions & 7 deletions ext/src/ruby_api/linker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ impl Linker {
.inner
.borrow_mut()
.define(
store.context(),
store.context()?,
unsafe { module.as_str()? },
unsafe { name.as_str()? },
item,
Expand Down Expand Up @@ -167,7 +167,7 @@ impl Linker {
let ext = self
.inner
.borrow()
.get(store.context_mut(), unsafe { module.as_str() }?, unsafe {
.get(store.context_mut()?, unsafe { module.as_str() }?, unsafe {
name.as_str()?
})
.map_err(|e| error!("{}", e))?;
Expand All @@ -193,7 +193,7 @@ impl Linker {
self.inner
.borrow_mut()
.instance(
store.context_mut(),
store.context_mut()?,
unsafe { module.as_str() }?,
instance.get(),
)
Expand All @@ -212,7 +212,11 @@ impl Linker {
pub fn module(&self, store: &Store, name: RString, module: &Module) -> Result<(), Error> {
self.inner
.borrow_mut()
.module(store.context_mut(), unsafe { name.as_str()? }, module.get())
.module(
store.context_mut()?,
unsafe { name.as_str()? },
module.get(),
)
.map(|_| ())
.map_err(|e| error!("{}", e))
}
Expand Down Expand Up @@ -272,14 +276,14 @@ impl Linker {
store: Obj<Store>,
module: &Module,
) -> Result<Instance, Error> {
if *rb_self.has_wasi.borrow() && !store.context().data().has_wasi_p1_ctx() {
if *rb_self.has_wasi.borrow() && !store.context()?.data().has_wasi_p1_ctx() {
return err!("{}", errors::missing_wasi_p1_ctx_error());
}

rb_self
.inner
.borrow_mut()
.instantiate(store.context_mut(), module.get())
.instantiate(store.context_mut()?, module.get())
.map_err(|e| StoreContextValue::from(store).handle_wasm_error(ruby, e))
.map(|instance| {
rb_self
Expand All @@ -300,7 +304,7 @@ impl Linker {
pub fn get_default(&self, store: Obj<Store>, module: RString) -> Result<Func<'_>, Error> {
self.inner
.borrow()
.get_default(store.context_mut(), unsafe { module.as_str() }?)
.get_default(store.context_mut()?, unsafe { module.as_str() }?)
.map(|func| Func::from_inner(store.into(), func))
.map_err(|e| error!("{}", e))
}
Expand Down
2 changes: 1 addition & 1 deletion ext/src/ruby_api/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ impl<'a> Memory<'a> {

let memtype = wasmtime::MemoryType::new(min, max);

let inner = MemoryImpl::new(store.context_mut(), memtype).map_err(|e| error!("{}", e))?;
let inner = MemoryImpl::new(store.context_mut()?, memtype).map_err(|e| error!("{}", e))?;

Ok(Self {
store: store.into(),
Expand Down
Loading
Loading