Skip to content

Commit 5a984bc

Browse files
committed
shared/runtime/pyexec: Set PYEXEC_FORCED_EXIT flag for SystemExit.
When MICROPY_PYEXEC_ENABLE_EXIT_CODE_HANDLING is enabled, SystemExit now sets the PYEXEC_FORCED_EXIT flag in addition to the exit code. This allows the REPL to properly detect and exit when SystemExit is raised, while still preserving the exit code in the lower bits. Enable MICROPY_PYEXEC_ENABLE_EXIT_CODE_HANDLING in Windows port. Fixes repl_lock.py test which expects REPL to exit on SystemExit. Signed-off-by: Andrew Leech <[email protected]>
1 parent 6e734dc commit 5a984bc

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

ports/windows/mpconfigport.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,9 @@
164164
// Enable support for compile-only mode.
165165
#define MICROPY_PYEXEC_COMPILE_ONLY (1)
166166

167+
// Enable handling of sys.exit() exit codes.
168+
#define MICROPY_PYEXEC_ENABLE_EXIT_CODE_HANDLING (1)
169+
167170
#define MICROPY_ERROR_REPORTING (MICROPY_ERROR_REPORTING_DETAILED)
168171
#define MICROPY_ERROR_PRINTER (&mp_stderr_print)
169172
#define MICROPY_WARNINGS (1)

shared/runtime/pyexec.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,8 @@ static int parse_compile_execute(const void *source, mp_parse_input_kind_t input
178178
} else {
179179
ret = PYEXEC_NORMAL_EXIT;
180180
}
181+
// Set PYEXEC_FORCED_EXIT flag so REPL knows to exit
182+
ret |= PYEXEC_FORCED_EXIT;
181183
#else
182184
ret = PYEXEC_FORCED_EXIT;
183185
#endif

0 commit comments

Comments
 (0)