From 6c4bbe01cd625d86b8e77bf8e670f0ef7c31758c Mon Sep 17 00:00:00 2001 From: Ivan FB Date: Fri, 5 Jun 2026 17:30:22 +0200 Subject: [PATCH] remove unused param in releaseFFIContext proc in ffi_context_pool.nim --- ffi/ffi_context_pool.nim | 5 +---- ffi/internal/ffi_macro.nim | 2 +- tests/test_ffi_context.nim | 12 ++++++------ 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/ffi/ffi_context_pool.nim b/ffi/ffi_context_pool.nim index 720807e..1656317 100644 --- a/ffi/ffi_context_pool.nim +++ b/ffi/ffi_context_pool.nim @@ -43,10 +43,7 @@ proc createFFIContext*[T]( return err("FFI context pool exhausted (max " & $MaxFFIContexts & " contexts)") proc releaseFFIContext*[T]( - pool: var FFIContextPool[T], - ctx: ptr FFIContext[T], - callback: FFICallBack, - userData: pointer, + ctx: ptr FFIContext[T], callback: FFICallBack, userData: pointer ): Result[void, string] = ## Parks a context for reuse without stopping its worker, so the next ## createFFIContext reuses the same threads and fds. Steady-state cleanup path diff --git a/ffi/internal/ffi_macro.nim b/ffi/internal/ffi_macro.nim index 69eb822..d770407 100644 --- a/ffi/internal/ffi_macro.nim +++ b/ffi/internal/ffi_macro.nim @@ -1567,7 +1567,7 @@ macro ffiDtor*(prc: untyped): untyped = let poolIdent = ident($libTypeName & "FFIPool") ffiBody.add quote do: - let `destroyResIdent` = `poolIdent`.releaseFFIContext( + let `destroyResIdent` = releaseFFIContext( cast[ptr FFIContext[`libTypeName`]](ctx), callback, userData ) if `destroyResIdent`.isErr(): diff --git a/tests/test_ffi_context.nim b/tests/test_ffi_context.nim index b6a2c95..b9876f3 100644 --- a/tests/test_ffi_context.nim +++ b/tests/test_ffi_context.nim @@ -795,7 +795,7 @@ proc countOpenFds(): int = except CatchableError: return -1 -proc releaseAndWait[T](pool: var FFIContextPool[T], ctx: ptr FFIContext[T]): cint = +proc releaseAndWait[T](ctx: ptr FFIContext[T]): cint = ## Test helper mirroring how a C consumer destroys a context: kick off the ## (non-blocking) teardown and block on the callback, returning its retCode. ## RET_OK means the lib's in-flight tasks finished and the slot was parked. @@ -803,7 +803,7 @@ proc releaseAndWait[T](pool: var FFIContextPool[T], ctx: ptr FFIContext[T]): cin initCallbackData(d) defer: deinitCallbackData(d) - if pool.releaseFFIContext(ctx, testCallback, addr d).isErr(): + if ctx.releaseFFIContext(testCallback, addr d).isErr(): return RET_ERR waitCallback(d) return d.retCode @@ -814,7 +814,7 @@ suite "releaseFFIContext (park & reuse)": let ctx1 = pool.createFFIContext().valueOr: check false return - check pool.releaseAndWait(ctx1) == RET_OK + check ctx1.releaseAndWait() == RET_OK # Reacquire: must be the same array slot, with its worker still running. let ctx2 = pool.createFFIContext().valueOr: @@ -843,7 +843,7 @@ suite "releaseFFIContext (park & reuse)": ctx.callbackState.callback = cast[pointer](testCallback) ctx.callbackState.userData = cast[pointer](0xDEAD) - check pool.releaseAndWait(ctx) == RET_OK + check ctx.releaseAndWait() == RET_OK check ctx.callbackState.callback.isNil() # a watchdog tick can't call a freed cb check ctx.callbackState.userData.isNil() check ctx.myLib.isNil() @@ -862,7 +862,7 @@ suite "releaseFFIContext (park & reuse)": let ctx = pool.createFFIContext().valueOr: check false return - check pool.releaseAndWait(ctx) == RET_OK + check ctx.releaseAndWait() == RET_OK let baseline = countOpenFds() @@ -877,7 +877,7 @@ suite "releaseFFIContext (park & reuse)": ).isOk() waitCallback(d) deinitCallbackData(d) - check pool.releaseAndWait(ctx) == RET_OK + check ctx.releaseAndWait() == RET_OK let afterCycles = countOpenFds() # Reuse must not grow fds. Before the fix each cycle leaked ~10 fds (4