[Zodb-checkins] CVS: Zope/lib/Components/ExtensionClass/src - Acquisition.c:1.53

Shane Hathaway shane@digicool.com
Fri, 14 Sep 2001 16:00:14 -0400


Update of /cvs-repository/Zope/lib/Components/ExtensionClass/src
In directory cvs.zope.org:/tmp/cvs-serv32296/src

Modified Files:
	Acquisition.c 
Log Message:
Corrected aq_inContextOf().   The former code returned the incorrect result
if the context object was the root of the hierarchy, a condition which
normally does not occur in Zope, but can occur in scripts.


=== Zope/lib/Components/ExtensionClass/src/Acquisition.c 1.52 => 1.53 ===
 Wrapper_inContextOf(Wrapper *self, PyObject *args)
 {
-  PyObject *o, *c;
+  PyObject *subob, *o, *c;
   int inner=1;
 
   UNLESS(PyArg_ParseTuple(args,"O|i",&o,&inner)) return NULL;
 
   if (inner) {
+    /* subob = self */
+    subob = OBJECT(self);
+
     /* o = aq_base(o) */
     while (isWrapper(o) && WRAPPER(o)->obj) o=WRAPPER(o)->obj;
 
     /* while 1: */
     while (1) {
 
-      /*   if aq_base(self) is o: return 1 */
-      c = self->obj;
+      /*   if aq_base(subob) is o: return 1 */
+      c = subob;
       while (isWrapper(c) && WRAPPER(c)->obj) c = WRAPPER(c)->obj;
       if (c == o) return PyInt_FromLong(1);
 
-      /*   self = aq_parent(aq_inner(self)) */
+      /*   self = aq_inner(subob) */
       /*   if self is None: break */
-      while (self->obj && isWrapper(self->obj)) self = WRAPPER(self->obj);
-      if (self->container && isWrapper(self->container))
-        self = WRAPPER(self->container);
+      if (isWrapper(subob)) {
+        self = WRAPPER(subob);
+        while (self->obj && isWrapper(self->obj))
+          self = WRAPPER(self->obj);
+      }
+      else break;
+
+      /*   subob = aq_parent(self) */
+      /*   if subob is None: break */
+      if (self->container)
+        subob = self->container;
       else break;
     }
   }