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

feat: seperate pointer from handle #18

Merged
merged 5 commits into from
Jan 4, 2024
Merged

Conversation

G4Vi
Copy link
Contributor

@G4Vi G4Vi commented Dec 22, 2023

This makes the c-pdk slightly safer by using separate types for ExtismPointer and a pointer in extism memory to the start of data in a memory block (here called ExtismHandle.

The functions taking ExtismHandle check against the bounds of the memory block referenced. The functions taking ExtismPointer are not available for use without #define EXTISM_ENABLE_LOW_LEVEL_API

Additionally, the sz and dup functions now are available for all data that can be loaded in extism memory, not just input.

Resolves #19

@G4Vi G4Vi marked this pull request as ready for review January 3, 2024 23:16
@G4Vi G4Vi requested a review from zshipko January 3, 2024 23:16
Copy link
Contributor

@zshipko zshipko left a comment

Choose a reason for hiding this comment

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

Thanks, this is a major improvement! I will try to make some plugins with the new interface over the next few days, definitely curious to try it out

Comment on lines 5 to 11
const char *msg = "Hello, world!";
ExtismPointer ptr = extism_alloc(extism_strlen(msg));
assert(ptr > 0);
extism_store(ptr, (const uint8_t *)msg, extism_strlen(msg));
assert(extism_length(ptr) == extism_strlen(msg));
extism_output_set(ptr, extism_strlen(msg));
ExtismHandle buf = extism_alloc(extism_strlen(msg));
assert(buf > 0);
extism_store_to_handle(buf, 0, msg, extism_strlen(msg));
assert(extism_length(buf) == extism_strlen(msg));
extism_output_handle(buf);
return 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

It's awesome that with the high-level API this just becomes:

extism_output_buf_from_sz("Hello, world");
return 0;

@G4Vi G4Vi merged commit 6e3323b into main Jan 4, 2024
2 checks passed
@G4Vi G4Vi deleted the feat-seperate-pointer-from-handle branch January 4, 2024 05:45
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.

Seperate ExtismPointer from handle
2 participants