[Python-checkins] CVS: python/dist/src/Python errors.c,2.53,2.54

Jeremy Hylton python-dev@python.org
Thu, 31 Aug 2000 19:47:27 -0700


Update of /cvsroot/python/python/dist/src/Python
In directory slayer.i.sourceforge.net:/tmp/cvs-serv2009/Python

Modified Files:
	errors.c 
Log Message:
refactor __del__ exception handler into PyErr_WriteUnraisable
add sanity check to gc: if an exception occurs during GC, call
PyErr_WriteUnraisable and then call Py_FatalEror. 


Index: errors.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/errors.c,v
retrieving revision 2.53
retrieving revision 2.54
diff -C2 -r2.53 -r2.54
*** errors.c	2000/08/24 22:38:39	2.53
--- errors.c	2000/09/01 02:47:24	2.54
***************
*** 451,452 ****
--- 451,479 ----
  	return result;
  }
+ 
+ /* Call when an exception has occurred but there is no way for Python
+    to handle it.  Examples: exception in __del__ or during GC. */
+ void
+ PyErr_WriteUnraisable(PyObject *obj)
+ {
+ 	PyObject *f, *t, *v, *tb;
+ 	PyErr_Fetch(&t, &v, &tb);
+ 	f = PySys_GetObject("stderr");
+ 	if (f != NULL) {
+ 		PyFile_WriteString("Exception ", f);
+ 		if (t) {
+ 			PyFile_WriteObject(t, f, Py_PRINT_RAW);
+ 			if (v && v != Py_None) {
+ 				PyFile_WriteString(": ", f);
+ 				PyFile_WriteObject(v, f, 0);
+ 			}
+ 		}
+ 		PyFile_WriteString(" in ", f);
+ 		PyFile_WriteObject(obj, f, 0);
+ 		PyFile_WriteString(" ignored\n", f);
+ 		PyErr_Clear(); /* Just in case */
+ 	}
+ 	Py_XDECREF(t);
+ 	Py_XDECREF(v);
+ 	Py_XDECREF(tb);
+ }