Skip to content

ffi: evaluate function signatures once#64559

Open
trivikr wants to merge 1 commit into
nodejs:mainfrom
trivikr:ffi-signature-evaluation
Open

ffi: evaluate function signatures once#64559
trivikr wants to merge 1 commit into
nodejs:mainfrom
trivikr:ffi-signature-evaluation

Conversation

@trivikr

@trivikr trivikr commented Jul 17, 2026

Copy link
Copy Markdown
Member

Fixes: #64558

Function signatures passed to DynamicLibrary.getFunction() and
DynamicLibrary.getFunctions() were evaluated twice. The native
implementation parsed the signature first, after which the JavaScript wrapper
reread signature.arguments and signature.return.

Accessors, proxies, or mutations could therefore give the native call
interface and JavaScript wrapper different signatures. For example, an
eight-argument native function could be exposed as a one-argument wrapper,
allowing native code to read arguments that the wrapper did not supply.

This change builds wrappers exclusively from the signature metadata attached
by the native implementation. It also simplifies wrapFFIFunction() so future
callers cannot supply separate signature values.


Assisted-by: openai:gpt-5.6-sol

Function signatures were read by the native implementation and then
read again while creating JavaScript wrappers. Accessors, proxies,
or mutations could therefore produce different native and JavaScript
signatures.

Build wrappers from signature metadata captured by native code instead.

Signed-off-by: Kamat, Trivikram <16024985+trivikr@users.noreply.github.com>
Assisted-by: openai:gpt-5.6-sol
@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 Jul 17, 2026
@trivikr trivikr added the request-ci Add this label to start a Jenkins CI on a PR. label Jul 17, 2026
@codecov

codecov Bot commented Jul 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.23%. Comparing base (608112a) to head (5fc8a83).
⚠️ Report is 16 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #64559      +/-   ##
==========================================
+ Coverage   90.21%   90.23%   +0.01%     
==========================================
  Files         739      739              
  Lines      241650   241740      +90     
  Branches    45542    45536       -6     
==========================================
+ Hits       218013   218138     +125     
+ Misses      15155    15119      -36     
- Partials     8482     8483       +1     
Files with missing lines Coverage Δ
lib/ffi.js 94.95% <100.00%> (+0.82%) ⬆️

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

@mcollina mcollina left a comment

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.

lgtm

@mcollina mcollina added request-ci Add this label to start a Jenkins CI on a PR. and removed request-ci Add this label to start a Jenkins CI on a PR. labels Jul 17, 2026
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jul 17, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@trivikr trivikr added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Jul 17, 2026
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.

ffi: getFunction() evaluates signature getters twice, causing native/JavaScript ABI mismatch

3 participants