summaryrefslogtreecommitdiff
path: root/Objects/object.c
diff options
context:
space:
mode:
authorEric Snow <ericsnowcurrently@gmail.com>2021-12-09 12:59:26 -0700
committerGitHub <noreply@github.com>2021-12-09 12:59:26 -0700
commitc8749b578324ad4089c8d014d9136bc42b065343 (patch)
tree8b74af3da8568651c2c2068d9fe544617d70554f /Objects/object.c
parentd8a464ef0380692975d73a3a1513d901b6af8e65 (diff)
downloadcpython-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/object.c')
-rw-r--r--Objects/object.c28
1 files changed, 17 insertions, 11 deletions
diff --git a/Objects/object.c b/Objects/object.c
index a1c2e16b6f..124485d64a 100644
--- a/Objects/object.c
+++ b/Objects/object.c
@@ -10,10 +10,10 @@
#include "pycore_namespace.h" // _PyNamespace_Type
#include "pycore_object.h" // _PyType_CheckConsistency()
#include "pycore_pyerrors.h" // _PyErr_Occurred()
-#include "pycore_pylifecycle.h" // _PyTypes_InitSlotDefs()
#include "pycore_pymem.h" // _PyMem_IsPtrFreed()
#include "pycore_pystate.h" // _PyThreadState_GET()
#include "pycore_symtable.h" // PySTEntry_Type
+#include "pycore_typeobject.h" // _PyTypes_InitSlotDefs()
#include "pycore_unionobject.h" // _PyUnion_Type
#include "frameobject.h" // PyFrame_Type
#include "pycore_interpreteridobject.h" // _PyInterpreterID_Type
@@ -1823,13 +1823,27 @@ PyObject _Py_NotImplementedStruct = {
};
PyStatus
-_PyTypes_Init(void)
+_PyTypes_InitState(PyInterpreterState *interp)
{
+ if (!_Py_IsMainInterpreter(interp)) {
+ return _PyStatus_OK();
+ }
+
PyStatus status = _PyTypes_InitSlotDefs();
if (_PyStatus_EXCEPTION(status)) {
return status;
}
+ return _PyStatus_OK();
+}
+
+PyStatus
+_PyTypes_InitTypes(PyInterpreterState *interp)
+{
+ if (!_Py_IsMainInterpreter(interp)) {
+ return _PyStatus_OK();
+ }
+
#define INIT_TYPE(TYPE) \
do { \
if (PyType_Ready(&(TYPE)) < 0) { \
@@ -1843,13 +1857,11 @@ _PyTypes_Init(void)
assert(PyBaseObject_Type.tp_base == NULL);
assert(PyType_Type.tp_base == &PyBaseObject_Type);
- // All other static types
+ // All other static types (unless initialized elsewhere)
INIT_TYPE(PyAsyncGen_Type);
INIT_TYPE(PyBool_Type);
INIT_TYPE(PyByteArrayIter_Type);
INIT_TYPE(PyByteArray_Type);
- INIT_TYPE(PyBytesIter_Type);
- INIT_TYPE(PyBytes_Type);
INIT_TYPE(PyCFunction_Type);
INIT_TYPE(PyCMethod_Type);
INIT_TYPE(PyCallIter_Type);
@@ -1873,7 +1885,6 @@ _PyTypes_Init(void)
INIT_TYPE(PyDict_Type);
INIT_TYPE(PyEllipsis_Type);
INIT_TYPE(PyEnum_Type);
- INIT_TYPE(PyFloat_Type);
INIT_TYPE(PyFrame_Type);
INIT_TYPE(PyFrozenSet_Type);
INIT_TYPE(PyFunction_Type);
@@ -1884,7 +1895,6 @@ _PyTypes_Init(void)
INIT_TYPE(PyListRevIter_Type);
INIT_TYPE(PyList_Type);
INIT_TYPE(PyLongRangeIter_Type);
- INIT_TYPE(PyLong_Type);
INIT_TYPE(PyMemberDescr_Type);
INIT_TYPE(PyMemoryView_Type);
INIT_TYPE(PyMethodDescr_Type);
@@ -1910,10 +1920,6 @@ _PyTypes_Init(void)
INIT_TYPE(PyStdPrinter_Type);
INIT_TYPE(PySuper_Type);
INIT_TYPE(PyTraceBack_Type);
- INIT_TYPE(PyTupleIter_Type);
- INIT_TYPE(PyTuple_Type);
- INIT_TYPE(PyUnicodeIter_Type);
- INIT_TYPE(PyUnicode_Type);
INIT_TYPE(PyWrapperDescr_Type);
INIT_TYPE(Py_GenericAliasType);
INIT_TYPE(_PyAnextAwaitable_Type);