Commit d7b0fa0
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
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
41 | | - | |
42 | | - | |
43 | | - | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
44 | 45 | | |
45 | 46 | | |
46 | | - | |
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
| |||
285 | 285 | | |
286 | 286 | | |
287 | 287 | | |
288 | | - | |
| 288 | + | |
289 | 289 | | |
290 | 290 | | |
291 | 291 | | |
| |||
0 commit comments