Commit 53d76dcf authored by Tres Seaver's avatar Tres Seaver

* Fix acquisition wrapper comparisons (Collector #1650)

parent 4aedef26
...@@ -30,3 +30,10 @@ Zope changes ...@@ -30,3 +30,10 @@ Zope changes
return the right thing regardless of how the id of the return the right thing regardless of how the id of the
object is stored internally. object is stored internally.
Bugs Fixed
- (Collector #1650)Where the underlying object does not define
its own '__cmp__()', comparisons of acquisition-wrapped
objects fall back to comparing the identities *of the
wrappers* . Fixed to unrwap the object (both, if needed)
before comparing identities.
...@@ -33,7 +33,7 @@ ...@@ -33,7 +33,7 @@
USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE. DAMAGE.
$Id: Acquisition.c,v 1.43 2000/09/29 15:44:53 shane Exp $ $Id: Acquisition.c,v 1.44 2000/09/29 17:21:27 tseaver Exp $
If you have questions regarding this software, If you have questions regarding this software,
contact: contact:
...@@ -605,6 +605,7 @@ Wrapper_setattro(Wrapper *self, PyObject *oname, PyObject *v) ...@@ -605,6 +605,7 @@ Wrapper_setattro(Wrapper *self, PyObject *oname, PyObject *v)
static int static int
Wrapper_compare(Wrapper *self, PyObject *w) Wrapper_compare(Wrapper *self, PyObject *w)
{ {
PyObject *obj, *wobj;
PyObject *m; PyObject *m;
int r; int r;
...@@ -612,8 +613,22 @@ Wrapper_compare(Wrapper *self, PyObject *w) ...@@ -612,8 +613,22 @@ Wrapper_compare(Wrapper *self, PyObject *w)
UNLESS (m=PyObject_GetAttr(OBJECT(self), py__cmp__)) UNLESS (m=PyObject_GetAttr(OBJECT(self), py__cmp__))
{ {
/* Unwrap self completely -> obj. */
while (self->obj && isWrapper(self->obj))
self=WRAPPER(self->obj);
obj = self->obj;
/* Unwrap w completely -> wobj. */
if (isWrapper(w))
{
while (WRAPPER(w)->obj && isWrapper(WRAPPER(w)->obj))
w=WRAPPER(w)->obj;
wobj = WRAPPER(w)->obj;
}
else wobj = w;
PyErr_Clear(); PyErr_Clear();
return (OBJECT(self) < w) ? -1 : 1; if (obj == wobj) return 0;
return (obj < w) ? -1 : 1;
} }
ASSIGN(m, PyObject_CallFunction(m, "O", w)); ASSIGN(m, PyObject_CallFunction(m, "O", w));
...@@ -1401,7 +1416,7 @@ void ...@@ -1401,7 +1416,7 @@ void
initAcquisition() initAcquisition()
{ {
PyObject *m, *d; PyObject *m, *d;
char *rev="$Revision: 1.43 $"; char *rev="$Revision: 1.44 $";
PURE_MIXIN_CLASS(Acquirer, PURE_MIXIN_CLASS(Acquirer,
"Base class for objects that implicitly" "Base class for objects that implicitly"
" acquire attributes from containers\n" " acquire attributes from containers\n"
...@@ -1420,7 +1435,7 @@ initAcquisition() ...@@ -1420,7 +1435,7 @@ initAcquisition()
/* Create the module and add the functions */ /* Create the module and add the functions */
m = Py_InitModule4("Acquisition", methods, m = Py_InitModule4("Acquisition", methods,
"Provide base classes for acquiring objects\n\n" "Provide base classes for acquiring objects\n\n"
"$Id: Acquisition.c,v 1.43 2000/09/29 15:44:53 shane Exp $\n", "$Id: Acquisition.c,v 1.44 2000/09/29 17:21:27 tseaver Exp $\n",
OBJECT(NULL),PYTHON_API_VERSION); OBJECT(NULL),PYTHON_API_VERSION);
d = PyModule_GetDict(m); d = PyModule_GetDict(m);
......
...@@ -33,7 +33,7 @@ ...@@ -33,7 +33,7 @@
USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE. DAMAGE.
$Id: Acquisition.c,v 1.43 2000/09/29 15:44:53 shane Exp $ $Id: Acquisition.c,v 1.44 2000/09/29 17:21:27 tseaver Exp $
If you have questions regarding this software, If you have questions regarding this software,
contact: contact:
...@@ -605,6 +605,7 @@ Wrapper_setattro(Wrapper *self, PyObject *oname, PyObject *v) ...@@ -605,6 +605,7 @@ Wrapper_setattro(Wrapper *self, PyObject *oname, PyObject *v)
static int static int
Wrapper_compare(Wrapper *self, PyObject *w) Wrapper_compare(Wrapper *self, PyObject *w)
{ {
PyObject *obj, *wobj;
PyObject *m; PyObject *m;
int r; int r;
...@@ -612,8 +613,22 @@ Wrapper_compare(Wrapper *self, PyObject *w) ...@@ -612,8 +613,22 @@ Wrapper_compare(Wrapper *self, PyObject *w)
UNLESS (m=PyObject_GetAttr(OBJECT(self), py__cmp__)) UNLESS (m=PyObject_GetAttr(OBJECT(self), py__cmp__))
{ {
/* Unwrap self completely -> obj. */
while (self->obj && isWrapper(self->obj))
self=WRAPPER(self->obj);
obj = self->obj;
/* Unwrap w completely -> wobj. */
if (isWrapper(w))
{
while (WRAPPER(w)->obj && isWrapper(WRAPPER(w)->obj))
w=WRAPPER(w)->obj;
wobj = WRAPPER(w)->obj;
}
else wobj = w;
PyErr_Clear(); PyErr_Clear();
return (OBJECT(self) < w) ? -1 : 1; if (obj == wobj) return 0;
return (obj < w) ? -1 : 1;
} }
ASSIGN(m, PyObject_CallFunction(m, "O", w)); ASSIGN(m, PyObject_CallFunction(m, "O", w));
...@@ -1401,7 +1416,7 @@ void ...@@ -1401,7 +1416,7 @@ void
initAcquisition() initAcquisition()
{ {
PyObject *m, *d; PyObject *m, *d;
char *rev="$Revision: 1.43 $"; char *rev="$Revision: 1.44 $";
PURE_MIXIN_CLASS(Acquirer, PURE_MIXIN_CLASS(Acquirer,
"Base class for objects that implicitly" "Base class for objects that implicitly"
" acquire attributes from containers\n" " acquire attributes from containers\n"
...@@ -1420,7 +1435,7 @@ initAcquisition() ...@@ -1420,7 +1435,7 @@ initAcquisition()
/* Create the module and add the functions */ /* Create the module and add the functions */
m = Py_InitModule4("Acquisition", methods, m = Py_InitModule4("Acquisition", methods,
"Provide base classes for acquiring objects\n\n" "Provide base classes for acquiring objects\n\n"
"$Id: Acquisition.c,v 1.43 2000/09/29 15:44:53 shane Exp $\n", "$Id: Acquisition.c,v 1.44 2000/09/29 17:21:27 tseaver Exp $\n",
OBJECT(NULL),PYTHON_API_VERSION); OBJECT(NULL),PYTHON_API_VERSION);
d = PyModule_GetDict(m); d = PyModule_GetDict(m);
......
...@@ -17,3 +17,15 @@ try: ...@@ -17,3 +17,15 @@ try:
raise 'Program error', 'spam' raise 'Program error', 'spam'
except AttributeError: pass except AttributeError: pass
#
# New test for wrapper comparisons.
#
foo = b.a
bar = b.a
assert( foo == bar )
c = A()
b.c = c
b.c.d = c
assert( b.c.d == c )
assert( b.c.d == b.c )
assert( b.c == c )
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment