diff options
| author | 2022-04-17 22:42:03 +0200 | |
|---|---|---|
| committer | 2022-04-17 22:42:03 +0200 | |
| commit | ba3049a01ca2a3f2452f0003fdd614ec4cec0227 (patch) | |
| tree | 3a6b2afba0c748d3bfa92245b3b6a1750783eec3 | |
| parent | readme: specify we're talking about _SQL_ functions (diff) | |
| download | zig-sqlite-ba3049a01ca2a3f2452f0003fdd614ec4cec0227.tar.gz zig-sqlite-ba3049a01ca2a3f2452f0003fdd614ec4cec0227.tar.xz zig-sqlite-ba3049a01ca2a3f2452f0003fdd614ec4cec0227.zip | |
fix alignCast in the xStep callback of createAggregateFunction
| -rw-r--r-- | sqlite.zig | 20 |
1 files changed, 8 insertions, 12 deletions
| @@ -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 | ||
| 3600 | test "sqlite: create aggregate function" { | 3600 | test "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 | ||