Skip to content

Commit a9771eb

Browse files
committed
py: Add MICROPY_VM_HOOK_EXC for exception-to-bytecode handoff.
New VM hook that fires when an unhandled exception is passed to byte code for handling by a try/except block. Unlike MICROPY_NLR_RAISE_HOOK which fires on every nlr_raise (including internal StopIteration, import probes, etc.), this hook only fires when an exception actually reaches a Python exception handler. Signed-off-by: iabdalkader <[email protected]>
1 parent 082381a commit a9771eb

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

py/mpconfig.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -737,6 +737,11 @@ typedef uint64_t mp_uint_t;
737737
#define MICROPY_VM_HOOK_RETURN
738738
#endif
739739

740+
// Hook for the VM when an unhandled exception is passed to byte code
741+
#ifndef MICROPY_VM_HOOK_EXC
742+
#define MICROPY_VM_HOOK_EXC
743+
#endif
744+
740745
// Hook for mp_sched_schedule when a function gets scheduled on sched_queue
741746
// (this macro executes within an atomic section)
742747
#ifndef MICROPY_SCHED_HOOK_SCHEDULED

py/vm.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1476,6 +1476,7 @@ unwind_jump:;
14761476

14771477
if (exc_sp >= exc_stack) {
14781478
// catch exception and pass to byte code
1479+
MICROPY_VM_HOOK_EXC
14791480
code_state->ip = exc_sp->handler;
14801481
mp_obj_t *sp = MP_TAGPTR_PTR(exc_sp->val_sp);
14811482
// save this exception in the stack so it can be used in a reraise, if needed

0 commit comments

Comments
 (0)