-
Notifications
You must be signed in to change notification settings - Fork 11
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
Do not free memory that needs to persist in the host #34
Conversation
Signed-off-by: Glenn Lewis <[email protected]>
I'm now wondering if In fact, I'm now thinking that the Additionally, I'm thinking that the MoonBit PDK also needs to do similar things... basically giving more memory control to the PDK user. |
Signed-off-by: Glenn Lewis <[email protected]>
extism_pdk.go
Outdated
@@ -230,19 +234,19 @@ func GetVarInt(key string) int { | |||
|
|||
func SetVarInt(key string, value int) { | |||
keyMem := AllocateBytes([]byte(key)) | |||
defer keyMem.Free() | |||
defer mem.Free() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps I'm missing its definition, but where does mem
come from?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yikes, I should not have done that in a hurry. I'm on a flight now but will fix this later tonight.
Sorry.
OutputMemory(AllocateBytes(b)) | ||
mem := AllocateBytes(b) | ||
defer mem.Free() | ||
OutputMemory(mem) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we'd retain memory that needs to be accessed by the host elsewhere, shouldn't that also be true here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So my thought here was that the host would output the information immediately and the memory could be freed. That seemed to work in the MoonBit PDK but this is one reason why I think a suite of conformance tests would be fantastic... To help answer questions like this one.
Signed-off-by: Glenn Lewis <[email protected]>
I've fixed the error and run the tests, and it all appears to work now. Sorry about that.
|
|
It seems like this is actually related to how the js-sdk has implemented var storage, I just opened a PR here: extism/js-sdk#71 Some of these other changes seem good though so I think this could still be worth merging with some small modifications |
extism_pdk.go
Outdated
@@ -208,13 +212,13 @@ func SetVar(key string, value []byte) { | |||
defer keyMem.Free() | |||
|
|||
valMem := AllocateBytes(value) | |||
defer valMem.Free() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should add this back since extism/js-sdk#71 addresses the root of the issue
Signed-off-by: Glenn Lewis <[email protected]>
As documented in the #js-sdk Discord channel, I believe that the Go PDK should not be freeing memory that needs to persist in the host.
This PR addresses this issue.