Skip to content

Commit 209ea09

Browse files
committed
fixup
Signed-off-by: Paolo Insogna <paolo@cowtech.it>
1 parent 8e0f40b commit 209ea09

4 files changed

Lines changed: 14 additions & 5 deletions

File tree

src/ffi/types.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -667,15 +667,15 @@ bool ToFFIReturnValue(Local<Value> result, ffi_type* type, void* ret) {
667667
return false;
668668
}
669669

670-
*static_cast<int32_t*>(ret) = static_cast<int32_t>(value);
670+
*static_cast<ffi_sarg*>(ret) = static_cast<ffi_sarg>(value);
671671
} else if (type == &ffi_type_uint32) {
672672
uint64_t value;
673673

674674
if (!GetStrictUnsignedInteger(result, UINT32_MAX, &value)) {
675675
return false;
676676
}
677677

678-
*static_cast<uint32_t*>(ret) = static_cast<uint32_t>(value);
678+
*static_cast<ffi_arg*>(ret) = static_cast<ffi_arg>(value);
679679
} else if (type == &ffi_type_sint64) {
680680
bool lossless;
681681

test/ffi/test-ffi-dynamic-library.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const common = require('../common');
44
common.skipIfFFIMissing();
55
const { gcUntil } = require('../common/gc');
66
const assert = require('node:assert');
7+
const { endianness } = require('node:os');
78
const { test } = require('node:test');
89
const ffi = require('node:ffi');
910
const { fixtureSymbols, libraryPath } = require('./ffi-test-common');
@@ -54,8 +55,11 @@ test('dlopen resolves functions from definitions', () => {
5455
// Shared-buffer wrapper sets `length` to the FFI signature's arity
5556
// (see `inheritMetadata` in lib/internal/ffi-shared-buffer.js). The raw
5657
// native function has length 0, but the wrapper exposes the parameter
57-
// count so `fn.length` is useful for introspection.
58-
assert.strictEqual(functions.add_i32.length, 2);
58+
// count so `fn.length` is useful for introspection. The shared-buffer
59+
// wrapper is disabled on big-endian hosts.
60+
assert.strictEqual(
61+
functions.add_i32.length,
62+
endianness() === 'BE' ? 0 : 2);
5963
assert.strictEqual(typeof functions.add_i32.pointer, 'bigint');
6064
assert.strictEqual(Object.getPrototypeOf(functions), null);
6165
} finally {

test/ffi/test-ffi-memory.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ test('ffi exportString and exportBuffer copy data into native memory', () => {
177177
const viewSource = new Uint16Array([0x0102, 0x0304, 0x0506]);
178178
const middleBytes = new Uint8Array(viewSource.buffer, 2, 2);
179179
ffi.exportArrayBufferView(middleBytes, viewPtr, 2);
180-
assert.deepStrictEqual([...ffi.toBuffer(viewPtr, 2)], [0x04, 0x03]);
180+
assert.deepStrictEqual([...ffi.toBuffer(viewPtr, 2)], [...middleBytes]);
181181

182182
const bufferViewPtr = alloc(8);
183183
const bufferView = Buffer.from([1, 7, 2, 8, 3]);

test/ffi/test-ffi-shared-buffer.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,13 @@ const common = require('../common');
44
common.skipIfFFIMissing();
55

66
const assert = require('node:assert');
7+
const { endianness } = require('node:os');
78
const { test } = require('node:test');
89

10+
if (endianness() === 'BE') {
11+
common.skip('shared-buffer FFI is disabled on big-endian hosts');
12+
}
13+
914
// Capture the unpatched DynamicLibrary.prototype.getFunction BEFORE loading
1015
// `node:ffi`, which patches it. The SB-metadata test below uses the raw
1116
// method to inspect Symbol-keyed internals that `inheritMetadata`

0 commit comments

Comments
 (0)