-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Avoid checks before _free
calls. NFC
#24416
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
info.bufferSize = data.length; | ||
info.buffer = _malloc(data.length); | ||
} | ||
info.buffer = _realloc(info.buffer, data.length); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does realloc do the equivalent check that the buffer size is < the desired length? (i.e. does it avoid the actual reallocation in the case where the existing buffer is big enough?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, thats exactly what it does
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think in practice it also never shrinks, but I think that is fine for all these cases.
a2398ba
to
1fe4c5c
Compare
src/lib/libstack_trace.js
Outdated
@@ -269,7 +269,7 @@ var LibraryStackTrace = { | |||
} else { | |||
name = wasmOffsetConverter.getName(pc); | |||
} | |||
if (_emscripten_pc_get_function.ret) _free(_emscripten_pc_get_function.ret); | |||
_free(_emscripten_pc_get_function.ret | 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because in wasm64 we cannot pass undefined
in place 0/NULL :(
It generates TypeError: Cannot convert undefined to a BigInt
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, right... I keep forgetting about BigInts there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But it allows 0? Will it convert anything that Number.isSafeInteger()
returns true for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have wrappers that convert pointer argument to bigint automatically by doing BigInt(arg)
for each of the pointer arguments. This does indeed work for all numbers, including zero, but it does not work for undefined or null.
node
Welcome to Node.js v20.19.2.
Type ".help" for more information.
> BigInt(0)
0n
> BigInt(undefined)
Uncaught TypeError: Cannot convert undefined to a BigInt
at BigInt (<anonymous>)
>
We don't really want to increase the size of all wrappers by handling this case (I think).
Free is defined to do nothing if NULL is passed so its harmless to just call it. Also, make more use of `_realloc`. Both these changes save on code size.
Free is defined to do nothing if NULL is passed so its harmless to just call it.
Also, make more use of
_realloc
.Both these changes save on code size.