summaryrefslogtreecommitdiffstats
path: root/Include
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@redhat.com>2019-05-01 03:35:33 (GMT)
committerGitHub <noreply@github.com>2019-05-01 03:35:33 (GMT)
commitdb7197543112954b0912e3d46e39fefcb1c3b950 (patch)
tree0c82232775c6b1a03671054f9e70f2bb99e6adc9 /Include
parentc4e671eec20dfcb29b18596a89ef075f826c9f96 (diff)
downloadcpython-db7197543112954b0912e3d46e39fefcb1c3b950.zip
cpython-db7197543112954b0912e3d46e39fefcb1c3b950.tar.gz
cpython-db7197543112954b0912e3d46e39fefcb1c3b950.tar.bz2
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 'Include')
-rw-r--r--Include/cpython/coreconfig.h43
1 files changed, 28 insertions, 15 deletions
diff --git a/Include/cpython/coreconfig.h b/Include/cpython/coreconfig.h
index ed2f09f..5743bf5 100644
--- a/Include/cpython/coreconfig.h
+++ b/Include/cpython/coreconfig.h
@@ -8,10 +8,18 @@ extern "C" {
/* --- _PyInitError ----------------------------------------------- */
typedef struct {
- const char *prefix;
- const char *msg;
- int user_err;
+ enum {
+ _Py_INIT_ERR_TYPE_OK=0,
+ _Py_INIT_ERR_TYPE_ERROR=1,
+ _Py_INIT_ERR_TYPE_EXIT=2
+ } _type;
+ const char *_func;
+ const char *err_msg;
+#ifdef MS_WINDOWS
+ unsigned int exitcode;
+#else
int exitcode;
+#endif
} _PyInitError;
/* Almost all errors causing Python initialization to fail */
@@ -23,20 +31,25 @@ typedef struct {
#endif
#define _Py_INIT_OK() \
- (_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, .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, .exitcode = -1}
-#define _Py_INIT_NO_MEMORY() _Py_INIT_USER_ERR("memory allocation failed")
+ (_PyInitError){._type = _Py_INIT_ERR_TYPE_OK,}
+ /* other fields are set to 0 */
+#define _Py_INIT_ERR(ERR_MSG) \
+ (_PyInitError){ \
+ ._type = _Py_INIT_ERR_TYPE_ERROR, \
+ ._func = _Py_INIT_GET_FUNC(), \
+ .err_msg = (ERR_MSG)}
+ /* other fields are set to 0 */
+#define _Py_INIT_NO_MEMORY() _Py_INIT_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)
+ (_PyInitError){ \
+ ._type = _Py_INIT_ERR_TYPE_EXIT, \
+ .exitcode = (EXITCODE)}
+#define _Py_INIT_IS_ERROR(err) \
+ (err._type == _Py_INIT_ERR_TYPE_ERROR)
+#define _Py_INIT_IS_EXIT(err) \
+ (err._type == _Py_INIT_ERR_TYPE_EXIT)
#define _Py_INIT_FAILED(err) \
- (err.msg != NULL || _Py_INIT_HAS_EXITCODE(err))
+ (err._type != _Py_INIT_ERR_TYPE_OK)
/* --- _PyWstrList ------------------------------------------------ */