bun-ffi-interop-pattern
CommunitySafe bun:ffi native interop without crashes.
Authorwenerme
Version1.0.0
Installs0
System Documentation
What problem does it solve?
Bun FFI users often hit crashes or subtle memory bugs when loading native libraries, passing pointers/structs, and reading native memory without correct layout or cleanup.
Core Features & Use Cases
- Crash-safe library loading: Uses lazy loading instead of calling dlopen at module top-level to avoid startup failures.
- Struct interop guardrails: Prevents incorrect pass-by-value struct usage by recommending pointer passing or ABI-based argument splitting.
- Correct native memory handling: Enforces explicit buffer sizes, explicit endianness when reading, safe CString handling, and mandatory frees in finally blocks.
- Reliable layout guidance: Refuses to guess struct offsets and instructs generating offsets via a small C program using sizeof/offsetof.
- Type-safe parsing wrapper pattern: Encourages building typed read functions with verified offsets and structure sizes.
Quick Start
Use bun:ffi to lazily dlopen your shared library, read returned pointers with correct byte lengths and endianness, and free any native allocations in a finally block.
Dependency Matrix
Required Modules
None requiredComponents
Standard package💻 Claude Code Installation
Recommended: Let Claude install automatically. Simply copy and paste the text below to Claude Code.
Please help me install this Skill: Name: bun-ffi-interop-pattern Download link: https://github.com/wenerme/ai/archive/main.zip#bun-ffi-interop-pattern Please download this .zip file, extract it, and install it in the .claude/skills/ directory.
Agent Skills Search Helper
Install a tiny helper to your Agent, search and equip skill from 471,000+ vetted skills library on demand.