[Zodb-checkins] CVS: Zope/lib/python/ZODB - cPersistence.c:1.62

Jeremy Hylton jeremy@zope.com
Tue, 18 Jun 2002 17:37:56 -0400


Update of /cvs-repository/Zope/lib/python/ZODB
In directory cvs.zope.org:/tmp/cvs-serv26939

Modified Files:
	cPersistence.c 
Log Message:
Don't silently ignore exceptions in _p_deactivate().



=== Zope/lib/python/ZODB/cPersistence.c 1.61 => 1.62 ===
       }
       else if (strcmp(name+3, "changed") == 0) {
+	  int deactivate = 0;
 	  if (!v)
 	    {
 	      /* delatter is used to invalidate the object
@@ -631,13 +632,37 @@
 	       */
 	      if (self->state != cPersistent_GHOST_STATE)
 		self->state = cPersistent_UPTODATE_STATE;
-	      v=Py_None;
+	      deactivate = 1;
 	    }
-	  if (v==Py_None)
+	  else if (v == Py_None)
+	      deactivate = 1;
+	  if (deactivate)
 	    {
-	      v=PyObject_GetAttr(OBJECT(self), py__p_deactivate);
-	      if (v) { ASSIGN(v, PyObject_CallObject(v, NULL)); }
-	      if (v) { Py_DECREF(v); }
+	      PyObject *res;
+	      PyObject *meth = PyObject_GetAttr(OBJECT(self), 
+						py__p_deactivate);
+	      if (meth == NULL)
+		  return -1;
+	      res = PyObject_CallObject(meth, NULL);
+	      if (res) {
+		  Py_DECREF(res);
+	      } 
+	      else {
+		  /* an error occured in _p_deactivate().  
+
+		  It's not clear what we should do here.  The code is
+		  obviously ignoring the exception, but it shouldn't
+		  return 0 for a getattr and set an exception.  The
+		  simplest change is to clear the exception, but that
+		  simply masks the error. 
+
+		  XXX We'll print an error to stderr just like
+		  exceptions in __del__().  It would probably be
+		  better to log it but that would be painful from C.
+		  */
+		  PyErr_WriteUnraisable(meth);
+	      }
+	      Py_DECREF(meth);
 	      return 0;
 	    }
 	  if (PyObject_IsTrue(v)) return changed(self);