- Every pointer has one owner, documented with
SAFETYcomments or host-language ownership docs. - Use opaque handles across native boundaries. Do not expose Rust, C++, or host-runtime internals directly.
- Check all nullable pointers before use and return explicit errors for invalid handles or null inputs.
- Provide allocate/free pairs for every caller-owned allocation and document which side frees each value.
- Every unsafe block must state the invariant, why it holds, and what would make it invalid.
- Generate C headers or native declarations from source when possible, and make CI verify generated files are current.
- Treat the C ABI or equivalent native ABI as the stable contract for downstream bindings.
- Freeze native struct layouts across compatible releases, and version breaking ABI changes deliberately.
- Convert native errors to host exceptions, result objects, or idiomatic error values at every boundary.
- Preserve diagnostic context across boundaries: message, numeric code when available, source operation, and cause chain.
Ffi And Language Interop
FFI and native interop rules: single documented pointer ownership, opaque handles, null-pointer checks, allocate/free pairs, unsafe-block invariants, generated C headers, stable C ABI, frozen struct layouts, and error/context conversion. Load when writing or reviewing FFI boundaries between native and host languages.
Ffi And Language Interop by goldziher · 4971886
npx skillmds@latest add goldziher/ffi-and-language-interop File contents
---name: ffi-and-language-interopdescription: FFI and native interop rules: single documented pointer ownership, opaque handles, null-pointer checks, allocate/free pairs, unsafe-block invariants, generated C headers, stable C ABI, frozen struct layouts, and error/context conversion. Load when writing or reviewing FFI boundaries between native and host languages.---- Every pointer has one owner, documented with `SAFETY` comments or host-language ownership docs.- Use opaque handles across native boundaries. Do not expose Rust, C++, or host-runtime internals directly.- Check all nullable pointers before use and return explicit errors for invalid handles or null inputs.- Provide allocate/free pairs for every caller-owned allocation and document which side frees each value.- Every unsafe block must state the invariant, why it holds, and what would make it invalid.- Generate C headers or native declarations from source when possible, and make CI verify generated files are current.- Treat the C ABI or equivalent native ABI as the stable contract for downstream bindings.- Freeze native struct layouts across compatible releases, and version breaking ABI changes deliberately.- Convert native errors to host exceptions, result objects, or idiomatic error values at every boundary.- Preserve diagnostic context across boundaries: message, numeric code when available, source operation, and cause chain.
goldziher/ai-rulez/tree/main/internal/builtins/universal/polyglot-bindings/skills/ffi-and-language-interop commit 4971886aa1
Frequently asked questions
Run npx skillmds@latest add goldziher/ffi-and-language-interop in your terminal (requires Node.js), paste this page's agent-chat prompt into Claude, Cursor, or any MCP-connected agent, or download the SKILL.md file and copy it into your agent's skills directory.
FFI and native interop rules: single documented pointer ownership, opaque handles, null-pointer checks, allocate/free pairs, unsafe-block invariants, generated C headers, stable C ABI, frozen struct layouts, and error/context conversion. Load when writing or reviewing FFI boundaries between native and host languages. It is listed under Coding & Dev Tools on SkillMD.
This skill has not completed SkillMD's automated safety review yet. SkillMD never runs a skill's scripts for you; review the SKILL.md before installing.
This skill is tagged as working with Claude Code, Claude.ai, OpenAI Codex. SKILL.md is an open format, so most agents that read a skills directory can load it too.
Yes. Installing skills from SkillMD is free, and the skill stays under its author's original license.
goldziher (@goldziher) published this skill. Their other Agent Skills are listed on their SkillMD profile.