fix(build): construct SQLITE_TRANSIENT without tripping Zig 0.16 pointer-alignment check#2
Merged
Merged
Conversation
…ter-alignment check zig build failed on aarch64 (macOS) compiling src/sqlite.zig: translate-c expands the SQLITE_TRANSIENT macro to @ptrFromInt(-1) for the destructor function-pointer type, and Zig 0.16's comptime alignment check rejects it because function pointers are >1-aligned on aarch64 and -1 is not aligned. Construct the sentinel against an align(1) function-pointer type (which accepts any address) and bind through a matching extern sqlite3_bind_text declaration. The destructor pointer is passed by value and never dereferenced, so this is ABI-safe and identical in behavior to the C macro. Works on both aarch64 and x86_64 (where the original already compiled). Verified on macOS/aarch64: zig build, zig build test-c, and zig build test-unit all pass. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012tRqDtnoLYPka4TGZ1BwYe Signed-off-by: Richard Case <richard.case@outlook.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
zig buildfails on aarch64 (Apple Silicon) while compilingsrc/sqlite.zig:Zig 0.16's translate-c expands the
SQLITE_TRANSIENTmacro ((void(*)(void*))-1) to@ptrFromInt(-1)for the destructor's function-pointer type. On aarch64 function pointers are >1-aligned, so the comptime alignment check rejects the unaligned-1. (On x86_64 the original compiled, which is why Phase 2 built on Linux.)Fix
Construct the sentinel against an
align(1)function-pointer type — which accepts any address — and bind through a matchingexterndeclaration ofsqlite3_bind_text:The destructor pointer is passed by value and never dereferenced, so this is ABI-safe and behaviorally identical to the C macro (
SQLitereceives the same(void*)-1sentinel and copies the bound value). Single call site changed; works on both aarch64 and x86_64.Verification (macOS / aarch64)
zig build✅ (previously failed — this is the fix)zig build test-c✅c_abi_test: PASSzig build test-unit✅ (exit 0)Known separate issue (not addressed here)
zig build test-pollstill fails to compile on macOS — but for an unrelated, pre-existing reason: the mock-server intests/core/poll_test.zighardcodes Linux socket types (std.os.linux.SOL/SO,sockaddr). Phase 2 was developed and validated on Linux, wheretest-pollpasses; the test harness was never made portable to macOS. That's a test-harness portability bug, distinct from this build break, and best fixed separately (and validated on both platforms).🤖 Generated with Claude Code
https://claude.ai/code/session_012tRqDtnoLYPka4TGZ1BwYe