GeezerVison is showing github.com — ffi: accept -0 for int32 and uint32 arguments · nodejs/node@c9dddad
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: src/ffi/types.cc +7-4Lines changed: 7 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -634,19 +634,22 @@ Maybe<FFIArgumentCategory> ToFFIArgument(Environment* env, | 634 | 634 |
| 635 | 635 | *static_cast<uint16_t*>(ret) = static_cast<uint16_t>(value); | 636 | 636 | } else if (type == &ffi_type_sint32) { | 637 | | - if (!arg->IsInt32()) { | | 637 | + int64_t value; | | 638 | + if (!GetValidatedSignedInt(env, arg, INT32_MIN, INT32_MAX, "int32") | | 639 | + .To(&value)) { | 638 | 640 | THROW_ERR_INVALID_ARG_VALUE(env, "Argument %u must be an int32", index); | 639 | 641 | return {}; | 640 | 642 | } | 641 | 643 |
| 642 | | - *static_cast<int32_t*>(ret) = arg->Int32Value(context).FromJust(); | | 644 | + *static_cast<int32_t*>(ret) = static_cast<int32_t>(value); | 643 | 645 | } else if (type == &ffi_type_uint32) { | 644 | | - if (!arg->IsUint32()) { | | 646 | + uint64_t value; | | 647 | + if (!GetValidatedUnsignedInt(env, arg, UINT32_MAX, "uint32").To(&value)) { | 645 | 648 | THROW_ERR_INVALID_ARG_VALUE(env, "Argument %u must be a uint32", index); | 646 | 649 | return {}; | 647 | 650 | } | 648 | 651 |
| 649 | | - *static_cast<uint32_t*>(ret) = arg->Uint32Value(context).FromJust(); | | 652 | + *static_cast<uint32_t*>(ret) = static_cast<uint32_t>(value); | 650 | 653 | } else if (type == &ffi_type_sint64) { | 651 | 654 | if (arg->IsBigInt()) { | 652 | 655 | bool lossless; | |
Collapse file Copy file name to clipboardExpand all lines: test/ffi/test-ffi-calls.js +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -20,6 +20,8 @@ test('ffi calls support integer arithmetic and char semantics', () => { | 20 | 20 | assert.strictEqual(symbols.add_u16(65_530, 10), 4); | 21 | 21 | assert.strictEqual(symbols.add_i32(-10, 52), 42); | 22 | 22 | assert.strictEqual(symbols.add_u32(0xFFFFFFFF, 1), 0); | | 23 | + assert.strictEqual(symbols.add_i32(-0, 1), 1); | | 24 | + assert.strictEqual(symbols.add_u32(-0, 1), 1); | 23 | 25 | assert.strictEqual(symbols.add_i64(20n, 22n), 42n); | 24 | 26 | assert.strictEqual(symbols.add_u64(20n, 22n), 42n); | 25 | 27 | assert.strictEqual(symbols.add_i64(20, 22), symbols.add_i64(20n, 22n)); | |
|