mirror of
https://github.com/python/cpython.git
synced 2025-10-03 21:55:41 +00:00
Issue #16453: Fix equality testing of dead weakref objects.
Also add tests for hashing.
This commit is contained in:
parent
027d6fcebd
commit
b704eab599
3 changed files with 79 additions and 15 deletions
|
@ -187,15 +187,19 @@ weakref_repr(PyWeakReference *self)
|
|||
static PyObject *
|
||||
weakref_richcompare(PyWeakReference* self, PyWeakReference* other, int op)
|
||||
{
|
||||
if (op != Py_EQ || self->ob_type != other->ob_type) {
|
||||
if ((op != Py_EQ && op != Py_NE) || self->ob_type != other->ob_type) {
|
||||
Py_INCREF(Py_NotImplemented);
|
||||
return Py_NotImplemented;
|
||||
}
|
||||
if (PyWeakref_GET_OBJECT(self) == Py_None
|
||||
|| PyWeakref_GET_OBJECT(other) == Py_None) {
|
||||
PyObject *res = self==other ? Py_True : Py_False;
|
||||
Py_INCREF(res);
|
||||
return res;
|
||||
int res = (self == other);
|
||||
if (op == Py_NE)
|
||||
res = !res;
|
||||
if (res)
|
||||
Py_RETURN_TRUE;
|
||||
else
|
||||
Py_RETURN_FALSE;
|
||||
}
|
||||
return PyObject_RichCompare(PyWeakref_GET_OBJECT(self),
|
||||
PyWeakref_GET_OBJECT(other), op);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue