mirror of
https://github.com/logos-messaging/nim-ffi.git
synced 2026-06-21 08:49:34 +00:00
myLib lives in non-GC `createShared` memory, so under --mm:refc a GC-managed lib object stored there is invisible to the cycle collector and gets reclaimed mid-operation under sustained request load — a use-after-free that crashes deep in the lib (e.g. a held chronos AsyncLock). Take a GC_ref once a handler installs myLib (tracked by FFIContext.myLibRefd) and GC_unref in freeLib so a later recycle/create can re-pin. Guarded to refc + ref types; orc tracks it precisely. Also wrap freeLib's `=destroy` in try/except: it is conservatively typed as raising, and recycleContext (its async caller) is `raises: []`, so the library would not compile under orc/arc without this. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
nim-ffi
Allows exposing Nim projects to other languages
Example
examples/nim_timer is now a self-contained Nimble project that imports nim-ffi directly.
Use cd examples/nim_timer && nimble install -y ../.. && nimble build to compile the example.
Description
Languages
Nim
87.9%
Smarty
5.9%
C++
4.8%
CMake
1.4%