diff options
author | Victor Stinner <vstinner@redhat.com> | 2019-05-17 21:54:00 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-17 21:54:00 (GMT) |
commit | 871ff77c1cd334a141d52b0d003c080a1928731e (patch) | |
tree | 0c7c37e1d28f52fc8967bc3d85da5bb68a13fa8a /Python | |
parent | 12083284c54be25abadd85781d36b63731dc1f0c (diff) | |
download | cpython-871ff77c1cd334a141d52b0d003c080a1928731e.zip cpython-871ff77c1cd334a141d52b0d003c080a1928731e.tar.gz cpython-871ff77c1cd334a141d52b0d003c080a1928731e.tar.bz2 |
bpo-36763: Add _PyInitError functions (GH-13395)
* Add _PyInitError functions:
* _PyInitError_Ok()
* _PyInitError_Error()
* _PyInitError_NoMemory()
* _PyInitError_Exit()
* _PyInitError_IsError()
* _PyInitError_IsExit()
* _PyInitError_Failed()
* frozenmain.c and _testembed.c now use functions rather than macros.
* Move _Py_INIT_xxx() macros to the internal API.
* Move _PyWstrList_INIT macro to the internal API.
Diffstat (limited to 'Python')
-rw-r--r-- | Python/bootstrap_hash.c | 1 | ||||
-rw-r--r-- | Python/coreconfig.c | 28 | ||||
-rw-r--r-- | Python/frozenmain.c | 4 |
3 files changed, 31 insertions, 2 deletions
diff --git a/Python/bootstrap_hash.c b/Python/bootstrap_hash.c index dd752b8..fe71cc3 100644 --- a/Python/bootstrap_hash.c +++ b/Python/bootstrap_hash.c @@ -1,4 +1,5 @@ #include "Python.h" +#include "pycore_coreconfig.h" #ifdef MS_WINDOWS # include <windows.h> /* All sample MSDN wincrypt programs include the header below. It is at least diff --git a/Python/coreconfig.c b/Python/coreconfig.c index 2e8f4cf..3c17e35 100644 --- a/Python/coreconfig.c +++ b/Python/coreconfig.c @@ -203,6 +203,34 @@ fail: } +/* --- _PyInitError ----------------------------------------------- */ + +_PyInitError _PyInitError_Ok(void) +{ return _Py_INIT_OK(); } + +_PyInitError _PyInitError_Error(const char *err_msg) +{ + return (_PyInitError){._type = _Py_INIT_ERR_TYPE_ERROR, + .err_msg = err_msg}; +} + +_PyInitError _PyInitError_NoMemory(void) +{ return _PyInitError_Error("memory allocation failed"); } + +_PyInitError _PyInitError_Exit(int exitcode) +{ return _Py_INIT_EXIT(exitcode); } + + +int _PyInitError_IsError(_PyInitError err) +{ return _Py_INIT_IS_ERROR(err); } + +int _PyInitError_IsExit(_PyInitError err) +{ return _Py_INIT_IS_EXIT(err); } + +int _PyInitError_Failed(_PyInitError err) +{ return _Py_INIT_FAILED(err); } + + /* --- _PyWstrList ------------------------------------------------ */ #ifndef NDEBUG diff --git a/Python/frozenmain.c b/Python/frozenmain.c index 0175e42..7b232bb 100644 --- a/Python/frozenmain.c +++ b/Python/frozenmain.c @@ -17,7 +17,7 @@ int Py_FrozenMain(int argc, char **argv) { _PyInitError err = _PyRuntime_Initialize(); - if (_Py_INIT_FAILED(err)) { + if (_PyInitError_Failed(err)) { _Py_ExitInitError(err); } @@ -84,7 +84,7 @@ Py_FrozenMain(int argc, char **argv) err = _Py_InitializeFromConfig(&config); /* No need to call _PyCoreConfig_Clear() since we didn't allocate any memory: program_name is a constant string. */ - if (_Py_INIT_FAILED(err)) { + if (_PyInitError_Failed(err)) { _Py_ExitInitError(err); } |