Commit a4a72a2
P1: fix Zig FFI null-handle test under Zig 0.14.0 (#31)
## The bug
`zig test src/main.zig -lc` failed on `test "error handling — null
handle"` (exit code 1). The test invokes `bqniser_type(null, 0)` and
then asserts `bqniser_last_error() != null` — i.e. that calling an
accessor with a null handle records the null-pointer error condition,
consistent with the ABI's `NullPointer` result code (`NullPointer = 4`
in `src/interface/abi/Bqniser/ABI/Types.idr`).
The function was the bug, not the test. `bqniser_type`'s null-handle and
uninitialized-handle paths returned `0` silently:
```zig
const h = castHandle(handle) orelse return 0; // no setError -> last_error stays null
if (!h.initialized) return 0;
```
So `last_error` was never populated and the assertion failed. (The prior
`lifecycle` test ends in `bqniser_free`, which calls `clearError()`, so
`last_error` is null entering the null-handle test.)
## The fix
On the null/uninitialized paths of the accessor functions that
previously swallowed the error (`bqniser_type`, `bqniser_bound`,
`bqniser_to_f64`), call `setError(...)` to record the condition — the
same house idiom already used by `bqniser_eval`, `bqniser_call1`,
`bqniser_call2`, and `bqniser_read_f64_arr`, and matching the worked
exemplar in `alloyiser` where the null-handle path maps to the ABI's
null-pointer condition. This makes the null-handle path observably
report the error, consistent with the ABI's `NullPointer` semantics.
The test's expectation was correct and is unchanged; only the
implementation was corrected.
## ABI preserved
- No exported C symbol names changed; every `C:<name>` in `Foreign.idr`
still has a matching `export fn <name>`.
- The `Result` enum integer values are unchanged and still match
`resultToInt`: `ok=0, error=1, invalid_param=2, out_of_memory=3,
null_pointer=4, eval_error=5`.
- Only `src/interface/ffi/src/main.zig` was touched.
## Verification
- `cd src/interface/ffi && zig test src/main.zig -lc` → **All 4 tests
passed** (zero errors/warnings).
- `cd src/interface/abi && idris2 --build bqniser-abi.ipkg` → **exit 0**
(build dir removed afterwards).
- ABI symbol ↔ Zig export parity confirmed; Result values match
`resultToInt`.
Note: any rust-ci / Hypatia / governance red checks are pre-existing
estate-infra 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 d29c797 commit a4a72a2
1 file changed
Lines changed: 24 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
191 | 191 | | |
192 | 192 | | |
193 | 193 | | |
194 | | - | |
195 | | - | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
196 | 202 | | |
197 | 203 | | |
198 | 204 | | |
199 | 205 | | |
200 | 206 | | |
201 | 207 | | |
202 | 208 | | |
203 | | - | |
204 | | - | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
205 | 217 | | |
206 | 218 | | |
207 | 219 | | |
| |||
230 | 242 | | |
231 | 243 | | |
232 | 244 | | |
233 | | - | |
234 | | - | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
235 | 253 | | |
236 | 254 | | |
237 | 255 | | |
| |||
0 commit comments