authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-08-20 10:50:11-07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-08-20 10:50:11-07:00
log3808c55d4ca3ef25fd865c530b458fdc2dff5a4f
tree242814cdbaf782b5b7eeb3fe87df4f68232f1e07
parentcf26ab65ab6ebe5d9d3d2696acd437b856261fd9
signature Signed by SSH key SHA256:4hHJbtBRU58AYXwjL7fkz2fnQHdiye8x1QpTCQ0sHNw

sqlite3: workaround bug

without this, fails compilation on arm64 and riscv64

1 files changed, 13 insertions(+), 5 deletions(-)

src/sqlite3.zig+13-5
...@@ -5,6 +5,8 @@ const extras = @import("extras");...@@ -5,6 +5,8 @@ const extras = @import("extras");
5const builtin = @import("builtin");5const builtin = @import("builtin");
66
7const Driver = @This();7const Driver = @This();
8const SQLITE_STATIC: *allowzero anyopaque = @ptrFromInt(0);
9const SQLITE_TRANSIENT: *allowzero anyopaque = @ptrFromInt(std.math.maxInt(usize));
810
9db: *c.sqlite3,11db: *c.sqlite3,
1012
...@@ -316,10 +318,10 @@ pub const Statement = struct {...@@ -316,10 +318,10 @@ pub const Statement = struct {
316318
317 fn bindType(stmt: Statement, allocator: std.mem.Allocator, idx: usize, T: type, value: T) !void {319 fn bindType(stmt: Statement, allocator: std.mem.Allocator, idx: usize, T: type, value: T) !void {
318 if (comptime extras.isZigString(T)) {320 if (comptime extras.isZigString(T)) {
319 return bindText(stmt, idx, value, c.SQLITE_STATIC);321 return bindText(stmt, idx, value, SQLITE_STATIC);
320 }322 }
321 if (comptime extras.isArrayOf(u8)(T)) {323 if (comptime extras.isArrayOf(u8)(T)) {
322 return s.please_d(stmt.db, c.sqlite3_bind_blob64(stmt.stmt, @intCast(idx), &value, value.len, c.SQLITE_TRANSIENT));324 return s.please_d(stmt.db, c.sqlite3_bind_blob64(stmt.stmt, @intCast(idx), &value, value.len, SQLITE_TRANSIENT));
323 }325 }
324 switch (@typeInfo(T)) {326 switch (@typeInfo(T)) {
325 .@"struct" => |info| {327 .@"struct" => |info| {
...@@ -361,7 +363,7 @@ pub const Statement = struct {...@@ -361,7 +363,7 @@ pub const Statement = struct {
361 switch (info.params.len) {363 switch (info.params.len) {
362 1 => {364 1 => {
363 const base = try value.bindField();365 const base = try value.bindField();
364 if (T.BaseType == string and comptime extras.isArrayOf(u8)(@TypeOf(base))) return bindText(stmt, idx, &base, c.SQLITE_TRANSIENT);366 if (T.BaseType == string and comptime extras.isArrayOf(u8)(@TypeOf(base))) return bindText(stmt, idx, &base, SQLITE_TRANSIENT);
365 return bindType(stmt, allocator, idx, @TypeOf(base), base);367 return bindType(stmt, allocator, idx, @TypeOf(base), base);
366 },368 },
367 2 => {369 2 => {
...@@ -372,8 +374,14 @@ pub const Statement = struct {...@@ -372,8 +374,14 @@ pub const Statement = struct {
372 }374 }
373 }375 }
374376
375 fn bindText(stmt: Statement, idx: usize, value: []const u8, destructor: c.sqlite3_destructor_type) !void {377 fn bindText(stmt: Statement, idx: usize, value: []const u8, destructor: *allowzero anyopaque) !void {
376 return s.please_d(stmt.db, c.sqlite3_bind_text64(stmt.stmt, @intCast(idx), value.ptr, value.len, destructor, c.SQLITE_UTF8));378 const destructor_real: c.sqlite3_destructor_type = blk: {
379 // https://github.com/ziglang/translate-c/issues/128
380 @setRuntimeSafety(false);
381 const ptr: c.sqlite3_destructor_type = @ptrCast(@alignCast(destructor));
382 break :blk ptr;
383 };
384 return s.please_d(stmt.db, c.sqlite3_bind_text64(stmt.stmt, @intCast(idx), value.ptr, value.len, destructor_real, c.SQLITE_UTF8));
377 }385 }
378386
379 pub fn exec(stmt: Statement, allocator: std.mem.Allocator) !void {387 pub fn exec(stmt: Statement, allocator: std.mem.Allocator) !void {