Skip to content

Commit d7b0fa0

Browse files
P1: fix Zig FFI to compile and match the Idris2 ABI (#39)
## Summary `src/interface/ffi/src/main.zig` did not compile under Zig 0.14.0. This PR fixes it with two minimal, FFI-only changes. The Idris2 ABI (`src/interface/abi/Anvomidaviser/ABI/Foreign.idr` + `Types.idr`) is the source of truth and is unchanged. ## Fixes 1. **Syntax error (`expected statement, found ';'`, ~line 288):** the `if (!h.initialized) { ... }` block at the end of `anvomidaviser_get_string` was terminated with a stray `;`. An `if` used as a statement takes no trailing semicolon, so the `};` after the block body was parsed as an empty statement. Removed the spurious semicolon. 2. **`Handle` was a Zig `opaque {}` with fields:** it was declared `pub const Handle = opaque { allocator, initialized }` but then instantiated (`handle.* = .{...}`) and field-accessed (`h.allocator`, `h.initialized`). Zig `opaque` types are unsized and cannot hold or expose fields, so this could never compile once the parser passed the syntax error. Changed `Handle` to a concrete `struct`, matching the house idiom in alloyiser's exemplar (its `Model` struct). It is still only ever handed to C as a pointer, so it remains opaque across the C ABI. ## ABI alignment (preserved) - Every `C:anvomidaviser_*` symbol in `Foreign.idr` has a matching `export fn` (19/19). - Result enum integer values match `Types.idr`'s `resultToInt` exactly: `ok=0, error=1, invalid_param=2, out_of_memory=3, null_pointer=4, rule_violation=5`. - No exported symbol names or result codes were changed. ## Verification - `cd src/interface/ffi && zig test src/main.zig -lc` → all 3 tests pass, 0 errors/warnings. - `cd src/interface/abi && idris2 --build anvomidaviser-abi.ipkg` → exit 0 (build dir removed afterward). Note: any rust-ci / Hypatia / governance red checks are pre-existing estate-infrastructure issues 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 6cc712e commit d7b0fa0

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

src/interface/ffi/src/main.zig

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ pub const Result = enum(c_int) {
3838
rule_violation = 5,
3939
};
4040

41-
/// Library handle (opaque to prevent direct access)
42-
pub const Handle = opaque {
43-
// Internal state hidden from C
41+
/// Library handle. Opaque to C (passed as a pointer); fields are private to
42+
/// this module. A concrete struct (not Zig `opaque`) so internal state can be
43+
/// stored and accessed here.
44+
pub const Handle = struct {
4445
allocator: std.mem.Allocator,
4546
initialized: bool,
46-
// Add your fields here
4747
};
4848

4949
//==============================================================================
@@ -285,7 +285,7 @@ export fn anvomidaviser_get_string(handle: ?*Handle) ?[*:0]const u8 {
285285
if (!h.initialized) {
286286
setError("Handle not initialized");
287287
return null;
288-
};
288+
}
289289

290290
const result = h.allocator.dupeZ(u8, "Anvomidaviser score pending") catch {
291291
setError("Failed to allocate string");

0 commit comments

Comments
 (0)