-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Stop including malloc/free by default #12213
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
Changes from 35 commits
481c365
a6f7487
cc10e48
2e650da
853820a
dc7ebb0
805ab76
35f68de
f19ce33
b86705e
15cac10
59e7980
01cc0fb
c863e55
3bd2a21
3254f23
3a51c71
4bec914
abc1b91
5317fda
d1ec7dc
f32a2be
df9dc35
348de37
519c36e
cef86f2
e1dbdb1
3a4e374
27522ba
c74f7f7
36d4ee5
c46129f
ab88c3e
3028848
02b0317
2b4a67f
99ac741
150d1fb
c510fb1
8393e1b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -208,10 +208,14 @@ function lengthBytesUTF32(str) { | |
// Allocate heap space for a JS string, and write it there. | ||
// It is the responsibility of the caller to free() that memory. | ||
function allocateUTF8(str) { | ||
#if '_malloc' in IMPLEMENTED_FUNCTIONS | ||
var size = lengthBytesUTF8(str) + 1; | ||
var ret = _malloc(size); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm surprised not to see the pattern used more in the library code? Is that idea to wrap all malloc calls in I wonder if this could be rewritten as:
Thus avoiding the ifdef here?
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, good idea to use a macro here, done. This doesn't happen more because the deps_info mechanism is usually enough. But in 2 places we can't use deps (in the FS we don't want any FS usage to force malloc, and allocUTF8 isn't tracked by deps - so in both cases we don't have the fine-grained tracking we need for deps_info). |
||
if (ret) stringToUTF8Array(str, HEAP8, ret, size); | ||
return ret; | ||
#else | ||
{{{ makeMallocAbort("allocateUTF8") }}} | ||
#endif | ||
} | ||
|
||
// Allocate stack space for a JS string, and write it 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.
How did this work previously?
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.
It worked thanks to how aliases work:
a: "b"
meansa
is an alias ofb
, so it just emitsBasically it does an indirection. And that happens to work if
b
is in JS or in compiled code. It is confusing though which is why I changed it.Thinking on it now, though, even better would be to implement these in C. However it's for SDL1 and not 2 so it matters less.