Skip to content

Commit 5687c8e

Browse files
Store the index in tp_subclasses.
1 parent eade37b commit 5687c8e

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

Include/cpython/object.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ struct _typeobject {
218218
PyObject *tp_bases;
219219
PyObject *tp_mro; /* method resolution order */
220220
PyObject *tp_cache; /* no longer used */
221-
PyObject *tp_subclasses; /* not used for static types (see gh-94673) */
221+
PyObject *tp_subclasses; /* for static builtin types this is an index */
222222
PyObject *tp_weaklist;
223223
destructor tp_del;
224224

@@ -227,7 +227,6 @@ struct _typeobject {
227227

228228
destructor tp_finalize;
229229
vectorcallfunc tp_vectorcall;
230-
size_t tp_static_builtin_index; /* 0 means "not initialized" */
231230
};
232231

233232
/* This struct is used by the specializer

Objects/typeobject.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -73,29 +73,29 @@ static inline PyTypeObject * subclass_from_ref(PyObject *ref);
7373
static inline int
7474
static_builtin_index_is_set(PyTypeObject *self)
7575
{
76-
return self->tp_static_builtin_index > 0;
76+
return self->tp_subclasses != NULL;
7777
}
7878

7979
static inline size_t
8080
static_builtin_index_get(PyTypeObject *self)
8181
{
8282
assert(static_builtin_index_is_set(self));
8383
/* We store a 1-based index so 0 can mean "not initialized". */
84-
return self->tp_static_builtin_index - 1;
84+
return (size_t)self->tp_subclasses - 1;
8585
}
8686

8787
static inline void
8888
static_builtin_index_set(PyTypeObject *self, size_t index)
8989
{
9090
assert(index < _Py_MAX_STATIC_BUILTIN_TYPES);
9191
/* We store a 1-based index so 0 can mean "not initialized". */
92-
self->tp_static_builtin_index = index + 1;
92+
self->tp_subclasses = (PyObject *)(index + 1);
9393
}
9494

9595
static inline void
9696
static_builtin_index_clear(PyTypeObject *self)
9797
{
98-
self->tp_static_builtin_index = 0;
98+
self->tp_subclasses = NULL;
9999
}
100100

101101
static inline static_builtin_state *

0 commit comments

Comments
 (0)