Skip to content

Commit 4b1839b

Browse files
P1: implement missing FFI functions + fix result-code semantics (#32)
The Zig FFI (src/interface/ffi/src/main.zig) was generic scaffolding that drifted from the Idris2 ABI, which is the source of truth (src/interface/abi/Typedqliser/ABI/Foreign.idr and .../Types.idr). Two core domain functions declared in Foreign.idr were missing from the Zig: * typedqliser_check_query : Bits64 -> String -> Bits32 -> PrimIO Bits32 (handle pointer, query C-string, requested safety level) -> result code. Validates a query against the registered schema up to the requested level and records the achieved certificate level on the handle. * typedqliser_certificate_level : Bits64 -> PrimIO Bits32 (handle pointer) -> highest safety level the last checked query achieved (0 if none), within the ten cumulative type-safety levels. Both are now exported `callconv(.C)` functions with arities/types matching the Idris %foreign declarations exactly (the handle is threaded as a Bits64 pointer value, reconstructed FFI-side). Result-code semantics corrected to match Typedqliser.ABI.Types.resultToInt: Ok=0, Error=1, InvalidQuery=2, SchemaError=3, NullPointer=4. The generic scaffold encoded codes 2 and 3 as invalid_param / out_of_memory, so cross-FFI those codes meant the WRONG thing. They are renamed to invalid_query (2) and schema_error (3) and all usages updated. The pre-existing extra exports (build_info, free_string, get_string, is_initialized, last_error, process, process_array, register_callback) are kept as a harmless superset; init/free/version are unchanged in behaviour. Verification: * zig test src/interface/ffi/src/main.zig -lc -> all 8 tests pass (added tests exercising check_query + certificate_level, the malformed-query InvalidQuery path, the SchemaError path, null-handle rejection, and a guard pinning the result codes to resultToInt). * idris2 --build src/interface/abi/typedqliser-abi.ipkg -> exit 0. Claude-Session: https://claude.ai/code/session_019xMKB3T4Vo5FYC7Czx3JSH Co-authored-by: Claude <noreply@anthropic.com>
1 parent 62bfa85 commit 4b1839b

1 file changed

Lines changed: 225 additions & 43 deletions

File tree

0 commit comments

Comments
 (0)