File tree Expand file tree Collapse file tree 1 file changed +11
-4
lines changed Expand file tree Collapse file tree 1 file changed +11
-4
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,8 @@ extern "C" {
8
8
# error "this header requires Py_BUILD_CORE define"
9
9
#endif
10
10
11
+ #include "pycore_critical_section.h" // Py_BEGIN_CRITICAL_SECTION()
12
+
11
13
static inline PyObject * _PyWeakref_GET_REF (PyObject * ref_obj ) {
12
14
assert (PyWeakref_Check (ref_obj ));
13
15
PyWeakReference * ref = _Py_CAST (PyWeakReference * , ref_obj );
@@ -35,15 +37,20 @@ static inline PyObject* _PyWeakref_GET_REF(PyObject *ref_obj) {
35
37
36
38
static inline int _PyWeakref_IS_DEAD (PyObject * ref_obj ) {
37
39
assert (PyWeakref_Check (ref_obj ));
40
+ int is_dead ;
41
+ Py_BEGIN_CRITICAL_SECTION (ref_obj );
38
42
PyWeakReference * ref = _Py_CAST (PyWeakReference * , ref_obj );
39
43
PyObject * obj = ref -> wr_object ;
40
44
if (obj == Py_None ) {
41
45
// clear_weakref() was called
42
- return 1 ;
46
+ is_dead = 1 ;
43
47
}
44
-
45
- // See _PyWeakref_GET_REF() for the rationale of this test
46
- return (Py_REFCNT (obj ) == 0 );
48
+ else {
49
+ // See _PyWeakref_GET_REF() for the rationale of this test
50
+ is_dead = (Py_REFCNT (obj ) == 0 );
51
+ }
52
+ Py_END_CRITICAL_SECTION ();
53
+ return is_dead ;
47
54
}
48
55
49
56
extern Py_ssize_t _PyWeakref_GetWeakrefCount (PyWeakReference * head );
You can’t perform that action at this time.
0 commit comments