Stream: git-wasmtime

Topic: wasmtime / issue #2748 Clarify ownership of data returned...


view this post on Zulip Wasmtime GitHub notifications bot (Nov 21 2021 at 21:14):

pnevyk commented on issue #2748:

What was the reason for changing the free_memory signature from &mut self to mut self?

I have a struct that encapsulates JITModule and compiles expressions to functions, while storing the raw pointer into internal vector and returning only an index to this vector which identifies the expression for later evaluation. In Drop of my struct I was calling self.module.free_memory, which I believe was safe to do, because no raw pointers got out to the user of my struct.

When I updated to the current version with this change, the borrow checker is not happy anymore. What is the intended usage of free_memory?

Thanks.

view this post on Zulip Wasmtime GitHub notifications bot (Nov 21 2021 at 21:26):

pnevyk edited a comment on issue #2748:

What was the reason for changing the free_memory signature from &mut self to mut self?

I have a struct that encapsulates JITModule and compiles expressions to functions, while storing the raw pointer into internal vector and returning only an index to this vector which identifies the expression for later evaluation. In Drop of my struct I was calling self.module.free_memory, which I believe was safe to do, because no raw pointers got out to the user of my struct.

When I updated to the current version with this change, the borrow checker is not happy anymore. ~What is the intended usage of free_memory?~

EDIT: I now see the benefit of this change of guaranteeing that the method is called at most once. However, since it is unsafe function, I think it could stay &mut self, not preventing the use cases as mine.

Thanks.


Last updated: Dec 23 2024 at 12:05 UTC