diff options
| author | Eric Snow <ericsnowcurrently@gmail.com> | 2021-12-09 12:59:26 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-12-09 12:59:26 -0700 |
| commit | c8749b578324ad4089c8d014d9136bc42b065343 (patch) | |
| tree | 8b74af3da8568651c2c2068d9fe544617d70554f /Objects/exceptions.c | |
| parent | d8a464ef0380692975d73a3a1513d901b6af8e65 (diff) | |
| download | cpython-git-c8749b578324ad4089c8d014d9136bc42b065343.tar.gz | |
bpo-46008: Make runtime-global object/type lifecycle functions and state consistent. (gh-29998)
This change is strictly renames and moving code around. It helps in the following ways:
* ensures type-related init functions focus strictly on one of the three aspects (state, objects, types)
* passes in PyInterpreterState * to all those functions, simplifying work on moving types/objects/state to the interpreter
* consistent naming conventions help make what's going on more clear
* keeping API related to a type in the corresponding header file makes it more obvious where to look for it
https://bugs.python.org/issue46008
Diffstat (limited to 'Objects/exceptions.c')
| -rw-r--r-- | Objects/exceptions.c | 44 |
1 files changed, 29 insertions, 15 deletions
diff --git a/Objects/exceptions.c b/Objects/exceptions.c index e1a8c1363e..1340157525 100644 --- a/Objects/exceptions.c +++ b/Objects/exceptions.c @@ -7,6 +7,7 @@ #define PY_SSIZE_T_CLEAN #include <Python.h> #include <stdbool.h> +#include "pycore_exceptions.h" // struct _Py_exc_state #include "pycore_initconfig.h" #include "pycore_object.h" #include "structmember.h" // PyMemberDef @@ -3189,10 +3190,8 @@ SimpleExtendsException(PyExc_Warning, ResourceWarning, #endif /* MS_WINDOWS */ PyStatus -_PyExc_Init(PyInterpreterState *interp) +_PyExc_InitTypes(PyInterpreterState *interp) { - struct _Py_exc_state *state = &interp->exc_state; - #define PRE_INIT(TYPE) \ if (!(_PyExc_ ## TYPE.tp_flags & Py_TPFLAGS_READY)) { \ if (PyType_Ready(&_PyExc_ ## TYPE) < 0) { \ @@ -3201,17 +3200,6 @@ _PyExc_Init(PyInterpreterState *interp) Py_INCREF(PyExc_ ## TYPE); \ } -#define ADD_ERRNO(TYPE, CODE) \ - do { \ - PyObject *_code = PyLong_FromLong(CODE); \ - assert(_PyObject_RealIsSubclass(PyExc_ ## TYPE, PyExc_OSError)); \ - if (!_code || PyDict_SetItem(state->errnomap, _code, PyExc_ ## TYPE)) { \ - Py_XDECREF(_code); \ - return _PyStatus_ERR("errmap insertion problem."); \ - } \ - Py_DECREF(_code); \ - } while (0) - PRE_INIT(BaseException); PRE_INIT(BaseExceptionGroup); PRE_INIT(Exception); @@ -3282,10 +3270,37 @@ _PyExc_Init(PyInterpreterState *interp) PRE_INIT(ProcessLookupError); PRE_INIT(TimeoutError); + return _PyStatus_OK(); + +#undef PRE_INIT +} + +PyStatus +_PyExc_InitGlobalObjects(PyInterpreterState *interp) +{ if (preallocate_memerrors() < 0) { return _PyStatus_NO_MEMORY(); } + return _PyStatus_OK(); +} + +PyStatus +_PyExc_InitState(PyInterpreterState *interp) +{ + struct _Py_exc_state *state = &interp->exc_state; + +#define ADD_ERRNO(TYPE, CODE) \ + do { \ + PyObject *_code = PyLong_FromLong(CODE); \ + assert(_PyObject_RealIsSubclass(PyExc_ ## TYPE, PyExc_OSError)); \ + if (!_code || PyDict_SetItem(state->errnomap, _code, PyExc_ ## TYPE)) { \ + Py_XDECREF(_code); \ + return _PyStatus_ERR("errmap insertion problem."); \ + } \ + Py_DECREF(_code); \ + } while (0) + /* Add exceptions to errnomap */ assert(state->errnomap == NULL); state->errnomap = PyDict_New(); @@ -3317,7 +3332,6 @@ _PyExc_Init(PyInterpreterState *interp) return _PyStatus_OK(); -#undef PRE_INIT #undef ADD_ERRNO } |
