Skip to content

fix: pass memory ownership to host functions - #2

Merged
G4Vi merged 1 commit into
mainfrom
fix-adapt-host-function-memory-ownership
Sep 23, 2024
Merged

G4Vi merged 1 commit into
mainfrom
fix-adapt-host-function-memory-ownership

Conversation

@G4Vi

@G4Vi G4Vi commented Sep 20, 2024

Copy link
Copy Markdown
Contributor

fixes #1

UniqueHandle<T> automatically frees their extism memory when they go out of scope so memory passed into those host functions is now allocated to the non-owning Handle<T>

bool var_set(const std::string_view name, const imports::RawHandle value); was replaced with

template <typename T = char> bool var_set(const std::string_view name, UniqueHandle<T> unique_value); as it now need ownership of the value. It is not freed by C++ as .release is called just like it is done for output.

@G4Vi
G4Vi requested a review from zshipko September 20, 2024 18:46

@zshipko zshipko left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Looks good!

Unrelated, but I'm excited to try out the cpp-pdk, I appreciate the thought put into the design!

@G4Vi
G4Vi merged commit a0149b2 into main Sep 23, 2024
@G4Vi
G4Vi deleted the fix-adapt-host-function-memory-ownership branch September 23, 2024 18:20
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.

Extism host functions should take ownership of memory passed in

2 participants