[Zope-dev] more on the segfault saga

Matthew T. Kromer matt@zope.com
Thu, 14 Mar 2002 17:10:28 -0500


This is a multi-part message in MIME format.
--------------000200010905010001010300
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit

Attached is another diagnostic patch which you might apply to Python. 
 If you apply this patch, you WILL need to rebuild Zope to include it.

What it will do is complain to stderr if an object is INCREF'd from 
refcount 0.  It also silences the complaint for the one area which I 
know revives dead objects.

This patch will probably cause a crash after an erroneous incref-from-0 
is detected, since it doesnt actually DO the incref in that case.

The intent is to find a case in the code where an object is held between 
threads; one thread decrefs to zero, the other thread increfs, causing a 
revive -- but too late to save the patient.

-- 
Matt Kromer
Zope Corporation  http://www.zope.com/ 



--------------000200010905010001010300
Content-Type: text/plain;
 name="incref.patch.1"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="incref.patch.1"

--- Include/object.h.orig	Thu Mar 14 16:44:36 2002
+++ Include/object.h	Thu Mar 14 16:54:29 2002
@@ -442,7 +442,7 @@
 #define _Py_NewReference(op) ((op)->ob_refcnt = 1)
 #endif
 
-#define Py_INCREF(op) ((op)->ob_refcnt++)
+#define Py_INCREF(op) ((op)->ob_refcnt > 0 ? (op)->ob_refcnt++ : fprintf(stderr,"Eeek! Increfing an object from refct 0 at %s:%d\n",__FILE__,__LINE__) )
 #define Py_DECREF(op) \
 	if (--(op)->ob_refcnt != 0) \
 		; \
--- Objects/classobject.c.orig	Thu Mar 14 17:04:40 2002
+++ Objects/classobject.c	Thu Mar 14 17:01:36 2002
@@ -535,7 +535,8 @@
 #endif
 #else /* !Py_TRACE_REFS */
 	/* Py_INCREF boosts _Py_RefTotal if Py_REF_DEBUG is defined */
-	Py_INCREF(inst);
+	/* Py_INCREF(inst); */
+	inst->ob_refcnt++;	/* we dont want to trap this one */
 #endif /* !Py_TRACE_REFS */
 
 	/* Save the current exception, if any. */

--------------000200010905010001010300--