From e11fecb5a97595a91506eeba8fd5a185d35ace9e Mon Sep 17 00:00:00 2001 From: Antoine Pitrou Date: Sun, 11 Nov 2012 19:36:51 +0100 Subject: Issue #16453: Fix equality testing of dead weakref objects. Also add tests for ordering and hashing. --- Objects/weakrefobject.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'Objects/weakrefobject.c') diff --git a/Objects/weakrefobject.c b/Objects/weakrefobject.c index 13323cfbcf..dae3c24f4a 100644 --- a/Objects/weakrefobject.c +++ b/Objects/weakrefobject.c @@ -195,9 +195,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); -- cgit v1.2.1