Files
Victor Stinner 3d9a42049e [3.13] gh-152132: Fix Py_RunMain() to return an exit code (#153446) (#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 fac72f1ee9)
(cherry picked from commit 62c34a62c2)
2026-07-09 22:50:58 +02:00

42 lines
832 B
C

#ifndef Py_INTERNAL_PYTHONRUN_H
#define Py_INTERNAL_PYTHONRUN_H
#ifdef __cplusplus
extern "C" {
#endif
#ifndef Py_BUILD_CORE
# error "this header requires Py_BUILD_CORE define"
#endif
extern PyObject* _PyRun_SimpleFile(
FILE *fp,
PyObject *filename,
int closeit,
PyCompilerFlags *flags);
extern PyObject* _PyRun_AnyFile(
FILE *fp,
PyObject *filename,
int closeit,
PyCompilerFlags *flags);
extern const char* _Py_SourceAsString(
PyObject *cmd,
const char *funcname,
const char *what,
PyCompilerFlags *cf,
PyObject **cmd_copy);
// Export for special main.c string compiling with source tracebacks
extern PyObject* _PyRun_SimpleString(
const char *command,
PyObject* name,
PyCompilerFlags *flags);
#ifdef __cplusplus
}
#endif
#endif // !Py_INTERNAL_PYTHONRUN_H