summaryrefslogtreecommitdiff
path: root/Python/pylifecycle.c
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@redhat.com>2019-05-01 05:35:33 +0200
committerGitHub <noreply@github.com>2019-05-01 05:35:33 +0200
commitdb7197543112954b0912e3d46e39fefcb1c3b950 (patch)
tree0c82232775c6b1a03671054f9e70f2bb99e6adc9 /Python/pylifecycle.c
parentc4e671eec20dfcb29b18596a89ef075f826c9f96 (diff)
downloadcpython-git-db7197543112954b0912e3d46e39fefcb1c3b950.tar.gz
bpo-36763: Rework _PyInitError API (GH-13031)
* Remove _PyInitError.user_err field and _Py_INIT_USER_ERR() macro: use _Py_INIT_ERR() instead. _Py_ExitInitError() now longer calls abort() on error: exit with exit code 1 instead. * Add _PyInitError._type private field. * exitcode field type is now unsigned int on Windows. * Rename prefix field to _func. * Rename msg field to err_msg.
Diffstat (limited to 'Python/pylifecycle.c')
-rw-r--r--Python/pylifecycle.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c
index 185d4066e5..c874a509aa 100644
--- a/Python/pylifecycle.c
+++ b/Python/pylifecycle.c
@@ -1685,7 +1685,7 @@ initsite(void)
PyObject *m;
m = PyImport_ImportModule("site");
if (m == NULL) {
- return _Py_INIT_USER_ERR("Failed to import the site module");
+ return _Py_INIT_ERR("Failed to import the site module");
}
Py_DECREF(m);
return _Py_INIT_OK();
@@ -1872,8 +1872,7 @@ init_sys_streams(PyInterpreterState *interp)
struct _Py_stat_struct sb;
if (_Py_fstat_noraise(fileno(stdin), &sb) == 0 &&
S_ISDIR(sb.st_mode)) {
- return _Py_INIT_USER_ERR("<stdin> is a directory, "
- "cannot continue");
+ return _Py_INIT_ERR("<stdin> is a directory, cannot continue");
}
#endif
@@ -2181,14 +2180,17 @@ Py_FatalError(const char *msg)
void _Py_NO_RETURN
_Py_ExitInitError(_PyInitError err)
{
- if (_Py_INIT_HAS_EXITCODE(err)) {
+ assert(_Py_INIT_FAILED(err));
+ if (_Py_INIT_IS_EXIT(err)) {
+#ifdef MS_WINDOWS
+ ExitProcess(err.exitcode);
+#else
exit(err.exitcode);
+#endif
}
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);
+ assert(_Py_INIT_IS_ERROR(err));
+ fatal_error(err._func, err.err_msg, 1);
}
}