Skip to content
Prev Previous commit
Next Next commit
Fix pymain_run_stdin() in Modules/main.c to call pymain_start_pyrepl(…
…) instead of pymain_run_module(L"_pyrepl", 0)

This change is an equivalent to the one done in https://github.com/python/cpython/pull/120904/files#diff-79e40dbd94b164b5f42a960224cc7496e33c189b4c66a6810904eda7d703b6f2R600
Two callers of `pymain_start_pyrepl` differs in whether the PYTHONSTARTUP script is already executed or not, so pythonstartup argument is added to `pymain_start_pyrepl` to control whether it should be executed in it or not.
  • Loading branch information
whitphx committed May 19, 2025
commit 3d76ed8c3d0d158d50618b376e4afb2ff7871161
8 changes: 4 additions & 4 deletions Modules/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ pymain_run_command(wchar_t *command)


static int
pymain_start_pyrepl(void)
pymain_start_pyrepl(int pythonstartup)
{
int res = 0;
PyObject *console = NULL;
Expand Down Expand Up @@ -306,7 +306,7 @@ pymain_start_pyrepl(void)
goto done;
}
if (!PyDict_SetItemString(kwargs, "mainmodule", main_module)
&& !PyDict_SetItemString(kwargs, "pythonstartup", _PyLong_GetOne())) {
&& !PyDict_SetItemString(kwargs, "pythonstartup", pythonstartup ? Py_True : Py_False)) {
console_result = PyObject_Call(console, empty_tuple, kwargs);
if (console_result == NULL) {
res = pymain_exit_err_print();
Expand Down Expand Up @@ -570,7 +570,7 @@ pymain_run_stdin(PyConfig *config)
int run = PyRun_AnyFileExFlags(stdin, "<stdin>", 0, &cf);
return (run != 0);
}
return pymain_run_module(L"_pyrepl", 0);
return pymain_start_pyrepl(0);
}


Expand Down Expand Up @@ -603,7 +603,7 @@ pymain_repl(PyConfig *config, int *exitcode)
*exitcode = (run != 0);
return;
}
int run = pymain_start_pyrepl();
int run = pymain_start_pyrepl(1);
*exitcode = (run != 0);
return;
}
Expand Down
Loading