Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/main/capi/scalar_function-c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,9 +354,14 @@ duckdb_expression duckdb_scalar_function_bind_get_argument(duckdb_bind_info info
return nullptr;
}
auto &bind_info = GetCScalarFunctionBindInfo(info);
auto wrapper = new ExpressionWrapper();
wrapper->expr = bind_info.arguments[index]->Copy();
return reinterpret_cast<duckdb_expression>(wrapper);
try {
auto wrapper = duckdb::make_uniq<ExpressionWrapper>();
wrapper->expr = bind_info.arguments[index]->Copy();
return reinterpret_cast<duckdb_expression>(wrapper.release());
} catch (std::exception &e) {
duckdb_scalar_function_bind_set_error(info, e.what());
return nullptr;
}
}

void duckdb_scalar_function_set_extra_info(duckdb_scalar_function function, void *extra_info,
Expand Down
7 changes: 7 additions & 0 deletions test/api/capi/capi_scalar_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,13 @@ TEST_CASE("Test Scalar Function with Bind Info", "[capi]") {
result = tester.Query("SELECT get_connection_id(200::UTINYINT + 200::UTINYINT)");
REQUIRE_FAIL(result);
REQUIRE(StringUtil::Contains(result->ErrorMessage(), "Overflow in addition of"));

// Correlated subquery as argument: BoundSubqueryExpression::Copy() throws SerializationException.
// Before the fix, this exception escaped the C API boundary and called std::terminate() because
// Go's CGo frames (and plain C callers) have no C++ unwind tables. The fix catches at the C
// boundary and surfaces it as a normal query error.
result = tester.Query("SELECT get_connection_id((SELECT 42::UBIGINT)) FROM (VALUES(1)) t(x)");
REQUIRE_FAIL(result);
}

TEST_CASE("Test volatile scalar function with bind in WHERE clause", "[capi]") {
Expand Down
Loading