Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-export EngineWeak from the wasmi crate #1003

Merged
merged 2 commits into from
Apr 24, 2024
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ Dates in this file are formattes as `YYYY-MM-DD`.
config.engine_limits(wasmi::EnforcedLimits::strict());
```
In future updates we might relax this to make `EnforcedLimits` fully customizable.
- Added `EngineWeak` constructed via `Engine::weak`. (https://github.com/wasmi-labs/wasmi/pull/1003)
- This properly mirrors the Wasmtime API and allows users to store weak references to the `Engine`.

### Changed

Expand Down
10 changes: 4 additions & 6 deletions crates/wasmi/src/engine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,17 +119,15 @@ pub struct Engine {
}

/// A weak reference to an [`Engine`].
///
/// # Note
///
/// This was required to break a reference cycle between [`Engine`] and [`ModuleHeader`].
#[derive(Debug, Clone)]
pub struct EngineWeak {
inner: Weak<EngineInner>,
}

impl EngineWeak {
/// Upgrades the [`EngineWeak`] to an [`Engine`] if the [`Engine`] does still exist.
/// Upgrades the [`EngineWeak`] to an [`Engine`].
///
/// Returns `None` if strong references (the [`Engine`] itself) no longer exist.
pub fn upgrade(&self) -> Option<Engine> {
let inner = self.inner.upgrade()?;
Some(Engine { inner })
Expand All @@ -155,7 +153,7 @@ impl Engine {
}

/// Creates an [`EngineWeak`] from the given [`Engine`].
pub(crate) fn downgrade(&self) -> EngineWeak {
pub fn weak(&self) -> EngineWeak {
EngineWeak {
inner: Arc::downgrade(&self.inner),
}
Expand Down
1 change: 1 addition & 0 deletions crates/wasmi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ pub use self::{
Config,
EnforcedLimits,
Engine,
EngineWeak,
ResumableCall,
ResumableInvocation,
StackLimits,
Expand Down
2 changes: 1 addition & 1 deletion crates/wasmi/src/module/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl ModuleHeaderBuilder {
pub fn finish(self) -> ModuleHeader {
ModuleHeader {
inner: Arc::new(ModuleHeaderInner {
engine: self.engine.downgrade(),
engine: self.engine.weak(),
func_types: self.func_types.into(),
imports: self.imports.finish(),
funcs: self.funcs.into(),
Expand Down
Loading