Content-Length: 423938 | pFad | http://github.com/micropython/micropython/commit/88513d12268f5a5c3f3488f1a2d70cb605129537

CC webassembly/api: Allow specifying the pystack size. · micropython/micropython@88513d1 · GitHub
Skip to content

Commit 88513d1

Browse files
committed
webassembly/api: Allow specifying the pystack size.
This allows increasing the Python recursion depth if needed. Also increase the default to 2k words. There is enough RAM in the browser/node context for this to be increased, and having a larger pystack allows more complex code to run without hitting the limit. Signed-off-by: Damien George <damien@micropython.org>
1 parent 13195a6 commit 88513d1

File tree

3 files changed

+23
-16
lines changed

3 files changed

+23
-16
lines changed

Diff for: ports/webassembly/api.js

+12-5
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
*/
2626

2727
// Options:
28+
// - pystack: size in words of the MicroPython Python stack.
2829
// - heapsize: size in bytes of the MicroPython GC heap.
2930
// - url: location to load `micropython.mjs`.
3031
// - stdin: function to return input characters.
@@ -34,10 +35,11 @@
3435
// - stderr: same behaviour as stdout but for error output.
3536
// - linebuffer: whether to buffer line-by-line to stdout/stderr.
3637
export async function loadMicroPython(options) {
37-
const { heapsize, url, stdin, stdout, stderr, linebuffer } = Object.assign(
38-
{ heapsize: 1024 * 1024, linebuffer: true },
39-
options,
40-
);
38+
const { pystack, heapsize, url, stdin, stdout, stderr, linebuffer } =
39+
Object.assign(
40+
{ pystack: 2 * 1024, heapsize: 1024 * 1024, linebuffer: true },
41+
options,
42+
);
4143
let Module = {};
4244
Module.locateFile = (path, scriptDirectory) =>
4345
url || scriptDirectory + path;
@@ -96,7 +98,12 @@ export async function loadMicroPython(options) {
9698
);
9799
return proxy_convert_mp_to_js_obj_jsside_with_free(value);
98100
};
99-
Module.ccall("mp_js_init", "null", ["number"], [heapsize]);
101+
Module.ccall(
102+
"mp_js_init",
103+
"null",
104+
["number", "number"],
105+
[pystack, heapsize],
106+
);
100107
Module.ccall("proxy_c_init", "null", [], []);
101108
return {
102109
_module: Module,

Diff for: ports/webassembly/main.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,12 @@ void external_call_depth_dec(void) {
6666
--external_call_depth;
6767
}
6868

69-
void mp_js_init(int heap_size) {
69+
void mp_js_init(int pystack_size, int heap_size) {
70+
#if MICROPY_ENABLE_PYSTACK
71+
mp_obj_t *pystack = (mp_obj_t *)malloc(pystack_size * sizeof(mp_obj_t));
72+
mp_pystack_init(pystack, pystack + pystack_size);
73+
#endif
74+
7075
#if MICROPY_ENABLE_GC
7176
char *heap = (char *)malloc(heap_size * sizeof(char));
7277
gc_init(heap, heap + heap_size);
@@ -80,11 +85,6 @@ void mp_js_init(int heap_size) {
8085
MP_STATE_MEM(gc_alloc_threshold) = 16 * 1024 / MICROPY_BYTES_PER_GC_BLOCK;
8186
#endif
8287

83-
#if MICROPY_ENABLE_PYSTACK
84-
static mp_obj_t pystack[1024];
85-
mp_pystack_init(pystack, &pystack[MP_ARRAY_SIZE(pystack)]);
86-
#endif
87-
8888
mp_init();
8989

9090
#if MICROPY_VFS_POSIX

Diff for: tests/ports/webassembly/heap_expand.mjs.exp

+5-5
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
135109888
1818
134978800
1919
134716640
20-
135216848
21-
136217216
22-
138218032
23-
142219616
24-
150222864
20+
135216784
21+
136217152
22+
138217840
23+
142219296
24+
150222224
2525
1
2626
2
2727
4

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/micropython/micropython/commit/88513d12268f5a5c3f3488f1a2d70cb605129537

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy