Ivan FB 825ae5af06
feat(ffi): RET_STALE_WARN progress callback replacing handler timeout
nim-ffi never times a handler out: a hard-cancel mid-call into the
underlying library (Waku/libp2p) can leave it half-applied. Instead, while
a request is still in flight its result callback receives a non-terminal
RET_STALE_WARN every StaleWarnInterval (5s default, Android's ANR interval;
-d:ffiStaleWarnIntervalMs to override), carrying the elapsed milliseconds as
a decimal string. The request always ends with exactly one terminal
RET_OK/RET_ERR — the dev decides what to do with a slow one, nim-ffi does
not decide for them.

This replaces the never-released per-proc {.ffi: "timeout = <ms>".} override
and the defaultRequestTimeout context field (issue #93), whose hard abort
unblocked the caller early. The stale-warn interval is an internal context
seam (staleWarnInterval), not a per-proc pragma.

Codegen: emit RET_STALE_WARN in the C/C++ headers, and guard every generated
trampoline (C, C++, Rust, and the Nim abi=c reply trampolines) to early-return
on the non-terminal code so the repeated callback can't double-free the
one-shot reply box. Typed wrappers ignore the progress signal for now; it is
delivered at the raw result-callback boundary.

Closes #126.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-11 00:59:26 +02:00
..

echo — CBOR-free abi = c C bindings

Generated by nimble genbindings_c_abi_echo (-d:targetLang=c_abi), this is the pure C ABI rendering of the echo library, meant to be read side-by-side with the CBOR rendering in ../c_bindings/ (issue #105).

../c_bindings/ (-d:targetLang=c) this dir (-d:targetLang=c_abi)
Wire format on the C side CBOR flat C structs (no serialization)
Third-party dependency vendored TinyCBOR none
Files echo.h + nim_ffi_cbor.h + nim_ffi_prelude.h one self-contained echo.h
String type NimFfiStr (owned) const char* (borrowed for the call)

Both talk to the same unmodified Nim dylib API shape (echo_ctx_create, echo_ctx_shout, …) and share the async, binding-owned callback contract. The difference is only the ABI at the boundary: here the macro-generated _CWire structs (ShoutRequest { const char* text; }, …) are passed as native C structs and the Nim side converts them to/from Nim objects. CBOR is still used, but only as an internal transport between the exported wrapper and the FFI worker thread — it never appears in this header.

The library is built with -d:ffiEchoAbiC, which flips the shared examples/echo/echo.nim source to declareLibrary(..., defaultABIFormat = "c"). A library that always wants the C ABI would set that in its own declareLibrary call and need no extra flag.

Run the end-to-end test with nimble test_c_abi_e2e.