Skip to content

Conversation

zshipko
Copy link
Contributor

@zshipko zshipko commented Aug 29, 2024

Updates plugins to allocate a single ExternRef for the host context up front, to avoid running into the failed to allocate externref error from Wasmtime

@zshipko zshipko requested a review from chrisdickinson August 29, 2024 23:47
Copy link
Contributor

@chrisdickinson chrisdickinson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oof, that's a tricky one! I left one comment to address – zeroing out self.host_context when we don't receive a host context – but otherwise I think this LGTM!

@@ -366,7 +368,7 @@ fn test_call_with_host_context() {
[PTR],
UserData::default(),
|current_plugin, _val, ret, _user_data: UserData<()>| {
let foo = current_plugin.host_context::<Foo>()?;
let foo = current_plugin.host_context::<Foo>()?.clone();
let hnd = current_plugin.memory_new(foo.message)?;
ret[0] = current_plugin.memory_to_val(hnd);
Ok(())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The invariant that's on my mind: if I call_with_host_context(host context = A) and then call(), will host functions invoked by the second call see A as their context?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The host context should be reset before the next call (see the comment below for the link)

}
Some(self.host_context.clone())
} else {
None
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we may want to zero out self.host_context here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made it so we're zeroing out the host context after each call: https://github.com/extism/extism/pull/759/files/be744b5ea7df5c1a6f3d5accb28324c811a71e73#diff-fc3b26932af6a72d6a908c3d72663d22045526b2c46c6777aadeb7852d1137d4R816 - but am open to moving it up to here if you think that makes more sense.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, perfect! That makes sense.

@zshipko zshipko merged commit d2a3699 into main Aug 30, 2024
5 checks passed
@zshipko zshipko deleted the fix-host-context branch August 30, 2024 00:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants