[Python-checkins] bpo-46417: Clear more static types (GH-30796)
vstinner
webhook-mailer at python.org
Sat Jan 22 12:55:56 EST 2022
https://github.com/python/cpython/commit/500c146387b01ea797b52e6a54caf228384e184c
commit: 500c146387b01ea797b52e6a54caf228384e184c
branch: main
author: Victor Stinner <vstinner at python.org>
committer: vstinner <vstinner at python.org>
date: 2022-01-22T18:55:48+01:00
summary:
bpo-46417: Clear more static types (GH-30796)
* Move PyContext static types into object.c static_types list.
* Rename PyContextTokenMissing_Type to _PyContextTokenMissing_Type
and declare it in pycore_context.h.
* _PyHamtItems types are no long exported: replace PyAPI_DATA() with
extern.
files:
M Include/internal/pycore_context.h
M Include/internal/pycore_hamt.h
M Objects/object.c
M Python/bltinmodule.c
M Python/context.c
M Python/hamt.c
M Python/pylifecycle.c
diff --git a/Include/internal/pycore_context.h b/Include/internal/pycore_context.h
index 31ca0a43fae29..1bf4e8f3ee532 100644
--- a/Include/internal/pycore_context.h
+++ b/Include/internal/pycore_context.h
@@ -8,9 +8,11 @@
#include "pycore_hamt.h" /* PyHamtObject */
+extern PyTypeObject _PyContextTokenMissing_Type;
+
/* runtime lifecycle */
-PyStatus _PyContext_InitTypes(PyInterpreterState *);
+PyStatus _PyContext_Init(PyInterpreterState *);
void _PyContext_Fini(PyInterpreterState *);
diff --git a/Include/internal/pycore_hamt.h b/Include/internal/pycore_hamt.h
index cf9c19e022d8a..85e35c5afc90c 100644
--- a/Include/internal/pycore_hamt.h
+++ b/Include/internal/pycore_hamt.h
@@ -8,9 +8,16 @@
#define _Py_HAMT_MAX_TREE_DEPTH 7
+extern PyTypeObject _PyHamt_Type;
+extern PyTypeObject _PyHamt_ArrayNode_Type;
+extern PyTypeObject _PyHamt_BitmapNode_Type;
+extern PyTypeObject _PyHamt_CollisionNode_Type;
+extern PyTypeObject _PyHamtKeys_Type;
+extern PyTypeObject _PyHamtValues_Type;
+extern PyTypeObject _PyHamtItems_Type;
+
/* runtime lifecycle */
-PyStatus _PyHamt_InitTypes(PyInterpreterState *);
void _PyHamt_Fini(PyInterpreterState *);
@@ -69,15 +76,6 @@ typedef struct {
} PyHamtIterator;
-PyAPI_DATA(PyTypeObject) _PyHamt_Type;
-PyAPI_DATA(PyTypeObject) _PyHamt_ArrayNode_Type;
-PyAPI_DATA(PyTypeObject) _PyHamt_BitmapNode_Type;
-PyAPI_DATA(PyTypeObject) _PyHamt_CollisionNode_Type;
-PyAPI_DATA(PyTypeObject) _PyHamtKeys_Type;
-PyAPI_DATA(PyTypeObject) _PyHamtValues_Type;
-PyAPI_DATA(PyTypeObject) _PyHamtItems_Type;
-
-
/* Create a new HAMT immutable mapping. */
PyHamtObject * _PyHamt_New(void);
diff --git a/Objects/object.c b/Objects/object.c
index a5ee8eef4a3b4..a1663c0dbb7b7 100644
--- a/Objects/object.c
+++ b/Objects/object.c
@@ -4,6 +4,7 @@
#include "Python.h"
#include "pycore_call.h" // _PyObject_CallNoArgs()
#include "pycore_ceval.h" // _Py_EnterRecursiveCall()
+#include "pycore_context.h" // _PyContextTokenMissing_Type
#include "pycore_dict.h" // _PyObject_MakeDictFromInstanceAttributes()
#include "pycore_floatobject.h" // _PyFloat_DebugMallocStats()
#include "pycore_initconfig.h" // _PyStatus_EXCEPTION()
@@ -1853,6 +1854,9 @@ static PyTypeObject* static_types[] = {
&PyClassMethod_Type,
&PyCode_Type,
&PyComplex_Type,
+ &PyContextToken_Type,
+ &PyContextVar_Type,
+ &PyContext_Type,
&PyCoro_Type,
&PyDictItems_Type,
&PyDictIterItem_Type,
@@ -1867,6 +1871,7 @@ static PyTypeObject* static_types[] = {
&PyDict_Type,
&PyEllipsis_Type,
&PyEnum_Type,
+ &PyFilter_Type,
&PyFloat_Type,
&PyFrame_Type,
&PyFrozenSet_Type,
@@ -1879,6 +1884,7 @@ static PyTypeObject* static_types[] = {
&PyList_Type,
&PyLongRangeIter_Type,
&PyLong_Type,
+ &PyMap_Type,
&PyMemberDescr_Type,
&PyMemoryView_Type,
&PyMethodDescr_Type,
@@ -1905,12 +1911,21 @@ static PyTypeObject* static_types[] = {
&PyUnicodeIter_Type,
&PyUnicode_Type,
&PyWrapperDescr_Type,
+ &PyZip_Type,
&Py_GenericAliasType,
&_PyAnextAwaitable_Type,
&_PyAsyncGenASend_Type,
&_PyAsyncGenAThrow_Type,
&_PyAsyncGenWrappedValue_Type,
+ &_PyContextTokenMissing_Type,
&_PyCoroWrapper_Type,
+ &_PyHamtItems_Type,
+ &_PyHamtKeys_Type,
+ &_PyHamtValues_Type,
+ &_PyHamt_ArrayNode_Type,
+ &_PyHamt_BitmapNode_Type,
+ &_PyHamt_CollisionNode_Type,
+ &_PyHamt_Type,
&_PyInterpreterID_Type,
&_PyManagedBuffer_Type,
&_PyMethodWrapper_Type,
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c
index ecd8be1af6f2d..ed612091d8394 100644
--- a/Python/bltinmodule.c
+++ b/Python/bltinmodule.c
@@ -2986,11 +2986,6 @@ _PyBuiltin_Init(PyInterpreterState *interp)
const PyConfig *config = _PyInterpreterState_GetConfig(interp);
- if (PyType_Ready(&PyFilter_Type) < 0 ||
- PyType_Ready(&PyMap_Type) < 0 ||
- PyType_Ready(&PyZip_Type) < 0)
- return NULL;
-
mod = _PyModule_CreateInitialized(&builtinsmodule, PYTHON_API_VERSION);
if (mod == NULL)
return NULL;
diff --git a/Python/context.c b/Python/context.c
index 9ed73b7444d44..f3033d9b649af 100644
--- a/Python/context.c
+++ b/Python/context.c
@@ -1260,7 +1260,7 @@ context_token_missing_tp_repr(PyObject *self)
}
-PyTypeObject PyContextTokenMissing_Type = {
+PyTypeObject _PyContextTokenMissing_Type = {
PyVarObject_HEAD_INIT(&PyType_Type, 0)
"Token.MISSING",
sizeof(PyContextTokenMissing),
@@ -1279,7 +1279,7 @@ get_token_missing(void)
}
_token_missing = (PyObject *)PyObject_New(
- PyContextTokenMissing, &PyContextTokenMissing_Type);
+ PyContextTokenMissing, &_PyContextTokenMissing_Type);
if (_token_missing == NULL) {
return NULL;
}
@@ -1323,25 +1323,12 @@ _PyContext_Fini(PyInterpreterState *interp)
PyStatus
-_PyContext_InitTypes(PyInterpreterState *interp)
+_PyContext_Init(PyInterpreterState *interp)
{
if (!_Py_IsMainInterpreter(interp)) {
return _PyStatus_OK();
}
- PyStatus status = _PyHamt_InitTypes(interp);
- if (_PyStatus_EXCEPTION(status)) {
- return status;
- }
-
- if ((PyType_Ready(&PyContext_Type) < 0) ||
- (PyType_Ready(&PyContextVar_Type) < 0) ||
- (PyType_Ready(&PyContextToken_Type) < 0) ||
- (PyType_Ready(&PyContextTokenMissing_Type) < 0))
- {
- return _PyStatus_ERR("can't init context types");
- }
-
PyObject *missing = get_token_missing();
if (PyDict_SetItemString(
PyContextToken_Type.tp_dict, "MISSING", missing))
diff --git a/Python/hamt.c b/Python/hamt.c
index 8c8e025a3eff3..cbfe4459d3ed0 100644
--- a/Python/hamt.c
+++ b/Python/hamt.c
@@ -2953,27 +2953,6 @@ PyTypeObject _PyHamt_CollisionNode_Type = {
};
-PyStatus
-_PyHamt_InitTypes(PyInterpreterState *interp)
-{
- if (!_Py_IsMainInterpreter(interp)) {
- return _PyStatus_OK();
- }
-
- if ((PyType_Ready(&_PyHamt_Type) < 0) ||
- (PyType_Ready(&_PyHamt_ArrayNode_Type) < 0) ||
- (PyType_Ready(&_PyHamt_BitmapNode_Type) < 0) ||
- (PyType_Ready(&_PyHamt_CollisionNode_Type) < 0) ||
- (PyType_Ready(&_PyHamtKeys_Type) < 0) ||
- (PyType_Ready(&_PyHamtValues_Type) < 0) ||
- (PyType_Ready(&_PyHamtItems_Type) < 0))
- {
- return _PyStatus_ERR("can't init hamt types");
- }
-
- return _PyStatus_OK();
-}
-
void
_PyHamt_Fini(PyInterpreterState *interp)
{
diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c
index 662e578818349..a53f532e9e202 100644
--- a/Python/pylifecycle.c
+++ b/Python/pylifecycle.c
@@ -760,7 +760,7 @@ pycore_init_types(PyInterpreterState *interp)
return status;
}
- status = _PyContext_InitTypes(interp);
+ status = _PyContext_Init(interp);
if (_PyStatus_EXCEPTION(status)) {
return status;
}
More information about the Python-checkins
mailing list