summaryrefslogtreecommitdiffstats
path: root/Include/cpython/coreconfig.h
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 /Include/cpython/coreconfig.h
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 'Include/cpython/coreconfig.h')
-rw-r--r--Include/cpython/coreconfig.h11
1 files changed, 7 insertions, 4 deletions
diff --git a/Include/cpython/coreconfig.h b/Include/cpython/coreconfig.h
index f7ac3f9..2ce99b2 100644
--- a/Include/cpython/coreconfig.h
+++ b/Include/cpython/coreconfig.h
@@ -11,6 +11,7 @@ typedef struct {
const char *prefix;
const char *msg;
int user_err;
+ int exitcode;
} _PyInitError;
/* Almost all errors causing Python initialization to fail */
@@ -22,16 +23,18 @@ typedef struct {
#endif
#define _Py_INIT_OK() \
- (_PyInitError){.prefix = NULL, .msg = NULL, .user_err = 0}
+ (_PyInitError){.prefix = NULL, .msg = NULL, .user_err = 0, .exitcode = -1}
#define _Py_INIT_ERR(MSG) \
- (_PyInitError){.prefix = _Py_INIT_GET_FUNC(), .msg = (MSG), .user_err = 0}
+ (_PyInitError){.prefix = _Py_INIT_GET_FUNC(), .msg = (MSG), .user_err = 0, .exitcode = -1}
/* Error that can be fixed by the user like invalid input parameter.
Don't abort() the process on such error. */
#define _Py_INIT_USER_ERR(MSG) \
- (_PyInitError){.prefix = _Py_INIT_GET_FUNC(), .msg = (MSG), .user_err = 1}
+ (_PyInitError){.prefix = _Py_INIT_GET_FUNC(), .msg = (MSG), .user_err = 1, .exitcode = -1}
#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_FAILED(err) \
- (err.msg != NULL)
+ (err.msg != NULL || err.exitcode != -1)
/* _PyCoreConfig */