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" {
88# error "this header requires Py_BUILD_CORE define"
99#endif
1010
11+ #include "pycore_critical_section.h" // Py_BEGIN_CRITICAL_SECTION()
12+
1113static inline PyObject * _PyWeakref_GET_REF (PyObject * ref_obj ) {
1214 assert (PyWeakref_Check (ref_obj ));
1315 PyWeakReference * ref = _Py_CAST (PyWeakReference * , ref_obj );
@@ -35,15 +37,20 @@ static inline PyObject* _PyWeakref_GET_REF(PyObject *ref_obj) {
3537
3638static inline int _PyWeakref_IS_DEAD (PyObject * ref_obj ) {
3739 assert (PyWeakref_Check (ref_obj ));
40+ int is_dead ;
41+ Py_BEGIN_CRITICAL_SECTION (ref_obj );
3842 PyWeakReference * ref = _Py_CAST (PyWeakReference * , ref_obj );
3943 PyObject * obj = ref -> wr_object ;
4044 if (obj == Py_None ) {
4145 // clear_weakref() was called
42- return 1 ;
46+ is_dead = 1 ;
4347 }
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 ;
4754}
4855
4956extern Py_ssize_t _PyWeakref_GetWeakrefCount (PyWeakReference * head );
You can’t perform that action at this time.
0 commit comments