mirror of
https://github.com/python/cpython.git
synced 2025-10-28 17:13:08 +00:00
gh-105927: Add _PyWeakref_IS_DEAD() function (#105992)
* Add _PyWeakref_IS_DEAD() internal function. * Modify is_dead_weakref() of Modules/_weakref.c and _pysqlite_drop_unused_cursor_references() to replace PyWeakref_GET_OBJECT() with _PyWeakref_IS_DEAD(). * Replace "int i" with "Py_ssize_t i" to iterate on cursors in _pysqlite_drop_unused_cursor_references().
This commit is contained in:
parent
d8f87cdf94
commit
c38da1e3e1
3 changed files with 30 additions and 14 deletions
|
|
@ -33,6 +33,19 @@ static inline PyObject* _PyWeakref_GET_REF(PyObject *ref_obj) {
|
|||
return Py_NewRef(obj);
|
||||
}
|
||||
|
||||
static inline int _PyWeakref_IS_DEAD(PyObject *ref_obj) {
|
||||
assert(PyWeakref_Check(ref_obj));
|
||||
PyWeakReference *ref = _Py_CAST(PyWeakReference*, ref_obj);
|
||||
PyObject *obj = ref->wr_object;
|
||||
if (obj == Py_None) {
|
||||
// clear_weakref() was called
|
||||
return 1;
|
||||
}
|
||||
|
||||
// See _PyWeakref_GET_REF() for the rationale of this test
|
||||
return (Py_REFCNT(obj) == 0);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue