Skip to content

Commit 8809d51

Browse files
committed
Address review and fix convertPtrToIdx on non-byte shifts
1 parent 8353f65 commit 8809d51

3 files changed

Lines changed: 5 additions & 18 deletions

File tree

src/embind/embind.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -718,9 +718,7 @@ var LibraryEmbind = {
718718
// assumes 4-byte alignment
719719
var base = _malloc({{{ POINTER_SIZE }}} + length + 1);
720720
var ptr = base + {{{ POINTER_SIZE }}};
721-
#if CAN_ADDRESS_2GB
722-
ptr >>>= 0;
723-
#endif
721+
{{{ convertPtrToIdx('ptr') }}};
724722
{{{ makeSetValue('base', '0', 'length', SIZE_TYPE) }}};
725723
if (stdStringIsUTF8 && valueIsOfTypeString) {
726724
stringToUTF8(value, ptr, length + 1);

src/parseTools.js

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -876,13 +876,6 @@ function isIntLiteral(x) {
876876
return /^\d+$/.test(x);
877877
}
878878

879-
// Returns the given Number (either literal or a variable) casted to a BigInt.
880-
function toBigInt(number) {
881-
// Code size optimization: if 'number' is a literal, use the short literal syntax '42n'.
882-
// Otherwise must use a longer cast to BigInt().
883-
return isIntLiteral(number) ? `${number}n` : `BigInt(${number})`;
884-
}
885-
886879
// Generates an expression that tests whether a pointer (either a BigInt or a signed int32 JS Number) is aligned to the given byte multiple.
887880
function isPtrAligned(ptr, alignment) {
888881
return `(${parensGuard(ptr)} % ${idxToPtr(alignment)} == 0)`;
@@ -928,8 +921,8 @@ function ptrToIdx(ptr, accessShift = 0) {
928921
// {{{ convertPtrToIdx(ptr, as) }}} is equal to 'ptr = {{{ ptrToIdx(ptr, as) }}}, i.e. it assigns
929922
// in-place. This can be used to avoid generating redundant "ptr = ptr;" assignments in JS code.
930923
function convertPtrToIdx(ptr, accessShift = 0) {
931-
if (MEMORY64 || MAXIMUM_MEMORY > MAX_MEMORY_2GB) return `${ptr} = ${ptrToIdx(ptr, accessShift)}`;
932-
return ''; // No conversion needed in 2GB mode.
924+
if (MEMORY64 || MAXIMUM_MEMORY > MAX_MEMORY_2GB || accessShift != 0) return `${ptr} = ${ptrToIdx(ptr, accessShift)}`;
925+
return ''; // No conversion of byte addresses needed in 2GB mode.
933926
}
934927

935928
// Given an index (unsigned Number) to one of the HEAP* arrays, converts it to an appropriate Wasm pointer

src/runtime_safe_heap.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@ var SAFE_HEAP_COUNTER = 0;
2525

2626
/** @param {number|boolean=} isFloat */
2727
function SAFE_HEAP_STORE(dest, value, bytes, isFloat) {
28-
#if CAN_ADDRESS_2GB
29-
dest >>>= 0;
30-
#endif
28+
{{{ convertPtrToIdx('dest') }}};
3129
#if SAFE_HEAP_LOG
3230
out('SAFE_HEAP store: ' + [dest, value, bytes, isFloat, SAFE_HEAP_COUNTER++]);
3331
#endif
@@ -56,9 +54,7 @@ function SAFE_HEAP_STORE_D(dest, value, bytes) {
5654

5755
/** @param {number|boolean=} isFloat */
5856
function SAFE_HEAP_LOAD(dest, bytes, unsigned, isFloat) {
59-
#if CAN_ADDRESS_2GB
60-
dest >>>= 0;
61-
#endif
57+
{{{ convertPtrToIdx('dest') }}};
6258
if (dest <= 0) abort(`segmentation fault loading ${bytes} bytes from address ${dest}`);
6359
#if SAFE_HEAP == 1
6460
if (dest % bytes !== 0) abort(`alignment error loading from address ${dest}, which was expected to be aligned to a multiple of ${bytes}`);

0 commit comments

Comments
 (0)