| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent f0140d7 commit 9c282c4
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -169,9 +169,8 @@ function convertPointerArg(type, value, stringState, index) { | |||
| 169 | 169 | if (hasPointerMemoryArg(type, value)) { | |
| 170 | 170 | return getRawPointer(value); | |
| 171 | 171 | } | |
| 172 | - if (needsRawPointerConversion(type)) { | ||
| 173 | - return getRawPointer(value); | ||
| 174 | - } | ||
| 172 | + // Pointer-like values (e.g. BigInt addresses) are passed through, matching | ||
| 173 | + // ToFFIArgument in src/ffi/types.cc and the single-argument fast path. | ||
| 175 | 174 | return value; | |
| 176 | 175 | } | |
| 177 | 176 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -133,3 +133,36 @@ test('optimized buffer signatures preserve pointer-like conversions', () => { | |||
| 133 | 133 | lib.close(); | |
| 134 | 134 | } | |
| 135 | 135 | }); | |
| 136 | + | ||
| 137 | + test('multi-argument buffer signatures accept pointer BigInts', () => { | ||
| 138 | + const { lib, functions } = ffi.dlopen(libraryPath, { | ||
| 139 | + sum_buffer: { arguments: ['buffer', 'u64'], return: 'u64' }, | ||
| 140 | + fill_buffer: { arguments: ['arraybuffer', 'u64', 'u32'], return: 'void' }, | ||
| 141 | + }); | ||
| 142 | + | ||
| 143 | + try { | ||
| 144 | + const bytes = Buffer.from([1, 2, 3, 4]); | ||
| 145 | + const pointer = ffi.getRawPointer(bytes); | ||
| 146 | + const length = BigInt(bytes.length); | ||
| 147 | + | ||
| 148 | + // The two-argument wrapper must treat a raw address like the buffer it | ||
| 149 | + // came from, matching both the single-argument fast path and the slow | ||
| 150 | + // paths in src/ffi/types.cc. | ||
| 151 | + assert.strictEqual(functions.sum_buffer(pointer, length), 10n); | ||
| 152 | + assert.strictEqual(functions.sum_buffer(bytes, length), 10n); | ||
| 153 | + assert.strictEqual(functions.sum_buffer(0n, length), 0n); | ||
| 154 | + assert.strictEqual(functions.sum_buffer(null, length), 0n); | ||
| 155 | + | ||
| 156 | + // The three-argument wrapper must forward the address to real memory | ||
| 157 | + // instead of rejecting it. | ||
| 158 | + functions.fill_buffer(pointer, length, 7); | ||
| 159 | + assert.deepStrictEqual(bytes, Buffer.from([7, 7, 7, 7])); | ||
| 160 | + | ||
| 161 | + // Still accepted once the call has been optimized. | ||
| 162 | + for (let i = 0; i < 100_000; i++) { | ||
| 163 | + assert.strictEqual(functions.sum_buffer(pointer, length), 28n); | ||
| 164 | + } | ||
| 165 | + } finally { | ||
| 166 | + lib.close(); | ||
| 167 | + } | ||
| 168 | + }); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments