]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
[3.15] gh-152132: Fix Py_RunMain() to return an exit code (GH-153446) (#153454)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Thu, 9 Jul 2026 19:00:28 +0000 (21:00 +0200)
committerGitHub <noreply@github.com>
Thu, 9 Jul 2026 19:00:28 +0000 (19:00 +0000)
commit76c28fc1077719ecb0ef6c4a276d36647f7a66c0
treeebb3b1973883e084e2e3790c3b91cf15c442fd33
parent0891295ac15b338fcd74ca0a647cbf975864fd98
[3.15] gh-152132: Fix Py_RunMain() to return an exit code (GH-153446) (#153454)

gh-152132: Fix Py_RunMain() to return an exit code (GH-153446)

* Fix Py_RunMain() to return an exit code, rather than calling
  Py_Exit(), when running a script, a command, or the REPL.
* _PyRun_SimpleFile() now logs errors to stderr, for example if setting
  __main__.__file__ fails.
* Add tests on Py_RunMain() exitcode.
* Rename functions:

  * _PyRun_SimpleStringFlagsWithName() => _PyRun_SimpleString()
  * _PyRun_SimpleFileObject() => _PyRun_SimpleFile()
  * _PyRun_AnyFileObject() => _PyRun_AnyFile()
  * _PyRun_InteractiveLoopObject() => _PyRun_InteractiveLoop()

* Change _PyRun_SimpleString(), _PyRun_SimpleFile(), _PyRun_AnyFile() and
  _PyRun_InteractiveLoop() return type to PyObject*.
* pymain_repl() now displays the error if PySys_Audit() or
  import _pyrepl failed.
* PyRun_SimpleFileExFlags() and PyRun_AnyFileExFlags() now log
  PyUnicode_DecodeFSDefault() error. So these functions can no longer
  return -1 with an exception set.
(cherry picked from commit fac72f1ee91fb380640a4c4be6df07a8f02d3110)

Co-authored-by: Victor Stinner <vstinner@python.org>
Include/internal/pycore_pylifecycle.h
Include/internal/pycore_pythonrun.h
Lib/test/test_embed.py
Misc/NEWS.d/next/C_API/2026-07-09-17-33-29.gh-issue-152132.Ma8MJZ.rst [new file with mode: 0644]
Modules/_testcapi/run.c
Modules/main.c
Programs/_testembed.c
Python/pythonrun.c