mirror of
https://github.com/logos-messaging/nim-ffi.git
synced 2026-06-21 08:49:34 +00:00
docs(macro): clarify ffiDtor recycle teardown comment
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 <noreply@anthropic.com>
This commit is contained in:
parent
18946d0593
commit
5f76d1fa5b
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user