Skip to content

ffi: fix FLOAT_32 and FLOAT_64 type constants#62892

Open
watilde wants to merge 1 commit intonodejs:mainfrom
watilde:ffi-fixes
Open

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

Conversation

@watilde
Copy link
Copy Markdown
Member

@watilde watilde commented Apr 22, 2026

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-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 22, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 22, 2026

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 47 commits behind head on main.

Files with missing lines Patch % Lines
src/ffi/types.cc 50.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 lines Coverage Δ
src/ffi/types.cc 60.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
Member Author

watilde commented Apr 23, 2026

rebase and make the commit Verified.

@watilde watilde requested review from bengl and cjihrig April 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
Member Author

watilde commented Apr 24, 2026

@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
Member Author

watilde commented Apr 24, 2026

Should be done now. Thank you!

@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

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