Wrote a parser verifying every FFI call
Wrote a parser that reads the real 7,308‑line C header and verifies
every call site, every enum constant and that every pointer‑owning
class is final, after a hand‑written placeholder header let calls to
three removed functions compile, link and crash.
September 2026

Situation. Early in the project the C interface was represented by a
hand‑written header describing the functions the application
expected. That header compiled, the application linked, and calls to
three functions that no longer existed in the core reached the point
of being called and crashed. The compiler and the linker had both
been satisfied by a description of the library rather than the
library, and the gap only appeared at runtime.

Task. The real header — 7,308 lines and 268 declarations — had to
become the authority, and every use of it in the Swift code had to
be verified against it automatically rather than by review.

Action. The check is a parser that reads the actual upstream header
and builds the set of functions, enum constants and types it
declares, then reads the Swift source and resolves every call site
and every constant reference against that set. A call to a function
the header does not declare fails the build. A reference to an enum
constant that has been renamed fails the build. The current count is
132 of the 268 declarations referenced, and knowing which 136 are
unused is itself useful, because it says exactly how much of the
core the client has not reached. The parser also enforces a rule the
compiler cannot: every Swift class that owns a pointer into the core
must be final. A non‑final pointer‑owning class can be subclassed,
and a subclass that overrides deinitialisation or adds its own
lifetime changes when the pointer is freed — a use‑after‑free with
no unsafe keyword anywhere near it. The rule is checked by name
across the whole tree.

Result. The class of defect that produced the original crash cannot
recur, because a stale reference is now a build failure rather than
a runtime one. The limitation is that the parser understands the
header's declarations and not its semantics: it proves a function
exists with a matching name, and a function whose meaning or
ownership rule changed upstream while keeping its signature passes
without comment.

Categories:
1Backend Engineering	/categories/backend/	engineer.company	70
1APIs & Integration	/categories/api/	engineer.company	70
1Automation & CI/CD	/categories/automation/	engineer.company	70
1Security	/categories/security/	engineer.company	70
1Testing & QA	/categories/testing/	engineer.company	70
1Documentation	/categories/documentation/	engineer.company	70

Services:
1Backend & API Development	/services/backend-development/	engineer.company	70
1DevOps & CI/CD Automation	/services/devops-cicd/	engineer.company	70
1Technical Documentation	/services/technical-documentation/	engineer.company	70

hThis page on the web	URL:https://engineer.company/portfolio/wrote-a-parser-verifying-every-ffi-call/	engineer.company	70
