mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
gh-133644: remove PyWeakref_GetObject and PyWeakref_GET_OBJECT (GH-133657)
This commit is contained in:
parent
30f849250b
commit
a5e0562350
16 changed files with 24 additions and 73 deletions
|
|
@ -47,20 +47,3 @@ PyAPI_FUNC(void) _PyWeakref_ClearRef(PyWeakReference *self);
|
|||
|
||||
// Test if a weak reference is dead.
|
||||
PyAPI_FUNC(int) PyWeakref_IsDead(PyObject *ref);
|
||||
|
||||
Py_DEPRECATED(3.13) static inline PyObject* PyWeakref_GET_OBJECT(PyObject *ref_obj)
|
||||
{
|
||||
PyWeakReference *ref = _PyWeakref_CAST(ref_obj);
|
||||
PyObject *obj = ref->wr_object;
|
||||
// Explanation for the Py_REFCNT() check: when a weakref's target is part
|
||||
// of a long chain of deallocations which triggers the trashcan mechanism,
|
||||
// clearing the weakrefs can be delayed long after the target's refcount
|
||||
// has dropped to zero. In the meantime, code accessing the weakref will
|
||||
// be able to "see" the target object even though it is supposed to be
|
||||
// unreachable. See issue gh-60806.
|
||||
if (Py_REFCNT(obj) > 0) {
|
||||
return obj;
|
||||
}
|
||||
return Py_None;
|
||||
}
|
||||
#define PyWeakref_GET_OBJECT(ref) PyWeakref_GET_OBJECT(_PyObject_CAST(ref))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue