Skip to content

ffi: support Symbol.dispose on DynamicLibrary#62925

Open
mcollina wants to merge 2 commits intonodejs:mainfrom
mcollina:ffi-symbol-dispose
Open

ffi: support Symbol.dispose on DynamicLibrary#62925
mcollina wants to merge 2 commits intonodejs:mainfrom
mcollina:ffi-symbol-dispose

Conversation

@mcollina
Copy link
Copy Markdown
Member

@mcollina mcollina commented Apr 24, 2026

Install Symbol.dispose on DynamicLibrary.prototype (calling close()) and on the object returned from ffi.dlopen(), so both can be used with the using declaration for automatic cleanup.

@mcollina mcollina requested review from ShogunPanda and cjihrig April 24, 2026 14:14
@nodejs-github-bot
Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/ffi

@nodejs-github-bot nodejs-github-bot added ffi Issues and PRs related to experimental Foreign Function Interface support. needs-ci PRs that need a full CI run. labels Apr 24, 2026
Comment thread lib/ffi.js Outdated
toArrayBuffer,
} = internalBinding('ffi');

ObjectDefineProperty(DynamicLibrary.prototype, SymbolDispose, {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just do a normal assignment here? That seems to be the norm in the rest of the codebase. (e.g. Timers, ChildProcess, Readline)

@addaleax addaleax added author ready PRs that have at least one approval, no pending requests for changes, and a CI started. request-ci Add this label to start a Jenkins CI on a PR. labels Apr 24, 2026
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Apr 24, 2026
@nodejs-github-bot
Copy link
Copy Markdown
Collaborator

@mcollina
Copy link
Copy Markdown
Member Author

Commit not validating due to nodejs/core-validate-commit#146

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 24, 2026

Codecov Report

❌ Patch coverage is 95.83829% with 35 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.65%. Comparing base (4e3a873) to head (aacdb0d).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
src/node_ffi.cc 82.67% 11 Missing and 11 partials ⚠️
src/ffi/types.cc 89.55% 1 Missing and 6 partials ⚠️
lib/internal/ffi-shared-buffer.js 99.05% 3 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #62925      +/-   ##
==========================================
- Coverage   91.47%   89.65%   -1.83%     
==========================================
  Files         357      708     +351     
  Lines      150883   220331   +69448     
  Branches    23778    42257   +18479     
==========================================
+ Hits       138026   197536   +59510     
- Misses      12582    14654    +2072     
- Partials      275     8141    +7866     
Files with missing lines Coverage Δ
lib/ffi.js 96.72% <100.00%> (+0.15%) ⬆️
src/node_builtins.cc 76.09% <ø> (ø)
src/node_ffi.h 72.72% <ø> (ø)
lib/internal/ffi-shared-buffer.js 99.05% <99.05%> (ø)
src/ffi/types.cc 48.91% <89.55%> (ø)
src/node_ffi.cc 69.76% <82.67%> (ø)

... and 466 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@nodejs-github-bot
Copy link
Copy Markdown
Collaborator

@ShogunPanda
Copy link
Copy Markdown
Contributor

@mcollina You're now missing a Signed-Off. once you add I'll approve and merge.

@mcollina mcollina force-pushed the ffi-symbol-dispose branch from 6da4424 to 3ea2ef6 Compare April 27, 2026 10:33
@nodejs-github-bot
Copy link
Copy Markdown
Collaborator

@nodejs-github-bot
Copy link
Copy Markdown
Collaborator

bengl and others added 2 commits April 28, 2026 09:10
Adds microbenchmarks covering the common FFI call shapes so future
changes to the invoker can be evaluated:

- add-i32.js: 2-arg integer
- add-f64.js: 2-arg float
- many-args.js: 6-arg integer
- pointer-bigint.js: 1-arg pointer (BigInt)
- sum-buffer.js: pointer + length (Buffer)

A `common.js` helper resolves the fixture-library path from
`test/ffi/fixture_library` without pulling in the test harness, and
throws a clear message if the fixture hasn't been built yet.

Also adds `sum_6_i32` to the fixture library for the many-args case.

Signed-off-by: Bryan English <bryan@bryanenglish.com>
PR-URL: nodejs#62918
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Install [Symbol.dispose]() on DynamicLibrary.prototype (calling close())
and on the object returned from ffi.dlopen(), so both can be used with
the `using` declaration for automatic cleanup.

Signed-off-by: Matteo Collina <hello@matteocollina.com>
@nodejs-github-bot
Copy link
Copy Markdown
Collaborator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author ready PRs that have at least one approval, no pending requests for changes, and a CI started. ffi Issues and PRs related to experimental Foreign Function Interface support. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants