Skip to content

ffi: add new methods and error codes#62762

Open
ShogunPanda wants to merge 1 commit intonodejs:mainfrom
ShogunPanda:ffi-followup
Open

ffi: add new methods and error codes#62762
ShogunPanda wants to merge 1 commit intonodejs:mainfrom
ShogunPanda:ffi-followup

Conversation

@ShogunPanda
Copy link
Copy Markdown
Contributor

As promised to @justjake, also the following followups requested in #62072 (comment):

  • Added ffi.exportArrayBuffer(...) and ffi.exportArrayBufferView(...).
  • Added raw pointer helper ffi.getRawPointer(source) (Buffer | ArrayBuffer | ArrayBufferView), with strong “unsafe/dangerous” docs and tests.
  • Moved byte-export copying to native code (exportBytes) to avoid extra JS Buffer wrapper allocations.

@ShogunPanda ShogunPanda requested review from bengl and jasnell April 15, 2026 18:28
@nodejs-github-bot
Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/config
  • @nodejs/gyp
  • @nodejs/performance

@nodejs-github-bot nodejs-github-bot added lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run. labels Apr 15, 2026
@justjake
Copy link
Copy Markdown

justjake commented Apr 15, 2026

Great! Thank you. It looks like I won't need my own unsafe-pointer once node:ffi gets stabilized 🎉 😄

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 15, 2026

Codecov Report

❌ Patch coverage is 57.20165% with 104 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.66%. Comparing base (d7ab027) to head (1fee1dd).
⚠️ Report is 7 commits behind head on main.

Files with missing lines Patch % Lines
src/ffi/data.cc 41.17% 45 Missing and 15 partials ⚠️
src/node_ffi.cc 46.80% 24 Missing and 1 partial ⚠️
src/ffi/types.cc 59.57% 19 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #62762      +/-   ##
==========================================
- Coverage   89.69%   89.66%   -0.03%     
==========================================
  Files         706      706              
  Lines      218143   218304     +161     
  Branches    41730    41772      +42     
==========================================
+ Hits       195655   195746      +91     
- Misses      14401    14475      +74     
+ Partials     8087     8083       -4     
Files with missing lines Coverage Δ
lib/ffi.js 96.56% <100.00%> (+0.71%) ⬆️
src/node_errors.h 86.48% <ø> (ø)
src/node_ffi.h 72.72% <ø> (ø)
src/ffi/types.cc 59.82% <59.57%> (+0.14%) ⬆️
src/node_ffi.cc 69.04% <46.80%> (-0.04%) ⬇️
src/ffi/data.cc 71.06% <41.17%> (-7.72%) ⬇️

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

@meixg
Copy link
Copy Markdown
Member

meixg commented Apr 16, 2026

LGTM
One small API thought: would it be better to expose this as something like getRawReference() instead of getRawPointer(), returning both the pointer and byteLength? For byte sources, the pointer is usually
meant to be used together with its length.

@ShogunPanda
Copy link
Copy Markdown
Contributor Author

@meixg I don't think it is acually necessary. When using the function you already own the source (getRawPointer(buffer)) so you can call the byteLength directly, isn't it?

@ShogunPanda ShogunPanda changed the title ffi: added new methods and error codes ffi: add new methods and error codes Apr 16, 2026
Signed-off-by: Paolo Insogna <paolo@cowtech.it>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants