From 9f0d2ed11dacbade3343cbe49e8f159f1d8b67f5 Mon Sep 17 00:00:00 2001 From: Vincent Rischmann Date: Sun, 14 Apr 2024 19:09:23 +0200 Subject: c: add a workaround for SQLITE_TRANSIENT being mistranslated See https://github.com/ziglang/zig/issues/15893 zig's translate-c creates an invalid type for SQLITE_TRANSIENT on some architectures (aarch64, riscv64 and others). We can work around this by making a C function that returns -1 cast to the proper destructor type and use that from zig (thanks https://github.com/Cloudef for mentioning this in this comment: https://github.com/ziglang/zig/issues/15893#issuecomment-1925092582) --- c.zig | 1 + c/loadable_extension.zig | 1 + c/workaround.c | 5 +++++ c/workaround.h | 3 +++ 4 files changed, 10 insertions(+) create mode 100644 c/workaround.c create mode 100644 c/workaround.h diff --git a/c.zig b/c.zig index 4589aef..3a43106 100644 --- a/c.zig +++ b/c.zig @@ -5,6 +5,7 @@ pub const c = if (@hasDecl(root, "loadable_extension")) else @cImport({ @cInclude("sqlite3.h"); + @cInclude("workaround.h"); }); // versionGreaterThanOrEqualTo returns true if the SQLite version is >= to the major.minor.patch provided. diff --git a/c/loadable_extension.zig b/c/loadable_extension.zig index 4b27534..fdfe15e 100644 --- a/c/loadable_extension.zig +++ b/c/loadable_extension.zig @@ -1,5 +1,6 @@ const c = @cImport({ @cInclude("loadable-ext-sqlite3ext.h"); + @cInclude("workaround.h"); }); pub usingnamespace c; diff --git a/c/workaround.c b/c/workaround.c new file mode 100644 index 0000000..592d33d --- /dev/null +++ b/c/workaround.c @@ -0,0 +1,5 @@ +#include "workaround.h" + +my_sqlite3_destructor_type sqliteTransientAsDestructor() { + return (my_sqlite3_destructor_type)-1; +} diff --git a/c/workaround.h b/c/workaround.h new file mode 100644 index 0000000..ae243b8 --- /dev/null +++ b/c/workaround.h @@ -0,0 +1,3 @@ +typedef void (*my_sqlite3_destructor_type)(void *); + +my_sqlite3_destructor_type sqliteTransientAsDestructor(); -- cgit v1.2.3