diff options
author | Victor Stinner <vstinner@redhat.com> | 2019-04-26 11:05:47 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-04-26 11:05:47 (GMT) |
commit | 4cb525a1f0cba152d1da61e531f2ad5db633120a (patch) | |
tree | 1f1763445e6150950986d8ba8e24181375124a7a | |
parent | 00db7c73af4f60df61e9df87cde7401c3ed9df69 (diff) | |
download | cpython-4cb525a1f0cba152d1da61e531f2ad5db633120a.zip cpython-4cb525a1f0cba152d1da61e531f2ad5db633120a.tar.gz cpython-4cb525a1f0cba152d1da61e531f2ad5db633120a.tar.bz2 |
bpo-36356: pymain_exit_error() only call pymain_free() for exit (GH-12968)
Add _Py_INIT_HAS_EXITCODE() macro.
-rw-r--r-- | Include/cpython/coreconfig.h | 4 | ||||
-rw-r--r-- | Modules/main.c | 7 | ||||
-rw-r--r-- | Python/pylifecycle.c | 2 |
3 files changed, 10 insertions, 3 deletions
diff --git a/Include/cpython/coreconfig.h b/Include/cpython/coreconfig.h index c1a7298..ed2f09f 100644 --- a/Include/cpython/coreconfig.h +++ b/Include/cpython/coreconfig.h @@ -33,8 +33,10 @@ typedef struct { #define _Py_INIT_NO_MEMORY() _Py_INIT_USER_ERR("memory allocation failed") #define _Py_INIT_EXIT(EXITCODE) \ (_PyInitError){.prefix = NULL, .msg = NULL, .user_err = 0, .exitcode = (EXITCODE)} +#define _Py_INIT_HAS_EXITCODE(err) \ + (err.exitcode != -1) #define _Py_INIT_FAILED(err) \ - (err.msg != NULL || err.exitcode != -1) + (err.msg != NULL || _Py_INIT_HAS_EXITCODE(err)) /* --- _PyWstrList ------------------------------------------------ */ diff --git a/Modules/main.c b/Modules/main.c index 6a7f735..68f0b99 100644 --- a/Modules/main.c +++ b/Modules/main.c @@ -570,7 +570,12 @@ exit_sigint(void) static void _Py_NO_RETURN pymain_exit_error(_PyInitError err) { - pymain_free(); + if (_Py_INIT_HAS_EXITCODE(err)) { + /* If it's an error rather than a regular exit, leave Python runtime + alive: _Py_ExitInitError() uses the current exception and use + sys.stdout in this case. */ + pymain_free(); + } _Py_ExitInitError(err); } diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index ae2d0bf..d93fe06 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -2172,7 +2172,7 @@ Py_FatalError(const char *msg) void _Py_NO_RETURN _Py_ExitInitError(_PyInitError err) { - if (err.exitcode >= 0) { + if (_Py_INIT_HAS_EXITCODE(err)) { exit(err.exitcode); } else { |