Skip to content

ffi: fix FLOAT_32 and FLOAT_64 type constants - #62892

Closed
watilde wants to merge 1 commit into
nodejs:mainfrom
watilde:ffi-fixes
Closed

ffi: fix FLOAT_32 and FLOAT_64 type constants#62892
watilde wants to merge 1 commit into
nodejs:mainfrom
watilde:ffi-fixes

Conversation

@watilde

Copy link
Copy Markdown
Member

Test code

$ cat test.js
const ffi = require('node:ffi');
const { functions } = ffi.dlopen('libm.so.6', {
sinf: { parameters: [ffi.types.FLOAT_32], result: ffi.types.FLOAT_32 },
});
console.log(functions.sinf(1.0));

Before

$ ./node --experimental-ffi test.js
node:ffi:75
throw error;
^
TypeError: Unsupported FFI type: float32
at Object.dlopen (node:ffi:71:91)
at Object.<anonymous> (/home/moku/Developments/watilde/node/test.js:3:27)
at Module._compile (node:internal/modules/cjs/loader:1829:14)
at Object..js (node:internal/modules/cjs/loader:1969:10)
at Module.load (node:internal/modules/cjs/loader:1552:32)
at Module._load (node:internal/modules/cjs/loader:1354:12)
at wrapModuleLoad (node:internal/modules/cjs/loader:255:19)
at Module.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:154:5)
at node:internal/main/run_main_module:33:47 {
code: 'ERR_INVALID_ARG_VALUE'
}
Node.js v26.0.0-pre

After

$ ./node --experimental-ffi test.js
0.8414709568023682
(node:721215) ExperimentalWarning: FFI is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)

@nodejs-github-botnodejs-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 22, 2026
@codecov

codecovBot commented Apr 22, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 50.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.64%. Comparing base (d44a71a) to head (4363008).
⚠️ Report is 52 commits behind head on main.

Files with missing linesPatch %Lines
src/ffi/types.cc50.00%0 Missing and 2 partials ⚠️
Additional details and impacted files
@@ Coverage Diff @@## main #62892 +/- ##
==========================================
+ Coverage 89.61% 89.64% +0.02% 
==========================================
Files 706 706 Lines 219203 219221 +18 Branches 41995 42016 +21 ==========================================
+ Hits 196445 196517 +72 + Misses 14663 14619 -44 + Partials 8095 8085 -10 
Files with missing linesCoverage Δ
src/ffi/types.cc60.35% <50.00%> (+0.20%)⬆️

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

@watilde

Copy link
Copy Markdown
MemberAuthor

rebase and make the commit Verified.

@watilde
watilde requested review from bengl and cjihrigApril 23, 2026 11:23
@ShogunPanda

Copy link
Copy Markdown
Contributor

Hi!
Thanks for spotting this, but the fix is actually incorrect.
The simple fix is in https://github.com/nodejs/node/blob/main/src/ffi/types.cc#L249 and following lines, where it should be:

} else if (type_str == "f32" || type_str == "float" || type_str == "float32") {
*ret = &ffi_type_float;
} else if (type_str == "f64" || type_str == "double" || type_str == "float64") {
*ret = &ffi_type_double; 

Can you please update this?

@watilde

Copy link
Copy Markdown
MemberAuthor

@ShogunPanda Good point, I've udpated. Thank you!

@ShogunPanda

Copy link
Copy Markdown
Contributor

Looks fine to me. Fix linting and we're should be good to go.

@watilde

Copy link
Copy Markdown
MemberAuthor

Should be done now. Thank you!

@addaleaxaddaleax 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-actionsgithub-actionsBot 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

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

watilde added a commit that referenced this pull request Apr 25, 2026
PR-URL: #62892
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Bryan English <bryan@bryanenglish.com>
@watilde

Copy link
Copy Markdown
MemberAuthor

Landed in 10ae641

@watildewatilde closed this Apr 25, 2026
aduh95 pushed a commit that referenced this pull request May 5, 2026
PR-URL: #62892
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Bryan English <bryan@bryanenglish.com>
@aduh95aduh95 mentioned this pull request May 5, 2026
nodejs-github-bot pushed a commit that referenced this pull request Aug 2, 2026
`ToFFIType()` accepts `float32` and `float64` as aliases for `float`
and `double`, and both names already appear in the `ffi.types`
constants list further down the same page, but they were missing from
the list of supported type names.
Also split `char` onto its own line. Unlike `u8`, `uint8` and `bool`,
which always map to `ffi_type_uint8`, `char` maps to either
`ffi_type_sint8` or `ffi_type_uint8` depending on the platform C ABI,
as the paragraph below the list already explains.
Signed-off-by: Soul Lee <alus20x@gmail.com>
PR-URL: #64874
Refs: #62892
Refs: #64848
Reviewed-By: René <contact.9a5d6388@renegade334.me.uk>
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Ulises Gascón <ulisesgascongonzalez@gmail.com>
aduh95 pushed a commit that referenced this pull request Aug 3, 2026
`ToFFIType()` accepts `float32` and `float64` as aliases for `float`
and `double`, and both names already appear in the `ffi.types`
constants list further down the same page, but they were missing from
the list of supported type names.
Also split `char` onto its own line. Unlike `u8`, `uint8` and `bool`,
which always map to `ffi_type_uint8`, `char` maps to either
`ffi_type_sint8` or `ffi_type_uint8` depending on the platform C ABI,
as the paragraph below the list already explains.
Signed-off-by: Soul Lee <alus20x@gmail.com>
PR-URL: #64874
Refs: #62892
Refs: #64848
Reviewed-By: René <contact.9a5d6388@renegade334.me.uk>
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Ulises Gascón <ulisesgascongonzalez@gmail.com>
aduh95 pushed a commit that referenced this pull request Aug 4, 2026
`ToFFIType()` accepts `float32` and `float64` as aliases for `float`
and `double`, and both names already appear in the `ffi.types`
constants list further down the same page, but they were missing from
the list of supported type names.
Also split `char` onto its own line. Unlike `u8`, `uint8` and `bool`,
which always map to `ffi_type_uint8`, `char` maps to either
`ffi_type_sint8` or `ffi_type_uint8` depending on the platform C ABI,
as the paragraph below the list already explains.
Signed-off-by: Soul Lee <alus20x@gmail.com>
PR-URL: #64874
Refs: #62892
Refs: #64848
Reviewed-By: René <contact.9a5d6388@renegade334.me.uk>
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Ulises Gascón <ulisesgascongonzalez@gmail.com>
aduh95 pushed a commit that referenced this pull request Aug 4, 2026
`ToFFIType()` accepts `float32` and `float64` as aliases for `float`
and `double`, and both names already appear in the `ffi.types`
constants list further down the same page, but they were missing from
the list of supported type names.
Also split `char` onto its own line. Unlike `u8`, `uint8` and `bool`,
which always map to `ffi_type_uint8`, `char` maps to either
`ffi_type_sint8` or `ffi_type_uint8` depending on the platform C ABI,
as the paragraph below the list already explains.
Signed-off-by: Soul Lee <alus20x@gmail.com>
PR-URL: #64874
Refs: #62892
Refs: #64848
Reviewed-By: René <contact.9a5d6388@renegade334.me.uk>
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Ulises Gascón <ulisesgascongonzalez@gmail.com>
aduh95 pushed a commit that referenced this pull request Aug 5, 2026
`ToFFIType()` accepts `float32` and `float64` as aliases for `float`
and `double`, and both names already appear in the `ffi.types`
constants list further down the same page, but they were missing from
the list of supported type names.
Also split `char` onto its own line. Unlike `u8`, `uint8` and `bool`,
which always map to `ffi_type_uint8`, `char` maps to either
`ffi_type_sint8` or `ffi_type_uint8` depending on the platform C ABI,
as the paragraph below the list already explains.
Signed-off-by: Soul Lee <alus20x@gmail.com>
PR-URL: #64874
Refs: #62892
Refs: #64848
Reviewed-By: René <contact.9a5d6388@renegade334.me.uk>
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Ulises Gascón <ulisesgascongonzalez@gmail.com>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

@watilde@ShogunPanda@nodejs-github-bot@bengl@addaleax