45 Commits

Author SHA1 Message Date
Ivan FB
b40b245cc7
docs: tighten the RET_STALE_WARN comments
They restated what the code says and repeated the never-time-out
rationale at each site; keep the non-obvious why (no cancel because a
partially-applied library call is worse, race not cancelling the loser,
responded left unset on purpose) and drop the rest.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-14 16:11:00 +02:00
Ivan FB
0d1abb4ced
fix(tests): ignore non-terminal RET_STALE_WARN in testCallback
The shared result callback treated every code as an answer, so the 5s
stale ping fired by the slow arm+ASan runner during the 50k-ref-alloc
handler woke waitCallback with retCode=3 and let the test tear the
context down while the handler was still running -- which in turn made
destroyFFIContext err and left the event thread firing on a torn-down
signal (the UBSan fireSync null deref). Honour the same contract the
generated C/C++/Rust trampolines now follow: a progress ping is not a
reply. Tests asserting on the pings use staleCallback instead.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-14 14:31:42 +02:00
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
Gabriel Cruz
c0f6f2e802
feat: main prefix validation (#116) 2026-07-10 16:49:07 -03:00
Gabriel Cruz
ea67fb747a
feat(ffi): make the scalar-fast-path binding drop loud (#120) 2026-07-09 16:43:21 -03:00
Gabriel Cruz
3e57751e3a
feat(ffi): async teardown hook for {.ffiDtor.} (#115) 2026-07-09 13:53:21 -03:00
Gabriel Cruz
5eaa799b7d
feat: CBOR-free abi=c C bindings (-d:targetLang=c_abi) (#109) 2026-07-06 13:48:08 -03:00
Gabriel Cruz
c91287ba22
feat: CBOR-free scalar fast path for abi=c procs (#110) 2026-07-06 12:48:07 -03:00
Gabriel Cruz
8dcdcdc76a
feat(ffi): configurable per-request handler timeout with a finite default (#93) (#108) 2026-07-06 11:58:04 -03:00
Gabriel Cruz
fb0a1f1077
feat(ffi): CBOR-free scalar fast path for all-scalar abi = c procs (#106) 2026-07-06 11:57:46 -03:00
Gabriel Cruz
8c1343aaf2
refactor(codegen): shared FFIType IR + single type parser for C/C++/Rust (#104) 2026-07-06 11:43:34 -03:00
Gabriel Cruz
08509cc74f
feat: slab-allocate event payloads (#107) 2026-07-06 10:52:09 -03:00
Gabriel Cruz
7e3fd96e74
feat(codegen): C binding generator (-d:targetLang=c) (#102) 2026-07-01 12:00:47 -03:00
Ivan FB
5d49ee6b08
feat(ffi): sharded MPSC request ingress (alternative to lock-free #98) (#101)
Co-authored-by: Gabriel Cruz <8129788+gmelodie@users.noreply.github.com>
2026-06-27 19:08:10 +02:00
Gabriel Cruz
4bac7a7bc6
test(bench): submit-throughput scaling gate for sendRequestToFFIThread (issue #90) (#97) 2026-06-25 18:02:45 -03:00
Gabriel Cruz
64a332ca8b
feat(ffi): scalar type mappings + seq[byte] byte-string codec (#99) 2026-06-25 17:16:21 -03:00
Gabriel Cruz
7362bfd212
test(bench): cbor vs c (cwire) codec microbenchmark (#86) 2026-06-23 13:47:56 -03:00
Gabriel Cruz
f6881274ca
feat(ffi): cwire codec composite fields (#88) 2026-06-23 12:55:07 -03:00
Gabriel Cruz
6c4657ad7e
feat(ffi): cwire codec core (flat scalars + strings) (#87) 2026-06-23 11:49:19 -03:00
Gabriel Cruz
a5ccadd62d
feat(ffi): per-interaction ABI-format annotations + c codec (ffiRaw) (#85) 2026-06-23 11:18:03 -03:00
Gabriel Cruz
021f469041
feat: {.ffiHandle.} — export complex live objects as opaque handles (#81) 2026-06-16 14:11:31 -03:00
Gabriel Cruz
16dc1b3573
chore(ci): add nph linting (#77) 2026-06-10 16:30:30 -03:00
Gabriel Cruz
9b3cde7674
feat: move user event code to a dedicated event thread (#69) 2026-06-09 11:35:04 -03:00
Gabriel Cruz
54c41a3e62
refactor(ffi): event thread scaffolding + FFIContext lifecycle split (#71) 2026-06-08 11:46:16 -03:00
Ivan FB
f96a5b158a
Remove wildcard event listener; keep per-event dispatch (#70) 2026-06-02 22:22:35 +02:00
Gabriel Cruz
7ccf34591d
chore: avoid throwing exceptions in C++ bindings (#46) 2026-05-29 12:35:49 -03:00
Ivan FB
e394166c46
Cpp typed event listeners (#51) 2026-05-28 22:40:33 +02:00
Ivan FB
496a341466
Event registry wiring (#49) 2026-05-27 22:26:39 +02:00
Ivan FB
e99220a3e4
fix use-after-free concern (#47)
Co-authored-by: Gabriel Cruz <8129788+gmelodie@users.noreply.github.com>
2026-05-26 23:46:27 +02:00
Gabriel Cruz
e43c1e03e8
tests: cover gaps in CBOR type coverage (#41) 2026-05-26 17:10:42 -03:00
Ivan FB
216316826c
add FFIEventRegistry: multi-listener data structure for FFI events (#45) 2026-05-26 21:42:01 +02:00
Gabriel Cruz
436c0d760b
test(cpp-e2e): add multi-context, cross-library, pipeline, stress tests (#30) (#42) 2026-05-26 09:18:12 -03:00
Ivan FB
6a7e4616fd
Adjust events to cbor (#39) 2026-05-25 15:51:56 +02:00
Gabriel Cruz
31d0ebfa51
chore(ci): extend cpp-e2e to OS matrix (#38) 2026-05-22 11:43:37 -03:00
Ivan FB
c7cf46bdea
avoid move ctor and assing operator in cpp generated code (#36) 2026-05-21 16:38:13 +02:00
Gabriel Cruz
ee472f05ad
chore(ci): fsanitize tests (#34) 2026-05-20 14:14:42 -03:00
Ivan FB
584e818ac9
Add basic cpp e2e tests (#27) 2026-05-19 12:43:34 +02:00
Ivan FB
e12745e85c
Add cddl generator (#24) 2026-05-18 20:00:57 +02:00
Ivan FB
ac303a707e
Start using CBOR (#23)
Co-authored-by: NagyZoltanPeter <113987313+NagyZoltanPeter@users.noreply.github.com>
Co-authored-by: Gabriel Cruz <8129788+gmelodie@users.noreply.github.com>
2026-05-16 01:08:42 +02:00
Ivan FB
e48c9f9edf
remove ffiType macro because it is duplicated by ffi macro (#22) 2026-05-13 14:48:54 +02:00
Ivan FB
6d31fa30bd
use fixed array of ctx to avoid consuming all fds (#14) 2026-05-13 00:02:23 +02:00
Gabriel Cruz
81c62c263e
fix: context buffer overflow (#21) 2026-05-11 19:21:40 -03:00
Ivan FB
a52c4facd9
Simplified FFI authoring with auto-generated C++ and Rust bindings (#15) 2026-05-11 23:28:17 +02:00
Gabriel Cruz
e99eb60fd1
chore: run tests with refc (#20)
* chore: run tests with refc

* chore: split ci jobs

* chore: fix tests
2026-05-09 10:47:37 -03:00
Ivan FB
df2277e726
Fix memleaks (#11)
* protect against mem leak in case of failures sending requests to ffi thread
* better cleanup if failures in createFFIContext
* avoid dangling cstring in handleRes under ARC/ORC
* better resource cleanup in destroyFFIContext
* invoke onNotResponding if failure in destroyFFIContext
* correct seq copy in alloc
* make sure the lock is init before cleanUpResources
* better possible exception handling in processReq
* guard allocSharedSeq if given seq is empty
* enhance error handling in ffi_context
* add new tests and some corrections
2026-04-27 21:22:45 +02:00