-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
webassembly/api: Allocate code data on C heap when running Python code. #14318
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
webassembly/api: Allocate code data on C heap when running Python code. #14318
Conversation
@WebReflection this should fix the issue you are seeing when trying to run large code strings. |
Find a compiled version of this PR here for testing: https://micropython.org/resources/wasm/micropython.mjs (also has https://micropython.org/resources/wasm/micropython.wasm). |
return proxy_convert_mp_to_js_obj_jsside_with_free(value); | ||
}, | ||
runPythonAsync(code) { | ||
const len = Module.lengthBytesUTF8(code); |
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.
if len
always needs a + 1
(for null code \x00
I suppose) why isn't this just const len = Module.lengthBytesUTF8(code) + 1;
instead? Not a blocker, just a silly question!
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.
Module.stringToUTF8
will always add a null byte at the end, so there must be enough room for it.
But, below in the call to mp_js_do_exec_async
, we pass just len
.
I can confirm this fixes the presented use-case/issue we had 🙏 rename this file as |
Bravo |
542fd1c
to
a5ad308
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #14318 +/- ##
=======================================
Coverage 98.39% 98.39%
=======================================
Files 161 161
Lines 21204 21204
=======================================
Hits 20864 20864
Misses 340 340 ☔ View full report in Codecov by Sentry. |
Code size report:
|
e4d6a16
to
7c7e07e
Compare
In modularize mode, the `_createMicroPythonModule()` constructor must be await'ed on, before `Module` is ready to use. Signed-off-by: Damien George <damien@micropython.org>
Otherwise Emscripten allocates it on the Emscripten C stack, which will overflow for large amounts of code. Fixes issue micropython#14307. Signed-off-by: Damien George <damien@micropython.org>
7c7e07e
to
9c7f065
Compare
Also added a fix for initialising |
@dpgeorge do you mind publishing this latest version to npm so we can also bump it? Thanks! |
The latest master with this PR merged is available here: https://www.npmjs.com/package/@micropython/micropython-webassembly-pyscript/v/1.22.0-335 |
Otherwise Emscripten allocates it on the Emscripten C stack, which will overflow for large amounts of code.
Fixes issue #14307.