3
3
#include "Python.h"
4
4
#include "pycore_call.h"
5
5
#include "pycore_code.h" // CO_FAST_FREE
6
- #include "pycore_symtable.h" // _Py_Mangle()
7
6
#include "pycore_dict.h" // _PyDict_KeysSize()
7
+ #include "pycore_frame.h" // _PyInterpreterFrame
8
8
#include "pycore_initconfig.h" // _PyStatus_OK()
9
+ #include "pycore_long.h" // _PyLong_IsNegative()
9
10
#include "pycore_memoryobject.h" // _PyMemoryView_FromBufferProc()
10
11
#include "pycore_moduleobject.h" // _PyModule_GetDef()
11
12
#include "pycore_object.h" // _PyType_HasFeature()
12
- #include "pycore_long.h" // _PyLong_IsNegative()
13
13
#include "pycore_pyerrors.h" // _PyErr_Occurred()
14
14
#include "pycore_pystate.h" // _PyThreadState_GET()
15
+ #include "pycore_symtable.h" // _Py_Mangle()
15
16
#include "pycore_typeobject.h" // struct type_cache
16
17
#include "pycore_unionobject.h" // _Py_union_type_or
17
- #include "pycore_frame .h" // _PyInterpreterFrame
18
+ #include "pycore_weakref .h" // _PyWeakref_GET_REF()
18
19
#include "opcode.h" // MAKE_CELL
19
20
#include "structmember.h" // PyMemberDef
20
21
@@ -75,13 +76,10 @@ slot_tp_setattro(PyObject *self, PyObject *name, PyObject *value);
75
76
static inline PyTypeObject *
76
77
type_from_ref (PyObject * ref )
77
78
{
78
- assert (PyWeakref_CheckRef (ref ));
79
- PyObject * obj = PyWeakref_GET_OBJECT (ref ); // borrowed ref
80
- assert (obj != NULL );
81
- if (obj == Py_None ) {
79
+ PyObject * obj = _PyWeakref_GET_REF (ref );
80
+ if (obj == NULL ) {
82
81
return NULL ;
83
82
}
84
- assert (PyType_Check (obj ));
85
83
return _PyType_CAST (obj );
86
84
}
87
85
@@ -450,15 +448,17 @@ _PyType_GetSubclasses(PyTypeObject *self)
450
448
Py_ssize_t i = 0 ;
451
449
PyObject * ref ; // borrowed ref
452
450
while (PyDict_Next (subclasses , & i , NULL , & ref )) {
453
- PyTypeObject * subclass = type_from_ref (ref ); // borrowed
451
+ PyTypeObject * subclass = type_from_ref (ref );
454
452
if (subclass == NULL ) {
455
453
continue ;
456
454
}
457
455
458
456
if (PyList_Append (list , _PyObject_CAST (subclass )) < 0 ) {
459
457
Py_DECREF (list );
458
+ Py_DECREF (subclass );
460
459
return NULL ;
461
460
}
461
+ Py_DECREF (subclass );
462
462
}
463
463
return list ;
464
464
}
@@ -778,11 +778,12 @@ PyType_Modified(PyTypeObject *type)
778
778
Py_ssize_t i = 0 ;
779
779
PyObject * ref ;
780
780
while (PyDict_Next (subclasses , & i , NULL , & ref )) {
781
- PyTypeObject * subclass = type_from_ref (ref ); // borrowed
781
+ PyTypeObject * subclass = type_from_ref (ref );
782
782
if (subclass == NULL ) {
783
783
continue ;
784
784
}
785
785
PyType_Modified (subclass );
786
+ Py_DECREF (subclass );
786
787
}
787
788
}
788
789
@@ -4989,12 +4990,13 @@ clear_static_tp_subclasses(PyTypeObject *type)
4989
4990
Py_ssize_t i = 0 ;
4990
4991
PyObject * key , * ref ; // borrowed ref
4991
4992
while (PyDict_Next (subclasses , & i , & key , & ref )) {
4992
- PyTypeObject * subclass = type_from_ref (ref ); // borrowed
4993
+ PyTypeObject * subclass = type_from_ref (ref );
4993
4994
if (subclass == NULL ) {
4994
4995
continue ;
4995
4996
}
4996
4997
// All static builtin subtypes should have been finalized already.
4997
4998
assert (!(subclass -> tp_flags & _Py_TPFLAGS_STATIC_BUILTIN ));
4999
+ Py_DECREF (subclass );
4998
5000
}
4999
5001
5000
5002
clear_tp_subclasses (type );
@@ -7636,10 +7638,12 @@ get_subclasses_key(PyTypeObject *type, PyTypeObject *base)
7636
7638
PyObject * subclasses = lookup_tp_subclasses (base );
7637
7639
if (subclasses != NULL ) {
7638
7640
while (PyDict_Next (subclasses , & i , & key , & ref )) {
7639
- PyTypeObject * subclass = type_from_ref (ref ); // borrowed
7641
+ PyTypeObject * subclass = type_from_ref (ref );
7640
7642
if (subclass == type ) {
7643
+ Py_DECREF (subclass );
7641
7644
return Py_NewRef (key );
7642
7645
}
7646
+ Py_DECREF (subclass );
7643
7647
}
7644
7648
}
7645
7649
/* It wasn't found. */
@@ -10035,7 +10039,7 @@ recurse_down_subclasses(PyTypeObject *type, PyObject *attr_name,
10035
10039
Py_ssize_t i = 0 ;
10036
10040
PyObject * ref ;
10037
10041
while (PyDict_Next (subclasses , & i , NULL , & ref )) {
10038
- PyTypeObject * subclass = type_from_ref (ref ); // borrowed
10042
+ PyTypeObject * subclass = type_from_ref (ref );
10039
10043
if (subclass == NULL ) {
10040
10044
continue ;
10041
10045
}
@@ -10045,16 +10049,20 @@ recurse_down_subclasses(PyTypeObject *type, PyObject *attr_name,
10045
10049
if (dict != NULL && PyDict_Check (dict )) {
10046
10050
int r = PyDict_Contains (dict , attr_name );
10047
10051
if (r < 0 ) {
10052
+ Py_DECREF (subclass );
10048
10053
return -1 ;
10049
10054
}
10050
10055
if (r > 0 ) {
10056
+ Py_DECREF (subclass );
10051
10057
continue ;
10052
10058
}
10053
10059
}
10054
10060
10055
10061
if (update_subclasses (subclass , attr_name , callback , data ) < 0 ) {
10062
+ Py_DECREF (subclass );
10056
10063
return -1 ;
10057
10064
}
10065
+ Py_DECREF (subclass );
10058
10066
}
10059
10067
return 0 ;
10060
10068
}
0 commit comments