Skip to content

[3.14] gh-152132: Fix Py_RunMain() to return an exit code (#153446)#153455

Merged
vstinner merged 1 commit into
python:3.14from
vstinner:pyrun_exc14
Jul 9, 2026
Merged

[3.14] gh-152132: Fix Py_RunMain() to return an exit code (#153446)#153455
vstinner merged 1 commit into
python:3.14from
vstinner:pyrun_exc14

Conversation

@vstinner

@vstinner vstinner commented Jul 9, 2026

Copy link
Copy Markdown
Member
  • 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 fac72f1)

* 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 fac72f1)
@vstinner vstinner added the needs backport to 3.13 bugs and security fixes label Jul 9, 2026
@vstinner vstinner merged commit 62c34a6 into python:3.14 Jul 9, 2026
51 checks passed
@miss-islington-app

Copy link
Copy Markdown

Thanks @vstinner for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13.
🐍🍒⛏🤖

@vstinner vstinner deleted the pyrun_exc14 branch July 9, 2026 19:37
@miss-islington-app

Copy link
Copy Markdown

Sorry, @vstinner, I could not cleanly backport this to 3.13 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker 62c34a62c21eccac8ac88ae130319d3e6d488e28 3.13

@bedevere-app

bedevere-app Bot commented Jul 9, 2026

Copy link
Copy Markdown

GH-153458 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.13 bugs and security fixes label Jul 9, 2026
vstinner added a commit that referenced this pull request Jul 9, 2026
…153455) (#153458)

[3.14] gh-152132: Fix Py_RunMain() to return an exit code (#153446) (#153455)

gh-152132: Fix Py_RunMain() to return an exit code (#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 fac72f1)
(cherry picked from commit 62c34a6)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant