You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
NB: this is analogous to #254 , but rebased and simplified
sdk: typed varargs + required explicit arity
Introduce typed C++ wrappers for varargs VDFs (vsql::VarArgs, vsql::AnyArg)
and the matching .varargs() / zero-arity .param() builder methods, so an
extension author can write a variadic SQL function without touching raw ABI
types. Also tightens the v2 builder to require an explicit arity
declaration before .build().
What changes for users
Before, an extension author who wanted a varargs SQL function had to drop
out of the typed SDK and write a raw-ABI body — the typed wrappers covered
fixed-arity only:
// Old: raw vef_vdf_func_t signature, manual invalue extraction
void ba_concat_all(vef_context_t *ctx, vef_vdf_args_t *args,
vef_vdf_result_t *result) {
for (unsigned int i = 0; i < args->value_count; i++) {
vef_invalue_t v = vsql::func_builder::get_invalue(ctx, args, i);
if (v.is_null) { result->type = VEF_RESULT_NULL; return; }
memcpy(result->str_buf + i * N, v.bin_value, N);
}
result->type = VEF_RESULT_VALUE;
result->actual_len = args->value_count * N;
}
After:
// New: typed VarArgs + AnyArg, no raw ABI in the body
void ba_concat_all(vsql::VarArgs args, vsql::StringResult out) {
auto dst = out.buffer();
size_t off = 0;
for (auto a : args) {
if (a.is_null()) { out.set_null(); return; }
auto bytes = a.as_custom();
memcpy(dst.data() + off, bytes.data(), bytes.size());
off += bytes.size();
}
out.set_length(off);
}
Registration picks up .varargs() (and zero-arity .param()):
.func(make_func<&ba_len>("ba_len")
.returns(INT)
.param() // explicit zero-arity
.build())
.func(make_func<&ba_concat_all>("ba_concat_all")
.returns(STRING)
.varargs()
.prerun<&ba_concat_all_prerun>()
.build())
The prerun hook is still raw ABI in this PR; the typed variant lands with
#551 (typed vsql::PrerunArgs / PrerunResult), and ba_concat_all_prerun
will convert to typed form when that merges.
Required-arity change
The v2 builder now rejects make_func<&fn>("name").returns(...).build()
without an arity call. You must pick exactly one of:
.param(TYPE) (one or more, for fixed-arity typed args)
.param() (zero-arity)
.varargs()
Eight in-tree test-extensions had implicit zero-arity functions and pick
up an explicit .param() in this PR. The v1 builder
(villagesql::func_builder, raw-ABI) is unchanged — that cow has left
the barn.
0 commit comments