Skip to content

Commit 84162aa

Browse files
P1: fix Zig FFI to compile under Zig 0.14.0 (#166)
## Summary The Zig FFI layer (`src/interface/ffi/src/main.zig`) did not compile under Zig 0.14.0. This fixes the two reported errors (and confirms there are no further ones), with no change to the C ABI surface. ## Errors and fixes 1. **`extern struct cannot contain a field of type 'mem.Allocator'`** (was at line ~94) - `Handle` and `DbConnection` were declared as `extern struct` while holding a `std.mem.Allocator` field. Zig 0.14 rejects this because `Allocator` is not extern-ABI-compatible. - These handles only ever cross the C boundary as opaque `?*T` pointers, so their layout is private to this module and `extern` was never needed. Both changed to a normal `struct` (the house idiom — same as the alloyiser exemplar, which uses a normal `struct` passed as an opaque pointer). - All `export fn`s already take/return them as `?*Handle` / `?*DbConnection`, so the C ABI is unchanged. 2. **`pointless discard of function parameter`** (was at lines ~470–472) - `verisimiser_vql_free_result` both used `result_ptr` (`if (result_ptr == 0) return;`) and then redundantly discarded it (`_ = result_ptr;`). Zig 0.14 errors on discarding a parameter that is also used. Removed the redundant discard, keeping the real use. No further errors surfaced after these two fixes. ## ABI preserved (source of truth) The Idris2 ABI (`src/interface/abi/Verisimiser/ABI/Foreign.idr` + `Types.idr`) is the source of truth and is unchanged: - All 24 exported C symbol names preserved 1:1 (every `C:<name>` in `Foreign.idr` has a matching `export fn <name>`). - `Result` enum integer values still match `resultToInt`: `Ok=0, Error=1, InvalidParam=2, OutOfMemory=3, NullPointer=4, ConnectionFailed=5, ChainCorrupted=6, SidecarUnavailable=7`. Only `src/interface/ffi/` was touched. ## Verification - `cd src/interface/ffi && zig test src/main.zig -lc` → all 8 tests pass, 0 errors/warnings - `zig build-obj src/main.zig -lc` → exit 0 (clean C-ABI object) - `cd src/interface/abi && idris2 --build verisimiser-abi.ipkg` → exit 0 - Symbol cross-check: every `C:<name>` in `Foreign.idr` maps to an `export fn` (empty diff) > Note: any rust-ci / Hypatia / governance red checks are pre-existing estate-infra and unrelated to this Zig-only change. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_019xMKB3T4Vo5FYC7Czx3JSH --- _Generated by [Claude Code](https://claude.ai/code/session_019xMKB3T4Vo5FYC7Czx3JSH)_ Co-authored-by: Claude <noreply@anthropic.com>
1 parent efd2291 commit 84162aa

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

src/interface/ffi/src/main.zig

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,12 @@ pub const DimensionMask = u32;
9090

9191
/// VeriSimiser library handle (opaque to C callers).
9292
/// Holds the augmentation state, sidecar connections, and configuration.
93-
pub const Handle = extern struct {
93+
///
94+
/// This is a normal Zig struct, never an `extern struct`: it holds a
95+
/// `std.mem.Allocator` (which is not extern-compatible) and is only ever
96+
/// crossed the C boundary as an opaque `?*Handle` pointer, so its layout is
97+
/// private to this module.
98+
pub const Handle = struct {
9499
allocator: std.mem.Allocator,
95100
initialized: bool,
96101
backend: DatabaseBackend,
@@ -102,7 +107,9 @@ pub const Handle = extern struct {
102107
};
103108

104109
/// Database connection handle (opaque to C callers).
105-
pub const DbConnection = extern struct {
110+
/// Normal struct for the same reason as `Handle`: it holds an allocator and
111+
/// only crosses the C boundary as an opaque pointer.
112+
pub const DbConnection = struct {
106113
allocator: std.mem.Allocator,
107114
backend: DatabaseBackend,
108115
connected: bool,
@@ -469,7 +476,6 @@ export fn verisimiser_vql_query(
469476
export fn verisimiser_vql_free_result(result_ptr: u64) void {
470477
if (result_ptr == 0) return;
471478
// TODO: free result set memory
472-
_ = result_ptr;
473479
}
474480

475481
//==============================================================================

0 commit comments

Comments
 (0)