GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — ffi: preserve uint8 semantics for bool fast calls · nodejs/node@ca60942

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • doc/contributing
    • ffi-fast-api-internals.md
  • src/ffi
    • fast.cc
    • fast.h
    • platforms
      • arm64.cc
      • loong64.cc
      • ppc64.cc
      • riscv64.cc
      • s390x.cc
      • x64.cc
  • test/ffi
    • test-ffi-calls.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎doc/contributing/ffi-fast-api-internals.md‎

Copy file name to clipboardExpand all lines: doc/contributing/ffi-fast-api-internals.md
+2-2Lines changed: 2 additions & 2 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -200,15 +200,15 @@ surface. It models the ABI categories that the generated trampoline knows how to
200200
marshal directly:
201201

202202
* `kVoid`
203-
* `kBool`
204203
* signed and unsigned 8-bit, 16-bit, 32-bit, and 64-bit integers
205204
* `kFloat32`
206205
* `kFloat64`
207206
* `kPointer`
208207
* `kBuffer`
209208

210209
Public aliases are normalized in `FastScalarTypeFromName()` and
211-
`FastArgTypeFromName()`.
210+
`FastArgTypeFromName()`. In particular, `bool` is normalized to `kUint8` to
211+
match its documented 8-bit unsigned integer semantics.
212212

213213
`pointer`, `ptr`, `string`, `str`, `buffer`, and `arraybuffer` all represent
214214
pointer-sized native values at the target ABI boundary. They differ in how
Collapse file

‎src/ffi/fast.cc‎

Copy file name to clipboardExpand all lines: src/ffi/fast.cc
+1-3Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ bool FastScalarTypeFromName(std::string_view type, FastFFIType* out) {
3737
if (type == "void") {
3838
*out = FastFFIType::kVoid;
3939
} else if (type == "bool") {
40-
*out = FastFFIType::kBool;
40+
*out = FastFFIType::kUint8;
4141
} else if (IsTypeName(type, {"i8", "int8"})) {
4242
*out = FastFFIType::kInt8;
4343
} else if (IsTypeName(type, {"u8", "uint8"})) {
@@ -96,8 +96,6 @@ CTypeInfo::Type ToV8Type(FastFFIType type, bool is_return) {
9696
switch (type) {
9797
case FastFFIType::kVoid:
9898
return CTypeInfo::Type::kVoid;
99-
case FastFFIType::kBool:
100-
return CTypeInfo::Type::kBool;
10199
case FastFFIType::kUint8:
102100
return CTypeInfo::Type::kUint32;
103101
case FastFFIType::kInt8:
Collapse file

‎src/ffi/fast.h‎

Copy file name to clipboardExpand all lines: src/ffi/fast.h
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ struct FFIFunction;
1717

1818
enum class FastFFIType : uint8_t {
1919
kVoid,
20-
kBool,
2120
kInt8,
2221
kUint8,
2322
kInt16,
Collapse file

‎src/ffi/platforms/arm64.cc‎

Copy file name to clipboardExpand all lines: src/ffi/platforms/arm64.cc
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ uint32_t UxthW(unsigned reg) {
136136
// to the ABI width expected by the native target before the final call.
137137
bool EmitNarrow(uint32_t** cursor, FastFFIType type, unsigned reg) {
138138
switch (type) {
139-
case FastFFIType::kBool:
140139
case FastFFIType::kUint8:
141140
*(*cursor)++ = UxtbW(reg);
142141
return true;
Collapse file

‎src/ffi/platforms/loong64.cc‎

Copy file name to clipboardExpand all lines: src/ffi/platforms/loong64.cc
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ bool IsFloatType(FastFFIType type) {
1919

2020
bool IsNarrowType(FastFFIType type) {
2121
switch (type) {
22-
case FastFFIType::kBool:
2322
case FastFFIType::kInt8:
2423
case FastFFIType::kUint8:
2524
case FastFFIType::kInt16:
Collapse file

‎src/ffi/platforms/ppc64.cc‎

Copy file name to clipboardExpand all lines: src/ffi/platforms/ppc64.cc
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ bool IsFloatType(FastFFIType type) {
2323

2424
bool IsNarrowType(FastFFIType type) {
2525
switch (type) {
26-
case FastFFIType::kBool:
2726
case FastFFIType::kInt8:
2827
case FastFFIType::kUint8:
2928
case FastFFIType::kInt16:
Collapse file

‎src/ffi/platforms/riscv64.cc‎

Copy file name to clipboardExpand all lines: src/ffi/platforms/riscv64.cc
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ bool IsFloatType(FastFFIType type) {
1919

2020
bool IsNarrowType(FastFFIType type) {
2121
switch (type) {
22-
case FastFFIType::kBool:
2322
case FastFFIType::kInt8:
2423
case FastFFIType::kUint8:
2524
case FastFFIType::kInt16:
Collapse file

‎src/ffi/platforms/s390x.cc‎

Copy file name to clipboardExpand all lines: src/ffi/platforms/s390x.cc
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ bool IsFloatType(FastFFIType type) {
1919

2020
bool IsNarrowType(FastFFIType type) {
2121
switch (type) {
22-
case FastFFIType::kBool:
2322
case FastFFIType::kInt8:
2423
case FastFFIType::kUint8:
2524
case FastFFIType::kInt16:
Collapse file

‎src/ffi/platforms/x64.cc‎

Copy file name to clipboardExpand all lines: src/ffi/platforms/x64.cc
-4Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,6 @@ void EmitNarrowInstruction(uint8_t** cursor, uint8_t opcode, unsigned reg) {
232232
// consumes the declared low 8/16 bits.
233233
bool EmitNarrowReturn(uint8_t** cursor, FastFFIType type, unsigned reg) {
234234
switch (type) {
235-
case FastFFIType::kBool:
236235
case FastFFIType::kUint8:
237236
EmitNarrowInstruction(cursor, 0xb6, reg);
238237
return true;
@@ -252,7 +251,6 @@ bool EmitNarrowReturn(uint8_t** cursor, FastFFIType type, unsigned reg) {
252251

253252
bool NeedsNarrow(FastFFIType type) {
254253
switch (type) {
255-
case FastFFIType::kBool:
256254
case FastFFIType::kUint8:
257255
case FastFFIType::kInt8:
258256
case FastFFIType::kUint16:
@@ -655,7 +653,6 @@ void EmitNarrowInstruction(uint8_t** cursor, uint8_t opcode, unsigned reg) {
655653

656654
bool EmitNarrowReturn(uint8_t** cursor, FastFFIType type, unsigned reg) {
657655
switch (type) {
658-
case FastFFIType::kBool:
659656
case FastFFIType::kUint8:
660657
EmitNarrowInstruction(cursor, 0xb6, reg);
661658
return true;
@@ -675,7 +672,6 @@ bool EmitNarrowReturn(uint8_t** cursor, FastFFIType type, unsigned reg) {
675672

676673
bool NeedsNarrow(FastFFIType type) {
677674
switch (type) {
678-
case FastFFIType::kBool:
679675
case FastFFIType::kUint8:
680676
case FastFFIType::kInt8:
681677
case FastFFIType::kUint16:
Collapse file

‎test/ffi/test-ffi-calls.js‎

Copy file name to clipboardExpand all lines: test/ffi/test-ffi-calls.js
+11-3Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Flags: --experimental-ffi --expose-gc
1+
// Flags: --experimental-ffi --expose-gc --allow-natives-syntax
22
'use strict';
33
const common = require('../common');
44
common.skipIfFFIMissing();
@@ -62,8 +62,16 @@ test('ffi bool signatures use uint8 values', () => {
6262
arguments: ['bool', 'bool'],
6363
return: 'bool',
6464
});
65-
assert.strictEqual(boolAdder(1, 0), 1);
66-
assert.throws(() => boolAdder(true, false), /Argument 0 must be a uint8/);
65+
function callBoolAdder(a, b) {
66+
return boolAdder(a, b);
67+
}
68+
69+
eval('%PrepareFunctionForOptimization(callBoolAdder)');
70+
assert.strictEqual(callBoolAdder(1, 0), 1);
71+
eval('%OptimizeFunctionOnNextCall(callBoolAdder)');
72+
assert.strictEqual(callBoolAdder(1, 0), 1);
73+
assert.throws(
74+
() => callBoolAdder(true, false), /Argument 0 must be a uint8/);
6775
} finally {
6876
lib.close();
6977
}

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.