Skip to content

Commit c16fe5b

Browse files
committed
webassembly: Enable C-stack checking.
This gets the recursive stress-tests working on this port. For relatively small Python functions the maximum recursive depth is about 150 nested calls. Signed-off-by: Damien George <damien@micropython.org>
1 parent f9b6d8e commit c16fe5b

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

ports/webassembly/main.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@
4949
// the top-level call into C.
5050
static size_t external_call_depth = 0;
5151

52+
// Emscripten defaults to a 64k C-stack, so our limit should be less than that.
53+
#define CSTACK_SIZE (32 * 1024)
54+
5255
#if MICROPY_GC_SPLIT_HEAP_AUTO
5356
static void gc_collect_top_level(void);
5457
#endif
@@ -67,6 +70,8 @@ void external_call_depth_dec(void) {
6770
}
6871

6972
void mp_js_init(int pystack_size, int heap_size) {
73+
mp_cstack_init_with_sp_here(CSTACK_SIZE);
74+
7075
#if MICROPY_ENABLE_PYSTACK
7176
mp_obj_t *pystack = (mp_obj_t *)malloc(pystack_size * sizeof(mp_obj_t));
7277
mp_pystack_init(pystack, pystack + pystack_size);

ports/webassembly/mpconfigport.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
#define MICROPY_READER_VFS (MICROPY_VFS)
4545
#define MICROPY_ENABLE_GC (1)
4646
#define MICROPY_ENABLE_PYSTACK (1)
47-
#define MICROPY_STACK_CHECK (0)
4847
#define MICROPY_KBD_EXCEPTION (1)
4948
#define MICROPY_REPL_EVENT_DRIVEN (1)
5049
#define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_MPZ)

0 commit comments

Comments
 (0)