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

Shane Hathaway shane at zope.com
Tue Jun 10 12:28:46 EDT 2003


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

Modified Files:
	Acquisition.c 
Log Message:
Fixed a potential Python 2.2+ bug and tidied the code slightly.

In Python 2.2 and above, getattr operations distinguish
AttributeErrors from other kinds of operations.  But Wrapper_acquire
was masking some errors as AttributeErrors.  Fixed.

Added a comment explaining apply_filter, added curly brackets to
disambiguate nesting in Wrapper_acquire, and re-indented to clarify.



=== Zope/lib/Components/ExtensionClass/src/Acquisition.c 1.60 => 1.61 ===
--- Zope/lib/Components/ExtensionClass/src/Acquisition.c:1.60	Wed Nov 13 12:45:53 2002
+++ Zope/lib/Components/ExtensionClass/src/Acquisition.c	Tue Jun 10 11:28:46 2003
@@ -346,6 +346,16 @@
 apply_filter(PyObject *filter, PyObject *inst, PyObject *oname, PyObject *r,
 	     PyObject *extra, PyObject *orig)
 {
+  /* Calls the filter, passing arguments.
+
+  Returns 1 if the filter accepts the value, 0 if not, -1 if an
+  exception occurred.
+
+  Note the special reference counting rule: This function decrements
+  the refcount of 'r' when it returns 0 or -1.  When it returns 1, it
+  leaves the refcount unchanged.
+  */
+
   PyObject *fr;
   int ir;
 
@@ -518,12 +528,11 @@
       else
 	{
 	  if ((r=PyObject_GetAttr(self->container,oname))) {
-	    if (r == Acquired)
-	      {
-		Py_DECREF(r);
-	      }
+	    if (r == Acquired) {
+	      Py_DECREF(r);
+	    }
 	    else {
-	      if (filter)
+	      if (filter) {
 		switch(apply_filter(filter,self->container,oname,r,
 				    extra,orig))
 		  {
@@ -533,12 +542,16 @@
 		    if (has__of__(r)) ASSIGN(r,__of__(r,OBJECT(self)));
 		    return r;
 		  }
-	      else 
-		{
-		  if (has__of__(r)) ASSIGN(r,__of__(r,OBJECT(self)));
-		  return r;
-		}
+	      }
+	      else {
+		if (has__of__(r)) ASSIGN(r,__of__(r,OBJECT(self)));
+		return r;
+	      }
 	    }
+	  }
+	  else {
+	    /* May be AttributeError or some other kind of error */
+	    return NULL;
 	  }
 	}
     }




More information about the Zodb-checkins mailing list