summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Vincent Rischmann2022-04-18 14:11:18 +0200
committerGravatar Vincent Rischmann2022-04-18 14:11:18 +0200
commit3412f101d3147a165bbbac216a54e69c9681e94c (patch)
tree3a6b2afba0c748d3bfa92245b3b6a1750783eec3
parentreadme: specify we're talking about _SQL_ functions (diff)
parentfix alignCast in the xStep callback of createAggregateFunction (diff)
downloadzig-sqlite-3412f101d3147a165bbbac216a54e69c9681e94c.tar.gz
zig-sqlite-3412f101d3147a165bbbac216a54e69c9681e94c.tar.xz
zig-sqlite-3412f101d3147a165bbbac216a54e69c9681e94c.zip
Merge branch 'fix-function-aarch64'
-rw-r--r--sqlite.zig20
1 files changed, 8 insertions, 12 deletions
diff --git a/sqlite.zig b/sqlite.zig
index 3220c57..f434a61 100644
--- a/sqlite.zig
+++ b/sqlite.zig
@@ -724,14 +724,14 @@ pub const Db = struct {
724 /// 724 ///
725 pub fn createAggregateFunction(self: *Self, func_name: [:0]const u8, my_ctx: anytype, comptime step_func: anytype, comptime finalize_func: anytype, comptime create_flags: CreateFunctionFlag) Error!void { 725 pub fn createAggregateFunction(self: *Self, func_name: [:0]const u8, my_ctx: anytype, comptime step_func: anytype, comptime finalize_func: anytype, comptime create_flags: CreateFunctionFlag) Error!void {
726 // Check that the context type is usable 726 // Check that the context type is usable
727 const ContextType = @TypeOf(my_ctx); 727 const ContextPtrType = @TypeOf(my_ctx);
728 switch (@typeInfo(ContextType)) { 728 const ContextType = switch (@typeInfo(ContextPtrType)) {
729 .Pointer => |ptr_info| switch (ptr_info.size) { 729 .Pointer => |ptr_info| switch (ptr_info.size) {
730 .One => {}, 730 .One => ptr_info.child,
731 else => @compileError("cannot use context of type " ++ @typeName(ContextType) ++ ", must be a single-item pointer"), 731 else => @compileError("cannot use context of type " ++ @typeName(ContextPtrType) ++ ", must be a single-item pointer"),
732 }, 732 },
733 else => @compileError("cannot use context of type " ++ @typeName(ContextType) ++ ", must be a single-item pointer"), 733 else => @compileError("cannot use context of type " ++ @typeName(ContextPtrType) ++ ", must be a single-item pointer"),
734 } 734 };
735 735
736 // Validate the step function 736 // Validate the step function
737 737
@@ -781,7 +781,7 @@ pub const Db = struct {
781 var fn_args: StepFuncArgTuple = undefined; 781 var fn_args: StepFuncArgTuple = undefined;
782 782
783 // First argument is always the user-provided context 783 // First argument is always the user-provided context
784 fn_args[0] = @ptrCast(ContextType, @alignCast(@alignOf(ContextType), c.sqlite3_user_data(ctx))); 784 fn_args[0] = @ptrCast(ContextPtrType, @alignCast(@alignOf(ContextType), c.sqlite3_user_data(ctx)));
785 785
786 comptime var i: usize = 0; 786 comptime var i: usize = 0;
787 inline while (i < step_func_args_len) : (i += 1) { 787 inline while (i < step_func_args_len) : (i += 1) {
@@ -800,7 +800,7 @@ pub const Db = struct {
800 fn xFinal(ctx: ?*c.sqlite3_context) callconv(.C) void { 800 fn xFinal(ctx: ?*c.sqlite3_context) callconv(.C) void {
801 var fn_args: FinalizeFuncArgTuple = undefined; 801 var fn_args: FinalizeFuncArgTuple = undefined;
802 // Only one argument, the user-provided context 802 // Only one argument, the user-provided context
803 fn_args[0] = @ptrCast(ContextType, @alignCast(@alignOf(ContextType), c.sqlite3_user_data(ctx))); 803 fn_args[0] = @ptrCast(ContextPtrType, @alignCast(@alignOf(ContextType), c.sqlite3_user_data(ctx)));
804 804
805 const result = @call(.{}, finalize_func, fn_args); 805 const result = @call(.{}, finalize_func, fn_args);
806 806
@@ -3598,10 +3598,6 @@ test "sqlite: create scalar function" {
3598} 3598}
3599 3599
3600test "sqlite: create aggregate function" { 3600test "sqlite: create aggregate function" {
3601 // TODO(vincent): fix this, panics on incorrect pointer alignment when casting the SQLite user data to the context type
3602 // in the xStep function.
3603 if (builtin.cpu.arch.isAARCH64()) return error.SkipZigTest;
3604
3605 var db = try getTestDb(); 3601 var db = try getTestDb();
3606 defer db.deinit(); 3602 defer db.deinit();
3607 3603