8000 Reuse tp_cache for tp_defined_slots · python/cpython@694e1b0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 694e1b0

Browse files
committed
Reuse tp_cache for tp_defined_slots
1 parent 9026dcc commit 694e1b0

File tree

13 files changed

+31
-45
lines changed

13 files changed

+31
-45
lines changed

Doc/c-api/typeobj.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,9 +1026,9 @@ type objects) *must* have the :attr:`ob_size` field.
10261026
.. seealso:: "Safe object finalization" (:pep:`442`)
10271027

10281028

1029-
.. c:member:: PyObject* PyTypeObject.tp_cache
1029+
.. c:member:: PyObject* PyTypeObject.tp_defined_slots
10301030
1031-
Unused. Not inherited. Internal use only.
1031+
Not inherited. Internal use only.
10321032

10331033

10341034
.. c:member:: PyObject* PyTypeObject.tp_subclasses

Doc/includes/typestruct.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ typedef struct _typeobject {
6767
inquiry tp_is_gc; /* For PyObject_IS_GC */
6868
PyObject *tp_bases;
6969
PyObject *tp_mro; /* method resolution order */
70-
PyObject *tp_cache;
70+
PyObject *tp_defined_slots;
7171
PyObject *tp_subclasses;
7272
PyObject *tp_weaklist;
7373
destructor tp_del;

Include/object.h

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ typedef struct _typeobject {
414414
inquiry tp_is_gc; /* For PyObject_IS_GC */
415415
PyObject *tp_bases;
416416
PyObject *tp_mro; /* method resolution order */
417-
PyObject *tp_cache;
417+
PyObject *tp_defined_slots; /* internal cache; changed in version 3.7 */
418418
PyObject *tp_subclasses;
419419
PyObject *tp_weaklist;
420420
destructor tp_del;
@@ -424,8 +424,6 @@ typedef struct _typeobject {
424424

425425
destructor tp_finalize;
426426

427-
PyObject *tp_defined_slots;
428-
429427
#ifdef COUNT_ALLOCS
430428
/* these must be last and never explicitly initialized */
431429
Py_ssize_t tp_allocs;
@@ -658,21 +656,17 @@ given type object has a specified feature.
658656
#define Py_TPFLAGS_BASE_EXC_SUBCLASS (1UL << 30)
659657
#define Py_TPFLAGS_TYPE_SUBCLASS (1UL << 31)
660658

659+
#define Py_TPFLAGS_DEFAULT ( \
660+
Py_TPFLAGS_HAVE_STACKLESS_EXTENSION | \
661+
Py_TPFLAGS_HAVE_VERSION_TAG | \
662+
0)
663+
661664
/* NOTE: The following flags reuse lower bits (removed as part of the
662665
* Python 3.0 transition). */
663666

664667
/* Type structure has tp_finalize member (3.4) */
665668
#define Py_TPFLAGS_HAVE_FINALIZE (1UL << 0)
666669

667-
/* Type structure has tp_defined_slots member (3.7) */
668-
#define Py_TPFLAGS_HAVE_DEFINED_SLOTS (1UL << 1)
669-
670-
#define Py_TPFLAGS_DEFAULT ( \
671-
Py_TPFLAGS_HAVE_STACKLESS_EXTENSION | \
672-
Py_TPFLAGS_HAVE_VERSION_TAG | \
673-
Py_TPFLAGS_HAVE_DEFINED_SLOTS | \
674-
0)
675-
676670
#ifdef Py_LIMITED_API
677671
#define PyType_HasFeature(t,f) ((PyType_GetFlags(t) & (f)) != 0)
678672
#else

Lib/test/test_sys.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1113,7 +1113,7 @@ def delx(self): del self.__x
11131113
check((1,2,3), vsize('') + 3*self.P)
11141114
# type
11151115
# static type: PyTypeObject
1116-
fmt = 'P2n15Pl4Pn9Pn11PI2P'
1116+
fmt = 'P2n15Pl4Pn9Pn11PIP'
11171117
if hasattr(sys, 'getcounts'):
11181118
fmt += '3n2P'
11191119
s = vsize(fmt)

Modules/_io/bufferedio.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2374,7 +2374,7 @@ PyTypeObject PyBufferedIOBase_Type = {
23742374
0, /* tp_is_gc */
23752375
0, /* tp_bases */
23762376
0, /* tp_mro */
2377-
0, /* tp_cache */
2377+
0, /* tp_defined_slots */
23782378
0, /* tp_subclasses */
23792379
0, /* tp_weaklist */
23802380
0, /* tp_del */
@@ -2466,7 +2466,7 @@ PyTypeObject PyBufferedReader_Type = {
24662466
0, /* tp_is_gc */
24672467
0, /* tp_bases */
24682468
0, /* tp_mro */
2469-
0, /* tp_cache */
2469+
0, /* tp_defined_slots */
24702470
0, /* tp_subclasses */
24712471
0, /* tp_weaklist */
24722472
0, /* tp_del */
@@ -2553,7 +2553,7 @@ PyTypeObject PyBufferedWriter_Type = {
25532553
0, /* tp_is_gc */
25542554
0, /* tp_bases */
25552555
0, /* tp_mro */
2556-
0, /* tp_cache */
2556+
0, /* tp_defined_slots */
25572557
0, /* tp_subclasses */
25582558
0, /* tp_weaklist */
25592559
0, /* tp_del */
@@ -2632,7 +2632,7 @@ PyTypeObject PyBufferedRWPair_Type = {
26322632
0, /* tp_is_gc */
26332633
0, /* tp_bases */
26342634
0, /* tp_mro */
2635-
0, /* tp_cache */
2635+
0, /* tp_defined_slots */
26362636
0, /* tp_subclasses */
26372637
0, /* tp_weaklist */
26382638
0, /* tp_del */
@@ -2727,7 +2727,7 @@ PyTypeObject PyBufferedRandom_Type = {
27272727
0, /* tp_is_gc */
27282728
0, /* tp_bases */
27292729
0, /* tp_mro */
2730-
0, /* tp_cache */
2730+
0, /* tp_defined_slots */
27312731
0, /* tp_subclasses */
27322732
0, /* tp_weaklist */
27332733
0, /* tp_del */

Modules/_io/fileio.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1231,7 +1231,7 @@ PyTypeObject PyFileIO_Type = {
12311231
0, /* tp_is_gc */
12321232
0, /* tp_bases */
12331233
0, /* tp_mro */
1234-
0, /* tp_cache */
1234+
0, /* tp_defined_slots */
12351235
0, /* tp_subclasses */
12361236
0, /* tp_weaklist */
12371237
0, /* tp_del */

Modules/_io/iobase.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -831,7 +831,7 @@ PyTypeObject PyIOBase_Type = {
831831
0, /* tp_is_gc */
832832
0, /* tp_bases */
833833
0, /* tp_mro */
834-
0, /* tp_cache */
834+
0, /* tp_defined_slots */
835835
0, /* tp_subclasses */
836836
0, /* tp_weaklist */
837837
0, /* tp_del */
@@ -1026,7 +1026,7 @@ PyTypeObject PyRawIOBase_Type = {
10261026
0, /* tp_is_gc */
10271027
0, /* tp_bases */
10281028
0, /* tp_mro */
1029-
0, /* tp_cache */
1029+
0, /* tp_defined_slots */
10301030
0, /* tp_subclasses */
10311031
0, /* tp_weaklist */
10321032
0, /* tp_del */

Modules/_io/textio.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ PyTypeObject PyTextIOBase_Type = {
207207
0, /* tp_is_gc */
208208
0, /* tp_bases */
209209
0, /* tp_mro */
210-
0, /* tp_cache */
210+
0, /* tp_defined_slots */
211211
0, /* tp_subclasses */
212212
0, /* tp_weaklist */
213213
0, /* tp_del */
@@ -3202,7 +3202,7 @@ PyTypeObject PyTextIOWrapper_Type = {
32023202
0, /* tp_is_gc */
32033203
0, /* tp_bases */
32043204
0, /* tp_mro */
3205-
0, /* tp_cache */
3205+
0, /* tp_defined_slots */
32063206
0, /* tp_subclasses */
32073207
0, /* tp_weaklist */
32083208
0, /* tp_del */

Modules/_io/winconsoleio.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1155,7 +1155,7 @@ PyTypeObject PyWindowsConsoleIO_Type = {
11551155
0, /* tp_is_gc */
11561156
0, /* tp_bases */
11571157
0, /* tp_mro */
1158-
0, /* tp_cache */
1158+
0, /* tp_defined_slots */
11591159
0, /* tp_subclasses */
11601160
0, /* tp_weaklist */
11611161
0, /* tp_del */

Modules/posixmodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12141,7 +12141,7 @@ static PyTypeObject ScandirIteratorType = {
1214112141
0, /* tp_is_gc */
1214212142
0, /* tp_bases */
1214312143
0, /* tp_mro */
12144-
0, /* tp_cache */
12144+
0, /* tp_defined_slots */
1214512145
0, /* tp_subclasses */
1214612146
0, /* tp_weaklist */
1214712147
0, /* tp_del */

Modules/socketmodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4925,7 +4925,7 @@ static PyTypeObject sock_type = {
49254925
0, /* tp_is_gc */
49264926
0, /* tp_bases */
49274927
0, /* tp_mro */
4928-
0, /* tp_cache */
4928+
0, /* tp_defined_slots */
49294929
0, /* tp_subclasses */
49304930
0, /* tp_weaklist */
49314931
0, /* tp_del */

Objects/genobject.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -807,7 +807,7 @@ PyTypeObject PyGen_Type = {
807807
0, /* tp_is_gc */
808808
0, /* tp_bases */
809809
0, /* tp_mro */
810-
0, /* tp_cache */
810+
0, /* tp_defined_slots */
811811
0, /* tp_subclasses */
812812
0, /* tp_weaklist */
813813
0, /* tp_del */
@@ -1062,7 +1062,7 @@ PyTypeObject PyCoro_Type = {
10621062
0, /* tp_is_gc */
10631063
0, /* tp_bases */
10641064
0, /* tp_mro */
1065-
0, /* tp_cache */
1065+
0, /* tp_defined_slots */
10661066
0, /* tp_subclasses */
10671067
0, /* tp_weaklist */
10681068
0, /* tp_del */
@@ -1407,7 +1407,7 @@ PyTypeObject PyAsyncGen_Type = {
14071407
0, /* tp_is_gc */
14081408
0, /* tp_bases */
14091409
0, /* tp_mro */
1410-
0, /* tp_cache */
1410+
0, /* tp_defined_slots */
14111411
0, /* tp_subclasses */
14121412
0, /* tp_weaklist */
14131413
0, /* tp_del */

Objects/typeobject.c

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,7 @@ PyType_Modified(PyTypeObject *type)
253253
PyObject *raw, *ref;
254254
Py_ssize_t i;
255255

256-
if (PyType_HasFeature(type, Py_TPFLAGS_HAVE_DEFINED_SLOTS))
257-
Py_CLEAR(type->tp_defined_slots);
256+
Py_CLEAR(type->tp_defined_slots);
258257

259258
if (!PyType_HasFeature(type, Py_TPFLAGS_VALID_VERSION_TAG))
260259
return;
@@ -3271,7 +3270,6 @@ type_dealloc(PyTypeObject *type)
32713270
Py_XDECREF(type->tp_dict);
32723271
Py_XDECREF(type->tp_bases);
32733272
Py_XDECREF(type->tp_mro);
3274-
Py_XDECREF(type->tp_cache);
32753273
Py_XDECREF(type->tp_subclasses);
32763274
Py_XDECREF(type->tp_defined_slots);
32773275
/* A type's tp_doc is heap allocated, unlike the tp_doc slots
@@ -3466,7 +3464,6 @@ type_traverse(PyTypeObject *type, visitproc visit, void *arg)
34663464
}
34673465

34683466
Py_VISIT(type->tp_dict);
3469-
Py_VISIT(type->tp_cache);
34703467
Py_VISIT(type->tp_defined_slots);
34713468
Py_VISIT(type->tp_mro);
34723469
Py_VISIT(type->tp_bases);
@@ -3498,9 +3495,6 @@ type_clear(PyTypeObject *type)
34983495
tp_clear handler). None of the other fields need to be
34993496
cleared, and here's why:
35003497
3501-
tp_cache:
3502-
Not used; if it were, it would be a dict.
3503-
35043498
tp_bases, tp_base:
35053499
If these are involved in a cycle, there must be at least
35063500
one other, mutable object in the cycle, e.g. a base
@@ -3523,6 +3517,7 @@ type_clear(PyTypeObject *type)
35233517
if (type->tp_dict)
35243518
PyDict_Clear(type->tp_dict);
35253519
Py_CLEAR(type->tp_mro);
3520+
Py_CLEAR(type->tp_defined_slots);
35263521

35273522
return 0;
35283523
}
@@ -7061,8 +7056,7 @@ get_tp_defined_slots(PyTypeObject *type)
70617056
{
70627057
PyObject *lst, *res;
70637058

7064-
if (PyType_HasFeature(type, Py_TPFLAGS_HAVE_DEFINED_SLOTS)
7065-
&& type->tp_defined_slots != NULL) {
7059+
if (type->tp_defined_slots != NULL) {
70667060
res = type->tp_defined_slots;
70677061
assert(PyTuple_CheckExact(res));
70687062
Py_INCREF(res);
@@ -7097,11 +7091,9 @@ get_tp_defined_slots(PyTypeObject *type)
70977091
Py_DECREF(tup);
70987092
}
70997093
res = PyList_AsTuple(lst);
7094+
Py_INCREF(res);
71007095
Py_DECREF(lst);
7101-
if (PyType_HasFeature(type, Py_TPFLAGS_HAVE_DEFINED_SLOTS)) {
7102-
Py_INCREF(res);
7103-
type->tp_defined_slots = res;
7104-
}
7096+
type->tp_defined_slots = res;
71057097
return res;
71067098

71077099
error:

0 commit comments

Comments
 (0)
0