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");
55const builtin = @import("builtin");
66
77const Driver = @This();
8const SQLITE_STATIC: *allowzero anyopaque = @ptrFromInt(0);
9const SQLITE_TRANSIENT: *allowzero anyopaque = @ptrFromInt(std.math.maxInt(usize));
810
911db: *c.sqlite3,
1012
......@@ -316,10 +318,10 @@ pub const Statement = struct {
316318
317319 fn bindType(stmt: Statement, allocator: std.mem.Allocator, idx: usize, T: type, value: T) !void {
318320 if (comptime extras.isZigString(T)) {
319 return bindText(stmt, idx, value, c.SQLITE_STATIC);
321 return bindText(stmt, idx, value, SQLITE_STATIC);
320322 }
321323 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));
323325 }
324326 switch (@typeInfo(T)) {
325327 .@"struct" => |info| {
......@@ -361,7 +363,7 @@ pub const Statement = struct {
361363 switch (info.params.len) {
362364 1 => {
363365 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);
365367 return bindType(stmt, allocator, idx, @TypeOf(base), base);
366368 },
367369 2 => {
......@@ -372,8 +374,14 @@ pub const Statement = struct {
372374 }
373375 }
374376
375 fn bindText(stmt: Statement, idx: usize, value: []const u8, destructor: c.sqlite3_destructor_type) !void {
376 return s.please_d(stmt.db, c.sqlite3_bind_text64(stmt.stmt, @intCast(idx), value.ptr, value.len, destructor, c.SQLITE_UTF8));
377 fn bindText(stmt: Statement, idx: usize, value: []const u8, destructor: *allowzero anyopaque) !void {
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));
377385 }
378386
379387 pub fn exec(stmt: Statement, allocator: std.mem.Allocator) !void {