summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorFred Drake <fdrake@acm.org>2001-12-19 16:44:30 (GMT)
committerFred Drake <fdrake@acm.org>2001-12-19 16:44:30 (GMT)
commit2a908f6b7b4c1d8774374cb356cea369e3e072cf (patch)
treebd3b97652f64d89ae408fb04bb156295c21c3328 /Objects
parent694ed091af3b83b32ef161bd333c042a0ddacc88 (diff)
downloadcpython-2a908f6b7b4c1d8774374cb356cea369e3e072cf.zip
cpython-2a908f6b7b4c1d8774374cb356cea369e3e072cf.tar.gz
cpython-2a908f6b7b4c1d8774374cb356cea369e3e072cf.tar.bz2
proxy_compare(): Make sure that we unwrap both objects being compared if
both are proxy objects.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/weakrefobject.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/Objects/weakrefobject.c b/Objects/weakrefobject.c
index 9a94fd4..2e02cf2 100644
--- a/Objects/weakrefobject.c
+++ b/Objects/weakrefobject.c
@@ -220,6 +220,13 @@ proxy_checkref(PyWeakReference *proxy)
o = PyWeakref_GET_OBJECT(o); \
}
+#define UNWRAP_I(o) \
+ if (PyWeakref_CheckProxy(o)) { \
+ if (!proxy_checkref((PyWeakReference *)o)) \
+ return -1; \
+ o = PyWeakref_GET_OBJECT(o); \
+ }
+
#define WRAP_UNARY(method, generic) \
static PyObject * \
method(PyObject *proxy) { \
@@ -284,11 +291,11 @@ proxy_setattr(PyWeakReference *proxy, PyObject *name, PyObject *value)
}
static int
-proxy_compare(PyWeakReference *proxy, PyObject *v)
+proxy_compare(PyObject *proxy, PyObject *v)
{
- if (!proxy_checkref(proxy))
- return -1;
- return PyObject_Compare(PyWeakref_GET_OBJECT(proxy), v);
+ UNWRAP_I(proxy);
+ UNWRAP_I(v);
+ return PyObject_Compare(proxy, v);
}
/* number slots */
@@ -451,7 +458,7 @@ _PyWeakref_ProxyType = {
(printfunc)proxy_print, /*tp_print*/
0, /*tp_getattr*/
0, /*tp_setattr*/
- (cmpfunc)proxy_compare, /*tp_compare*/
+ proxy_compare, /*tp_compare*/
(unaryfunc)proxy_repr, /*tp_repr*/
&proxy_as_number, /*tp_as_number*/
&proxy_as_sequence, /*tp_as_sequence*/
@@ -482,7 +489,7 @@ _PyWeakref_CallableProxyType = {
(printfunc)proxy_print, /*tp_print*/
0, /*tp_getattr*/
0, /*tp_setattr*/
- (cmpfunc)proxy_compare, /*tp_compare*/
+ proxy_compare, /*tp_compare*/
(unaryfunc)proxy_repr, /*tp_repr*/
&proxy_as_number, /*tp_as_number*/
&proxy_as_sequence, /*tp_as_sequence*/