Skip to content

bpo-36356: pymain_exit_error() only call pymain_free() for exit #12968

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Include/cpython/coreconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 ------------------------------------------------ */

Expand Down
7 changes: 6 additions & 1 deletion Modules/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion Python/pylifecycle.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down