-
Notifications
You must be signed in to change notification settings - Fork 13
sdk: prerun+varargs #254
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
Open
dbentley-vsql
wants to merge
1
commit into
main
Choose a base branch
from
dbentley/sdk_varargs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
sdk: prerun+varargs #254
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -126,6 +126,57 @@ void ba_concat(CustomArg a, CustomArg b, StringResult out) { | |
| out.set_length(kBytearrayLen * 2); | ||
| } | ||
|
|
||
| // BA_LEN: return the fixed length of a BYTEARRAY (zero-arity constant function) | ||
| void ba_len(IntResult out) { out.set(static_cast<long long>(kBytearrayLen)); } | ||
|
|
||
| // BA_CONCAT_ALL: concatenate any number of bytearrays (returns STRING). | ||
| // | ||
| // This demonstrates the "Escape Hatch" pattern: ba_concat above uses the | ||
| // typed Happy Path API (CustomArg, StringResult), but only supports exactly | ||
| // two arguments. ba_concat_all drops down to the raw ABI to accept varargs, | ||
| // using prerun to validate argument types and size the result buffer. | ||
|
|
||
| // Prerun: validate that all arguments are BYTEARRAY and request a buffer | ||
| // large enough to hold them all concatenated. | ||
| void ba_concat_all_prerun(vef_context_t *, vef_prerun_args_t *args, | ||
| vef_prerun_result_t *result) { | ||
| if (args->arg_count == 0) { | ||
| result->type = VEF_RESULT_ERROR; | ||
| snprintf(result->error_msg, VEF_MAX_ERROR_LEN, | ||
| "ba_concat_all requires at least one argument"); | ||
| return; | ||
| } | ||
| for (unsigned int i = 0; i < args->arg_count; i++) { | ||
| // NULL literals appear as VEF_TYPE_STRING in prerun; skip type check for | ||
| // those and handle them at runtime. | ||
| vef_type_id id = args->arg_types[i].id; | ||
| if (id != VEF_TYPE_CUSTOM && id != VEF_TYPE_STRING) { | ||
| result->type = VEF_RESULT_ERROR; | ||
| snprintf(result->error_msg, VEF_MAX_ERROR_LEN, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This too.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done (see above) |
||
| "ba_concat_all: argument %u must be BYTEARRAY", i); | ||
| return; | ||
| } | ||
| } | ||
| result->result_buffer_size = args->arg_count * kBytearrayLen; | ||
| } | ||
|
|
||
| // Main function: raw ABI signature since we iterate over a variable number | ||
| // of arguments. | ||
| void ba_concat_all(vef_context_t *ctx, vef_vdf_args_t *args, | ||
| vef_vdf_result_t *result) { | ||
| size_t total_len = args->value_count * kBytearrayLen; | ||
| for (unsigned int i = 0; i < args->value_count; i++) { | ||
| vef_invalue_t val = vsql::func_builder::get_invalue(ctx, args, i); | ||
| if (val.is_null) { | ||
| result->type = VEF_RESULT_NULL; | ||
| return; | ||
| } | ||
| memcpy(result->str_buf + i * kBytearrayLen, val.bin_value, kBytearrayLen); | ||
| } | ||
| result->type = VEF_RESULT_VALUE; | ||
| result->actual_len = total_len; | ||
| } | ||
|
|
||
| static constexpr const char kBytearrayTypeName[] = "bytearray"; | ||
|
|
||
| constexpr auto BYTEARRAY = vsql::make_type<kBytearrayTypeName>() | ||
|
|
@@ -136,22 +187,29 @@ constexpr auto BYTEARRAY = vsql::make_type<kBytearrayTypeName>() | |
| .compare<&bytearray_compare>() | ||
| .build(); | ||
|
|
||
| VEF_GENERATE_ENTRY_POINTS(make_extension() | ||
| .type(BYTEARRAY) | ||
| .func(make_func<&rot13>("rot13") | ||
| .returns(BYTEARRAY) | ||
| .param(BYTEARRAY) | ||
| .build()) | ||
| .func(make_func<&even_chars>("even_chars") | ||
| .returns(BYTEARRAY) | ||
| .param(BYTEARRAY) | ||
| .build()) | ||
| .func(make_func<&odd_chars>("odd_chars") | ||
| .returns(BYTEARRAY) | ||
| .param(BYTEARRAY) | ||
| .build()) | ||
| .func(make_func<&ba_concat>("ba_concat") | ||
| .returns(STRING) | ||
| .param(BYTEARRAY) | ||
| .param(BYTEARRAY) | ||
| .build())) | ||
| VEF_GENERATE_ENTRY_POINTS( | ||
| make_extension() | ||
| .type(BYTEARRAY) | ||
| .func(make_func<&rot13>("rot13") | ||
| .returns(BYTEARRAY) | ||
| .param(BYTEARRAY) | ||
| .build()) | ||
| .func(make_func<&even_chars>("even_chars") | ||
| .returns(BYTEARRAY) | ||
| .param(BYTEARRAY) | ||
| .build()) | ||
| .func(make_func<&odd_chars>("odd_chars") | ||
| .returns(BYTEARRAY) | ||
| .param(BYTEARRAY) | ||
| .build()) | ||
| .func(make_func<&ba_concat>("ba_concat") | ||
| .returns(STRING) | ||
| .param(BYTEARRAY) | ||
| .param(BYTEARRAY) | ||
| .build()) | ||
| .func(make_func<&ba_len>("ba_len").returns(INT).param().build()) | ||
| .func(make_func<&ba_concat_all>("ba_concat_all") | ||
| .returns(STRING) | ||
| .varargs() | ||
| .prerun<&ba_concat_all_prerun>() | ||
| .build())) | ||
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Please test these errors.
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.
done (extension_simple_type_usage.result)