diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2012-11-11 19:36:51 +0100 |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2012-11-11 19:36:51 +0100 |
commit | b704eab5993649f634e8367feb314dfacc95c6e3 (patch) | |
tree | b56925eac86d40fd6a6c27b526ff3c8d0c79f3dd /Objects/weakrefobject.c | |
parent | 027d6fcebd165ff9589b20f6a23acc8c054be6d0 (diff) | |
download | cpython-git-b704eab5993649f634e8367feb314dfacc95c6e3.tar.gz |
Issue #16453: Fix equality testing of dead weakref objects.
Also add tests for hashing.
Diffstat (limited to 'Objects/weakrefobject.c')
-rw-r--r-- | Objects/weakrefobject.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/Objects/weakrefobject.c b/Objects/weakrefobject.c index 0e46d92577..7b943b0f00 100644 --- a/Objects/weakrefobject.c +++ b/Objects/weakrefobject.c @@ -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); |