-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: improve input loading and string handling (#16)
* chore: improve code quality * take `void *` instead of `uint8_t*` for buffer params * add `const` to imports to signify when a ExtismPointer's data is modified * pass void to imports that shouldn't take parameters * minor cleanup in store and load functions * use size_t for pdk offsets and sizes instead of hardcoding it to uint64_t. * in wasm32 its 4 bytes * in wasm64 its 8 bytes * deprecate extism_alloc_string / add extism_alloc_buf * chore: namespace import macros * feat: implement convenience methods to load extism memory into zero terminated and malloc'd buffers * test: add tests for new functions, check input length before loading input, rename parameters to be more like libc
- Loading branch information
Showing
8 changed files
with
239 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#include "util.h" | ||
|
||
EXTISM_EXPORT_AS("run_test") int32_t run_test(void) { | ||
const char *msg = "Hello, world!"; | ||
ExtismPointer ptr = extism_alloc_buf_from_sz(msg); | ||
assert(ptr > 0); | ||
assert(extism_length(ptr) == extism_strlen(msg)); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#include "util.h" | ||
|
||
EXTISM_EXPORT_AS("run_test") int32_t run_test(void) { | ||
char c[2]; | ||
extism_load_input_unsafe(c, 0); | ||
assert(extism_load_input(c, 0)); | ||
assert(!extism_load_input(c, 1)); | ||
extism_load_input_sz_unsafe(c, 1); | ||
assert(!extism_load_input_sz(c, 0)); | ||
assert(extism_load_input_sz(c, 1)); | ||
assert(!extism_load_input_sz(c, 2)); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#include "util.h" | ||
#include <string.h> | ||
|
||
EXTISM_EXPORT_AS("run_test") int32_t run_test(void) { | ||
const char *hello = "hello"; | ||
assert(strlen(hello) == extism_strlen(hello)); | ||
assert(strlen("") == extism_strlen("")); | ||
return 0; | ||
} |
Oops, something went wrong.