summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@redhat.com>2019-03-01 11:14:41 (GMT)
committerGitHub <noreply@github.com>2019-03-01 11:14:41 (GMT)
commitdfe884759d1f4441c889695f8985bc9feb9f37eb (patch)
tree64e8bc65ee86db1bfca6a4a5cda8a7b598614989 /Python
parentb9f0354efce95b7557bc43ea193c4b652cd28392 (diff)
downloadcpython-dfe884759d1f4441c889695f8985bc9feb9f37eb.zip
cpython-dfe884759d1f4441c889695f8985bc9feb9f37eb.tar.gz
cpython-dfe884759d1f4441c889695f8985bc9feb9f37eb.tar.bz2
bpo-36142: Rework error reporting in pymain_main() (GH-12113)
Add a new _Py_INIT_EXIT() macro to be able to exit Python with an exitcode using _PyInitError API. Rewrite function calls by pymain_main() to use _PyInitError. Changes: * Remove _PyMain.err and _PyMain.status field * Add _Py_INIT_EXIT() macro and _PyInitError.exitcode field. * Rename _Py_FatalInitError() to _Py_ExitInitError().
Diffstat (limited to 'Python')
-rw-r--r--Python/frozenmain.c2
-rw-r--r--Python/pathconfig.c2
-rw-r--r--Python/pylifecycle.c19
3 files changed, 14 insertions, 9 deletions
diff --git a/Python/frozenmain.c b/Python/frozenmain.c
index 6160909..6554aa7 100644
--- a/Python/frozenmain.c
+++ b/Python/frozenmain.c
@@ -86,7 +86,7 @@ Py_FrozenMain(int argc, char **argv)
/* No need to call _PyCoreConfig_Clear() since we didn't allocate any
memory: program_name is a constant string. */
if (_Py_INIT_FAILED(err)) {
- _Py_FatalInitError(err);
+ _Py_ExitInitError(err);
}
#ifdef MS_WINDOWS
diff --git a/Python/pathconfig.c b/Python/pathconfig.c
index eadc09b..f96f015 100644
--- a/Python/pathconfig.c
+++ b/Python/pathconfig.c
@@ -408,7 +408,7 @@ pathconfig_global_init(void)
error:
_PyCoreConfig_Clear(&config);
- _Py_FatalInitError(err);
+ _Py_ExitInitError(err);
}
diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c
index 1d65d3b..088e7aa 100644
--- a/Python/pylifecycle.c
+++ b/Python/pylifecycle.c
@@ -960,7 +960,7 @@ Py_InitializeEx(int install_sigs)
_PyCoreConfig_Clear(&config);
if (_Py_INIT_FAILED(err)) {
- _Py_FatalInitError(err);
+ _Py_ExitInitError(err);
}
}
@@ -1432,7 +1432,7 @@ Py_NewInterpreter(void)
PyThreadState *tstate;
_PyInitError err = new_interpreter(&tstate);
if (_Py_INIT_FAILED(err)) {
- _Py_FatalInitError(err);
+ _Py_ExitInitError(err);
}
return tstate;
@@ -2073,12 +2073,17 @@ Py_FatalError(const char *msg)
}
void _Py_NO_RETURN
-_Py_FatalInitError(_PyInitError err)
+_Py_ExitInitError(_PyInitError err)
{
- /* On "user" error: exit with status 1.
- For all other errors, call abort(). */
- int status = err.user_err ? 1 : -1;
- fatal_error(err.prefix, err.msg, status);
+ if (err.exitcode >= 0) {
+ exit(err.exitcode);
+ }
+ else {
+ /* On "user" error: exit with status 1.
+ For all other errors, call abort(). */
+ int status = err.user_err ? 1 : -1;
+ fatal_error(err.prefix, err.msg, status);
+ }
}
/* Clean up and exit */