summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2012-11-11 18:37:41 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2012-11-11 18:37:41 (GMT)
commitf6a50cfa077ced55d39279dd908289a6f39f9f19 (patch)
treefa848b04ea37a44efa18cc0d2f901d0c51a2b7dd /Objects
parent6ff262e18f7178b22b3cc6300d05a8cb008865d2 (diff)
parente11fecb5a97595a91506eeba8fd5a185d35ace9e (diff)
downloadcpython-f6a50cfa077ced55d39279dd908289a6f39f9f19.zip
cpython-f6a50cfa077ced55d39279dd908289a6f39f9f19.tar.gz
cpython-f6a50cfa077ced55d39279dd908289a6f39f9f19.tar.bz2
Issue #16453: Fix equality testing of dead weakref objects.
Also add tests for ordering and hashing.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/weakrefobject.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/Objects/weakrefobject.c b/Objects/weakrefobject.c
index e07adb2..d3a4dd5 100644
--- a/Objects/weakrefobject.c
+++ b/Objects/weakrefobject.c
@@ -198,9 +198,13 @@ weakref_richcompare(PyWeakReference* self, PyWeakReference* other, int op)
}
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);