diff options
author | Victor Stinner <vstinner@python.org> | 2023-06-21 13:44:25 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-21 13:44:25 (GMT) |
commit | fb1e691e4bc7757c11bf9e51dda675f15537db8c (patch) | |
tree | 6bc8c40a35e6ccbc6c0f97f628a771b8df73f97a /Modules/_abc.c | |
parent | eaa670228066220f08c8d73f80365c50058d40b8 (diff) | |
download | cpython-fb1e691e4bc7757c11bf9e51dda675f15537db8c.zip cpython-fb1e691e4bc7757c11bf9e51dda675f15537db8c.tar.gz cpython-fb1e691e4bc7757c11bf9e51dda675f15537db8c.tar.bz2 |
gh-105927: _abc and _thread use PyWeakref_GetRef() (#105961)
Hold a strong reference on the object, rather than using a borrowed reference:
replace PyWeakref_GET_OBJECT() with PyWeakref_GetRef() and
_PyWeakref_GET_REF().
Remove assert(PyWeakref_CheckRef(localweakref)) since it's already
tested by _PyWeakref_GET_REF().
Diffstat (limited to 'Modules/_abc.c')
-rw-r--r-- | Modules/_abc.c | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/Modules/_abc.c b/Modules/_abc.c index d3e405d..93c0a93 100644 --- a/Modules/_abc.c +++ b/Modules/_abc.c @@ -8,6 +8,7 @@ #include "pycore_object.h" // _PyType_GetSubclasses() #include "pycore_runtime.h" // _Py_ID() #include "pycore_typeobject.h" // _PyType_GetMRO() +#include "pycore_weakref.h" // _PyWeakref_GET_REF() #include "clinic/_abc.c.h" /*[clinic input] @@ -150,12 +151,10 @@ _in_weak_set(PyObject *set, PyObject *obj) static PyObject * _destroy(PyObject *setweakref, PyObject *objweakref) { - PyObject *set; - set = PyWeakref_GET_OBJECT(setweakref); - if (set == Py_None) { + PyObject *set = _PyWeakref_GET_REF(setweakref); + if (set == NULL) { Py_RETURN_NONE; } - Py_INCREF(set); if (PySet_Discard(set, objweakref) < 0) { Py_DECREF(set); return NULL; @@ -843,16 +842,16 @@ subclasscheck_check_registry(_abc_data *impl, PyObject *subclass, assert(i == registry_size); for (i = 0; i < registry_size; i++) { - PyObject *rkey = PyWeakref_GetObject(copy[i]); - if (rkey == NULL) { + PyObject *rkey; + if (PyWeakref_GetRef(copy[i], &rkey) < 0) { // Someone inject non-weakref type in the registry. ret = -1; break; } - if (rkey == Py_None) { + + if (rkey == NULL) { continue; } - Py_INCREF(rkey); int r = PyObject_IsSubclass(subclass, rkey); Py_DECREF(rkey); if (r < 0) { |