From 5f76d1fa5b85c056ffda1e1d26d432bbaf0a6c79 Mon Sep 17 00:00:00 2001 From: Ivan FB Date: Fri, 5 Jun 2026 16:52:10 +0200 Subject: [PATCH] docs(macro): clarify ffiDtor recycle teardown comment MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The ffiDtor doc still claimed the generated destructor "calls destroyFFIContext", but it now uses the recycle path. Replaced that line with a concise note that the slot is recycled for reuse (bounding fd usage) and that the call is non-blocking — RET_OK once accepted, real outcome via callback. Switched the example placeholder from Waku to a generic MyLibObj, and dropped the duplicate inline comment in the body. Addresses PR #74 review comment r3363200458. Co-Authored-By: Claude Opus 4.8 --- ffi/internal/ffi_macro.nim | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/ffi/internal/ffi_macro.nim b/ffi/internal/ffi_macro.nim index b796185..69eb822 100644 --- a/ffi/internal/ffi_macro.nim +++ b/ffi/internal/ffi_macro.nim @@ -1511,14 +1511,15 @@ macro ffiDtor*(prc: untyped): untyped = ## The body contains any library-level cleanup to run before context teardown. ## ## Example: - ## proc waku_destroy*(w: Waku) {.ffiDtor.} = - ## w.cleanup() + ## proc mylibobj_destroy*(obj: MyLibObj) {.ffiDtor.} = + ## obj.cleanup() ## ## The generated C-exported proc has the signature: - ## cint waku_destroy(void* ctx, FfiCallback callback, void* userData) + ## cint mylibobj_destroy(void* ctx, FfiCallback callback, void* userData) ## - ## It extracts the library value from ctx, runs the body, then calls - ## destroyFFIContext to tear down the FFI thread and free the context. + ## Recycle the slot for reuse to keep fd usage bounded. + ## NON-BLOCKING: returns RET_OK once accepted; + ## the real outcome arrives via `callback`. let procName = prc[0] let formalParams = prc[3] @@ -1528,7 +1529,7 @@ macro ffiDtor*(prc: untyped): untyped = error("ffiDtor: proc must have exactly one parameter (w: LibType)") let libParamName = formalParams[1][0] # e.g. w - let libTypeName = formalParams[1][1] # e.g. Waku + let libTypeName = formalParams[1][1] # e.g. MyLibObj let procNameStr = block: let raw = $procName @@ -1565,10 +1566,6 @@ macro ffiDtor*(prc: untyped): untyped = ffiBody.add(bodyNode) let poolIdent = ident($libTypeName & "FFIPool") - # Hand teardown to the FFI thread (releaseFFIContext -> requestRecycle), recycling - # the slot for reuse to keep fd usage bounded. NON-BLOCKING: returns RET_OK once - # accepted; the real outcome arrives via `callback`, so callers must wait on it, - # not the return code. ffiBody.add quote do: let `destroyResIdent` = `poolIdent`.releaseFFIContext( cast[ptr FFIContext[`libTypeName`]](ctx), callback, userData