Skip to content

Commit

Permalink
py/modthread: Initialise nlr_jump_callback_top on threads.
Browse files Browse the repository at this point in the history
The main thread gets this because the thread state is in bss, but
subsequent threads need this field to be initialised.

Also added a note to mpstate.h to help avoid missing this in the future.

Fixes issue micropython#12695.

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <[email protected]>
  • Loading branch information
jimmo authored and dpgeorge committed Oct 17, 2023
1 parent e784714 commit 3883f29
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions py/modthread.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ STATIC void *thread_entry(void *args_in) {
// The GC starts off unlocked on this thread.
ts.gc_lock_depth = 0;

ts.nlr_jump_callback_top = NULL;
ts.mp_pending_exception = MP_OBJ_NULL;

// set locals and globals from the calling context
Expand Down
6 changes: 4 additions & 2 deletions py/mpstate.h
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,10 @@ typedef struct _mp_state_vm_t {
#endif
} mp_state_vm_t;

// This structure holds state that is specific to a given thread.
// Everything in this structure is scanned for root pointers.
// This structure holds state that is specific to a given thread. Everything
// in this structure is scanned for root pointers. Anything added to this
// structure must have corresponding initialisation added to thread_entry (in
// py/modthread.c).
typedef struct _mp_state_thread_t {
// Stack top at the start of program
char *stack_top;
Expand Down

0 comments on commit 3883f29

Please sign in to comment.