Skip to content

Commit 40e27fa

Browse files
author
fdrake
committed
proxy_compare(): Make sure that we unwrap both objects being compared if
both are proxy objects. git-svn-id: http://svn.python.org/projects/python/trunk@24819 6015fed2-1504-0410-9fe1-9d1591cc4771
1 parent 56d676d commit 40e27fa

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

Objects/weakrefobject.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,13 @@ proxy_checkref(PyWeakReference *proxy)
220220
o = PyWeakref_GET_OBJECT(o); \
221221
}
222222

223+
#define UNWRAP_I(o) \
224+
if (PyWeakref_CheckProxy(o)) { \
225+
if (!proxy_checkref((PyWeakReference *)o)) \
226+
return -1; \
227+
o = PyWeakref_GET_OBJECT(o); \
228+
}
229+
223230
#define WRAP_UNARY(method, generic) \
224231
static PyObject * \
225232
method(PyObject *proxy) { \
@@ -284,11 +291,11 @@ proxy_setattr(PyWeakReference *proxy, PyObject *name, PyObject *value)
284291
}
285292

286293
static int
287-
proxy_compare(PyWeakReference *proxy, PyObject *v)
294+
proxy_compare(PyObject *proxy, PyObject *v)
288295
{
289-
if (!proxy_checkref(proxy))
290-
return -1;
291-
return PyObject_Compare(PyWeakref_GET_OBJECT(proxy), v);
296+
UNWRAP_I(proxy);
297+
UNWRAP_I(v);
298+
return PyObject_Compare(proxy, v);
292299
}
293300

294301
/* number slots */
@@ -451,7 +458,7 @@ _PyWeakref_ProxyType = {
451458
(printfunc)proxy_print, /*tp_print*/
452459
0, /*tp_getattr*/
453460
0, /*tp_setattr*/
454-
(cmpfunc)proxy_compare, /*tp_compare*/
461+
proxy_compare, /*tp_compare*/
455462
(unaryfunc)proxy_repr, /*tp_repr*/
456463
&proxy_as_number, /*tp_as_number*/
457464
&proxy_as_sequence, /*tp_as_sequence*/
@@ -482,7 +489,7 @@ _PyWeakref_CallableProxyType = {
482489
(printfunc)proxy_print, /*tp_print*/
483490
0, /*tp_getattr*/
484491
0, /*tp_setattr*/
485-
(cmpfunc)proxy_compare, /*tp_compare*/
492+
proxy_compare, /*tp_compare*/
486493
(unaryfunc)proxy_repr, /*tp_repr*/
487494
&proxy_as_number, /*tp_as_number*/
488495
&proxy_as_sequence, /*tp_as_sequence*/

0 commit comments

Comments
 (0)