File tree Expand file tree Collapse file tree 32 files changed +76
-33
lines changed Expand file tree Collapse file tree 32 files changed +76
-33
lines changed Original file line number Diff line number Diff line change @@ -29,6 +29,9 @@ extern "C" {
29
29
PyMutex_LockFlags(wr->weakrefs_lock, _Py_LOCK_DONT_DETACH)
30
30
#define UNLOCK_WEAKREFS_FOR_WR (wr ) PyMutex_Unlock(wr->weakrefs_lock)
31
31
32
+ #define FT_CLEAR_WEAKREFS (obj , weakref_list ) \
33
+ PyObject_ClearWeakRefs(obj)
34
+
32
35
#else
33
36
34
37
#define LOCK_WEAKREFS (obj )
@@ -37,6 +40,13 @@ extern "C" {
37
40
#define LOCK_WEAKREFS_FOR_WR (wr )
38
41
#define UNLOCK_WEAKREFS_FOR_WR (wr )
39
42
43
+ #define FT_CLEAR_WEAKREFS (obj , weakref_list ) \
44
+ do { \
45
+ if (weakref_list != NULL) { \
46
+ PyObject_ClearWeakRefs(obj); \
47
+ } \
48
+ } while (0)
49
+
40
50
#endif
41
51
42
52
static inline int _is_dead (PyObject * obj )
Original file line number Diff line number Diff line change 5
5
#include "pycore_moduleobject.h" // _PyModule_GetState()
6
6
#include "pycore_pyatomic_ft_wrappers.h"
7
7
#include "pycore_typeobject.h" // _PyType_GetModuleState()
8
+ #include "pycore_weakref.h"
8
9
9
10
#include <stddef.h>
10
11
@@ -1532,7 +1533,7 @@ deque_dealloc(PyObject *self)
1532
1533
Py_ssize_t i ;
1533
1534
1534
1535
PyObject_GC_UnTrack (deque );
1535
- PyObject_ClearWeakRefs (self );
1536
+ FT_CLEAR_WEAKREFS (self , deque -> weakreflist );
1536
1537
if (deque -> leftblock != NULL ) {
1537
1538
(void )deque_clear (self );
1538
1539
assert (deque -> leftblock != NULL );
Original file line number Diff line number Diff line change 17
17
18
18
#include "Python.h"
19
19
#include "pycore_pyhash.h" // _Py_HashSecret
20
+ #include "pycore_weakref.h"
20
21
21
22
#include <stddef.h> // offsetof()
22
23
#include "expat.h"
@@ -690,7 +691,7 @@ element_dealloc(PyObject *op)
690
691
/* bpo-31095: UnTrack is needed before calling any callbacks */
691
692
PyObject_GC_UnTrack (self );
692
693
693
- PyObject_ClearWeakRefs (op );
694
+ FT_CLEAR_WEAKREFS (op , self -> weakreflist );
694
695
695
696
/* element_gc_clear clears all references and deallocates extra
696
697
*/
Original file line number Diff line number Diff line change 7
7
#include "pycore_pyatomic_ft_wrappers.h"
8
8
#include "pycore_pystate.h" // _PyThreadState_GET()
9
9
#include "pycore_tuple.h" // _PyTuple_ITEMS()
10
+ #include "pycore_weakref.h"
10
11
11
12
12
13
#include "clinic/_functoolsmodule.c.h"
@@ -351,7 +352,7 @@ partial_dealloc(PyObject *self)
351
352
PyTypeObject * tp = Py_TYPE (self );
352
353
/* bpo-31095: UnTrack is needed before calling any callbacks */
353
354
PyObject_GC_UnTrack (self );
354
- PyObject_ClearWeakRefs (self );
355
+ FT_CLEAR_WEAKREFS (self , partialobject_CAST ( self ) -> weakreflist );
355
356
(void )partial_clear (self );
356
357
tp -> tp_free (self );
357
358
Py_DECREF (tp );
@@ -1619,7 +1620,7 @@ lru_cache_dealloc(PyObject *op)
1619
1620
PyTypeObject * tp = Py_TYPE (obj );
1620
1621
/* bpo-31095: UnTrack is needed before calling any callbacks */
1621
1622
PyObject_GC_UnTrack (obj );
1622
- PyObject_ClearWeakRefs (op );
1623
+ FT_CLEAR_WEAKREFS (op , obj -> weakreflist );
1623
1624
1624
1625
(void )lru_cache_tp_clear (op );
1625
1626
tp -> tp_free (obj );
Original file line number Diff line number Diff line change 13
13
#include "pycore_object.h" // _PyObject_GC_UNTRACK()
14
14
#include "pycore_pyerrors.h" // _Py_FatalErrorFormat()
15
15
#include "pycore_pylifecycle.h" // _Py_IsInterpreterFinalizing()
16
+ #include "pycore_weakref.h"
16
17
17
18
#include "_iomodule.h"
18
19
@@ -421,7 +422,7 @@ buffered_dealloc(PyObject *op)
421
422
return ;
422
423
_PyObject_GC_UNTRACK (self );
423
424
self -> ok = 0 ;
424
- PyObject_ClearWeakRefs (op );
425
+ FT_CLEAR_WEAKREFS (op , self -> weakreflist );
425
426
if (self -> buffer ) {
426
427
PyMem_Free (self -> buffer );
427
428
self -> buffer = NULL ;
@@ -2311,7 +2312,7 @@ bufferedrwpair_dealloc(PyObject *op)
2311
2312
rwpair * self = rwpair_CAST (op );
2312
2313
PyTypeObject * tp = Py_TYPE (self );
2313
2314
_PyObject_GC_UNTRACK (self );
2314
- PyObject_ClearWeakRefs (op );
2315
+ FT_CLEAR_WEAKREFS (op , self -> weakreflist );
2315
2316
(void )bufferedrwpair_clear (op );
2316
2317
tp -> tp_free (self );
2317
2318
Py_DECREF (tp );
Original file line number Diff line number Diff line change 3
3
#include "pycore_object.h"
4
4
#include "pycore_pyatomic_ft_wrappers.h"
5
5
#include "pycore_sysmodule.h" // _PySys_GetSizeOf()
6
+ #include "pycore_weakref.h"
6
7
7
8
#include <stddef.h> // offsetof()
8
9
#include "_iomodule.h"
@@ -979,7 +980,7 @@ bytesio_dealloc(PyObject *op)
979
980
}
980
981
Py_CLEAR (self -> buf );
981
982
Py_CLEAR (self -> dict );
982
- PyObject_ClearWeakRefs (op );
983
+ FT_CLEAR_WEAKREFS (op , self -> weakreflist );
983
984
tp -> tp_free (self );
984
985
Py_DECREF (tp );
985
986
}
Original file line number Diff line number Diff line change 4
4
#include "pycore_fileutils.h" // _Py_BEGIN_SUPPRESS_IPH
5
5
#include "pycore_object.h" // _PyObject_GC_UNTRACK()
6
6
#include "pycore_pyerrors.h" // _PyErr_ChainExceptions1()
7
+ #include "pycore_weakref.h"
7
8
8
9
#include <stdbool.h> // bool
9
10
#ifdef HAVE_UNISTD_H
@@ -570,7 +571,7 @@ fileio_dealloc(PyObject *op)
570
571
PyMem_Free (self -> stat_atopen );
571
572
self -> stat_atopen = NULL ;
572
573
}
573
- PyObject_ClearWeakRefs (op );
574
+ FT_CLEAR_WEAKREFS (op , self -> weakreflist );
574
575
(void )fileio_clear (op );
575
576
576
577
PyTypeObject * tp = Py_TYPE (op );
Original file line number Diff line number Diff line change 14
14
#include "pycore_long.h" // _PyLong_GetOne()
15
15
#include "pycore_object.h" // _PyType_HasFeature()
16
16
#include "pycore_pyerrors.h" // _PyErr_ChainExceptions1()
17
+ #include "pycore_weakref.h"
17
18
18
19
#include <stddef.h> // offsetof()
19
20
#include "_iomodule.h"
@@ -383,7 +384,7 @@ iobase_dealloc(PyObject *op)
383
384
}
384
385
PyTypeObject * tp = Py_TYPE (self );
385
386
_PyObject_GC_UNTRACK (self );
386
- PyObject_ClearWeakRefs (op );
387
+ FT_CLEAR_WEAKREFS (op , self -> weakreflist );
387
388
Py_CLEAR (self -> dict );
388
389
tp -> tp_free (self );
389
390
Py_DECREF (tp );
Original file line number Diff line number Diff line change 1
1
#include "Python.h"
2
2
#include <stddef.h> // offsetof()
3
3
#include "pycore_object.h"
4
+ #include "pycore_weakref.h"
4
5
#include "_iomodule.h"
5
6
6
7
/* Implementation note: the buffer is always at least one character longer
@@ -638,7 +639,7 @@ stringio_dealloc(PyObject *op)
638
639
}
639
640
PyUnicodeWriter_Discard (self -> writer );
640
641
(void )stringio_clear (op );
641
- PyObject_ClearWeakRefs (op );
642
+ FT_CLEAR_WEAKREFS (op , self -> weakreflist );
642
643
tp -> tp_free (self );
643
644
Py_DECREF (tp );
644
645
}
Original file line number Diff line number Diff line change 16
16
#include "pycore_pyerrors.h" // _PyErr_ChainExceptions1()
17
17
#include "pycore_pystate.h" // _PyInterpreterState_GET()
18
18
#include "pycore_unicodeobject.h" // _PyUnicode_AsASCIIString()
19
+ #include "pycore_weakref.h"
19
20
20
21
#include "_iomodule.h"
21
22
@@ -1469,7 +1470,7 @@ textiowrapper_dealloc(PyObject *op)
1469
1470
return ;
1470
1471
self -> ok = 0 ;
1471
1472
_PyObject_GC_UNTRACK (self );
1472
- PyObject_ClearWeakRefs (op );
1473
+ FT_CLEAR_WEAKREFS (op , self -> weakreflist );
1473
1474
(void )textiowrapper_clear (op );
1474
1475
tp -> tp_free (self );
1475
1476
Py_DECREF (tp );
Original file line number Diff line number Diff line change 10
10
#include "pycore_fileutils.h" // _Py_BEGIN_SUPPRESS_IPH
11
11
#include "pycore_object.h" // _PyObject_GC_UNTRACK()
12
12
#include "pycore_pyerrors.h" // _PyErr_ChainExceptions1()
13
+ #include "pycore_weakref.h"
13
14
14
15
#ifdef HAVE_WINDOWS_CONSOLE_IO
15
16
@@ -518,7 +519,7 @@ winconsoleio_dealloc(PyObject *op)
518
519
if (_PyIOBase_finalize (op ) < 0 )
519
520
return ;
520
521
_PyObject_GC_UNTRACK (self );
521
- PyObject_ClearWeakRefs (op );
522
+ FT_CLEAR_WEAKREFS (op , self -> weakreflist );
522
523
Py_CLEAR (self -> dict );
523
524
tp -> tp_free (self );
524
525
Py_DECREF (tp );
Original file line number Diff line number Diff line change 7
7
#include "pycore_moduleobject.h" // _PyModule_GetState()
8
8
#include "pycore_parking_lot.h"
9
9
#include "pycore_time.h" // _PyTime_FromSecondsObject()
10
+ #include "pycore_weakref.h"
10
11
11
12
#include <stdbool.h>
12
13
#include <stddef.h> // offsetof()
@@ -221,7 +222,7 @@ simplequeue_dealloc(PyObject *op)
221
222
222
223
PyObject_GC_UnTrack (self );
223
224
(void )simplequeue_clear (op );
224
- PyObject_ClearWeakRefs (op );
225
+ FT_CLEAR_WEAKREFS (op , self -> weakreflist );
225
226
tp -> tp_free (self );
226
227
Py_DECREF (tp );
227
228
}
Original file line number Diff line number Diff line change 4
4
5
5
#include "blob.h"
6
6
#include "util.h"
7
+ #include "pycore_weakref.h"
7
8
8
9
#define clinic_state () (pysqlite_get_state_by_type(Py_TYPE(self)))
9
10
#include "clinic/blob.c.h"
@@ -56,7 +57,7 @@ blob_dealloc(PyObject *op)
56
57
57
58
close_blob (self );
58
59
59
- PyObject_ClearWeakRefs (op );
60
+ FT_CLEAR_WEAKREFS (op , self -> in_weakreflist );
60
61
(void )tp -> tp_clear (op );
61
62
tp -> tp_free (self );
62
63
Py_DECREF (tp );
Original file line number Diff line number Diff line change 31
31
#include "util.h"
32
32
33
33
#include "pycore_pyerrors.h" // _PyErr_FormatFromCause()
34
+ #include "pycore_weakref.h"
34
35
35
36
typedef enum {
36
37
TYPE_LONG ,
@@ -185,7 +186,7 @@ cursor_dealloc(PyObject *op)
185
186
pysqlite_Cursor * self = _pysqlite_Cursor_CAST (op );
186
187
PyTypeObject * tp = Py_TYPE (self );
187
188
PyObject_GC_UnTrack (self );
188
- PyObject_ClearWeakRefs (op );
189
+ FT_CLEAR_WEAKREFS (op , self -> in_weakreflist );
189
190
(void )tp -> tp_clear (op );
190
191
tp -> tp_free (self );
191
192
Py_DECREF (tp );
Original file line number Diff line number Diff line change @@ -44,6 +44,7 @@ static const char copyright[] =
44
44
#include "pycore_long.h" // _PyLong_GetZero()
45
45
#include "pycore_moduleobject.h" // _PyModule_GetState()
46
46
#include "pycore_unicodeobject.h" // _PyUnicode_Copy
47
+ #include "pycore_weakref.h"
47
48
48
49
#include "sre.h" // SRE_CODE
49
50
@@ -736,7 +737,8 @@ pattern_dealloc(PyObject *self)
736
737
{
737
738
PyTypeObject * tp = Py_TYPE (self );
738
739
PyObject_GC_UnTrack (self );
739
- PyObject_ClearWeakRefs (self );
740
+ PatternObject * obj = _PatternObject_CAST (self );
741
+ FT_CLEAR_WEAKREFS (self , obj -> weakreflist );
740
742
(void )pattern_clear (self );
741
743
tp -> tp_free (self );
742
744
Py_DECREF (tp );
Original file line number Diff line number Diff line change 11
11
#include "pycore_bytesobject.h" // _PyBytesWriter
12
12
#include "pycore_long.h" // _PyLong_AsByteArray()
13
13
#include "pycore_moduleobject.h" // _PyModule_GetState()
14
+ #include "pycore_weakref.h"
14
15
15
16
#include <stddef.h> // offsetof()
16
17
@@ -1794,7 +1795,7 @@ s_dealloc(PyObject *op)
1794
1795
PyStructObject * s = PyStructObject_CAST (op );
1795
1796
PyTypeObject * tp = Py_TYPE (s );
1796
1797
PyObject_GC_UnTrack (s );
1797
- PyObject_ClearWeakRefs (op );
1798
+ FT_CLEAR_WEAKREFS (op , s -> weakreflist );
1798
1799
if (s -> s_codes != NULL ) {
1799
1800
PyMem_Free (s -> s_codes );
1800
1801
}
Original file line number Diff line number Diff line change @@ -1034,7 +1034,8 @@ heapctypewithweakref_dealloc(PyObject *op)
1034
1034
{
1035
1035
HeapCTypeWithWeakrefObject * self = (HeapCTypeWithWeakrefObject * )op ;
1036
1036
PyTypeObject * tp = Py_TYPE (self );
1037
- PyObject_ClearWeakRefs (op );
1037
+ if (self -> weakreflist != NULL )
1038
+ PyObject_ClearWeakRefs ((PyObject * ) self );
1038
1039
Py_XDECREF (self -> weakreflist );
1039
1040
PyObject_Free (self );
1040
1041
Py_DECREF (tp );
Original file line number Diff line number Diff line change @@ -297,7 +297,9 @@ heapctypewithrelativeweakref_dealloc(PyObject* self)
297
297
{
298
298
PyTypeObject * tp = Py_TYPE (self );
299
299
HeapCTypeWithWeakrefStruct * data = PyObject_GetTypeData (self , tp );
300
- PyObject_ClearWeakRefs (self );
300
+ if (data -> weakreflist != NULL ) {
301
+ PyObject_ClearWeakRefs (self );
302
+ }
301
303
Py_XDECREF (data -> weakreflist );
302
304
PyObject_Free (self );
303
305
Py_DECREF (tp );
Original file line number Diff line number Diff line change 7
7
#include "pycore_long.h" // _PyLong_GetOne()
8
8
#include "pycore_pyerrors.h" // _PyErr_ChainExceptions1()
9
9
#include "pycore_typeobject.h" // _PyType_GetModuleState()
10
+ #include "pycore_weakref.h"
10
11
11
12
#include "datetime.h" // PyDateTime_TZInfo
12
13
@@ -375,7 +376,7 @@ zoneinfo_dealloc(PyObject *obj_self)
375
376
PyTypeObject * tp = Py_TYPE (self );
376
377
PyObject_GC_UnTrack (self );
377
378
378
- PyObject_ClearWeakRefs (obj_self );
379
+ FT_CLEAR_WEAKREFS (obj_self , self -> weakreflist );
379
380
380
381
if (self -> trans_list_utc != NULL ) {
381
382
PyMem_Free (self -> trans_list_utc );
Original file line number Diff line number Diff line change 13
13
#include "pycore_ceval.h" // _PyEval_GetBuiltin()
14
14
#include "pycore_modsupport.h" // _PyArg_NoKeywords()
15
15
#include "pycore_moduleobject.h" // _PyModule_GetState()
16
+ #include "pycore_weakref.h"
16
17
17
18
#include <stddef.h> // offsetof()
18
19
#include <stdbool.h>
@@ -728,7 +729,7 @@ array_dealloc(PyObject *op)
728
729
PyObject_GC_UnTrack (op );
729
730
730
731
arrayobject * self = arrayobject_CAST (op );
731
- PyObject_ClearWeakRefs (op );
732
+ FT_CLEAR_WEAKREFS (op , self -> weakreflist );
732
733
if (self -> ob_item != NULL ) {
733
734
PyMem_Free (self -> ob_item );
734
735
}
Original file line number Diff line number Diff line change 25
25
#include <Python.h>
26
26
#include "pycore_bytesobject.h" // _PyBytes_Find()
27
27
#include "pycore_fileutils.h" // _Py_stat_struct
28
+ #include "pycore_weakref.h"
28
29
29
30
#include <stddef.h> // offsetof()
30
31
#ifndef MS_WINDOWS
@@ -163,7 +164,7 @@ mmap_object_dealloc(PyObject *op)
163
164
Py_END_ALLOW_THREADS
164
165
#endif /* UNIX */
165
166
166
- PyObject_ClearWeakRefs (op );
167
+ FT_CLEAR_WEAKREFS (op , m_obj -> weakreflist );
167
168
168
169
tp -> tp_free (m_obj );
169
170
Py_DECREF (tp );
Original file line number Diff line number Diff line change 7
7
#include "pycore_object.h"
8
8
#include "pycore_pyerrors.h"
9
9
#include "pycore_pystate.h" // _PyThreadState_GET()
10
+ #include "pycore_weakref.h"
10
11
11
12
12
13
#include "clinic/classobject.c.h"
@@ -245,7 +246,7 @@ method_dealloc(PyObject *self)
245
246
{
246
247
PyMethodObject * im = _PyMethodObject_CAST (self );
247
248
_PyObject_GC_UNTRACK (im );
248
- PyObject_ClearWeakRefs (self );
249
+ FT_CLEAR_WEAKREFS (self , im -> im_weakreflist );
249
250
Py_DECREF (im -> im_func );
250
251
Py_XDECREF (im -> im_self );
251
252
assert (Py_IS_TYPE (self , & PyMethod_Type ));
You can’t perform that action at this time.
0 commit comments