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.
This commit is contained in:
Victor Stinner 2019-05-17 23:54:00 +02:00 committed by GitHub
parent 12083284c5
commit 871ff77c1c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 102 additions and 59 deletions

View file

@ -10,9 +10,41 @@ extern "C" {
#include "pycore_pystate.h" /* _PyRuntimeState */
/* --- _PyInitError ----------------------------------------------- */
/* Almost all errors causing Python initialization to fail */
#ifdef _MSC_VER
/* Visual Studio 2015 doesn't implement C99 __func__ in C */
# define _Py_INIT_GET_FUNC() __FUNCTION__
#else
# define _Py_INIT_GET_FUNC() __func__
#endif
#define _Py_INIT_OK() \
(_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){ \
._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._type != _Py_INIT_ERR_TYPE_OK)
/* --- _PyWstrList ------------------------------------------------ */
#define _PyWstrList_INIT (_PyWstrList){.length = 0, .items = NULL}
#ifndef NDEBUG
PyAPI_FUNC(int) _PyWstrList_CheckConsistency(const _PyWstrList *list);
#endif