Skip to content

Commit ed449c7

Browse files
committed
Fix pymain_run_python() error handling
1 parent 73a6443 commit ed449c7

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

Modules/main.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -648,13 +648,17 @@ pymain_repl(PyConfig *config, int *exitcode)
648648
static void
649649
pymain_run_python(int *exitcode)
650650
{
651+
int set_running = 0;
652+
651653
PyObject *main_importer_path = NULL;
652654
PyInterpreterState *interp = _PyInterpreterState_GET();
653655
/* pymain_repl() and pymain_run_stdin() modify the config */
654656
PyConfig *config = (PyConfig*)_PyInterpreterState_GetConfig(interp);
655657

656658
/* ensure path config is written into global variables */
657-
if (_PyStatus_EXCEPTION(_PyPathConfig_UpdateGlobal(config))) {
659+
PyStatus status = _PyPathConfig_UpdateGlobal(config);
660+
if (_PyStatus_EXCEPTION(status)) {
661+
_PyErr_SetFromPyStatus(status);
658662
goto error;
659663
}
660664

@@ -715,6 +719,7 @@ pymain_run_python(int *exitcode)
715719
pymain_header(config);
716720

717721
_PyInterpreterState_SetRunningMain(interp);
722+
set_running = 1;
718723
assert(!PyErr_Occurred());
719724

720725
if (config->run_command) {
@@ -740,7 +745,9 @@ pymain_run_python(int *exitcode)
740745
*exitcode = pymain_exit_err_print();
741746

742747
done:
743-
_PyInterpreterState_SetNotRunningMain(interp);
748+
if (set_running) {
749+
_PyInterpreterState_SetNotRunningMain(interp);
750+
}
744751
Py_XDECREF(main_importer_path);
745752
}
746753

0 commit comments

Comments
 (0)