-
Notifications
You must be signed in to change notification settings - Fork 4
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
Conversation
…gth_safe to low level api
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.
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
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; |
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.
It's awesome that with the high-level API this just becomes:
extism_output_buf_from_sz("Hello, world");
return 0;
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 calledExtismHandle
.The functions taking
ExtismHandle
check against the bounds of the memory block referenced. The functions takingExtismPointer
are not available for use without#define EXTISM_ENABLE_LOW_LEVEL_API
Additionally, the
sz
anddup
functions now are available for all data that can be loaded in extism memory, not just input.Resolves #19