Skip to content

ffi: support Symbol.dispose on DynamicLibrary#62925

Open
mcollina wants to merge 1 commit intonodejs:mainfrom
mcollina:ffi-symbol-dispose
Open

ffi: support Symbol.dispose on DynamicLibrary#62925
mcollina wants to merge 1 commit 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

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.64%. Comparing base (8385efc) to head (a0f4a8a).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #62925      +/-   ##
==========================================
- Coverage   91.48%   89.64%   -1.85%     
==========================================
  Files         358      708     +350     
  Lines      151574   220385   +68811     
  Branches    23917    42272   +18355     
==========================================
+ Hits       138674   197573   +58899     
- Misses      12624    14678    +2054     
- Partials      276     8134    +7858     
Files with missing lines Coverage Δ
lib/ffi.js 96.72% <100.00%> (+0.12%) ⬆️

... and 472 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

@nodejs-github-bot
Copy link
Copy Markdown
Collaborator

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>
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