summaryrefslogtreecommitdiffstats
path: root/Modules/gcmodule.c
diff options
context:
space:
mode:
authorJeremy Hylton <jeremy@alum.mit.edu>2000-09-01 02:47:25 (GMT)
committerJeremy Hylton <jeremy@alum.mit.edu>2000-09-01 02:47:25 (GMT)
commitb709df381034b6055f03644a8f2eb35cfc6cb411 (patch)
tree55a6c86396fefc64a68fef9a8621500c868320c4 /Modules/gcmodule.c
parentb9ce5ada37f271cd2e9ec67f86a82a166f1e1296 (diff)
downloadcpython-b709df381034b6055f03644a8f2eb35cfc6cb411.zip
cpython-b709df381034b6055f03644a8f2eb35cfc6cb411.tar.gz
cpython-b709df381034b6055f03644a8f2eb35cfc6cb411.tar.bz2
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.
Diffstat (limited to 'Modules/gcmodule.c')
-rw-r--r--Modules/gcmodule.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/Modules/gcmodule.c b/Modules/gcmodule.c
index 57ee7b9..889ae25 100644
--- a/Modules/gcmodule.c
+++ b/Modules/gcmodule.c
@@ -57,11 +57,13 @@ static int allocated;
DEBUG_UNCOLLECTABLE | \
DEBUG_INSTANCES | \
DEBUG_OBJECTS
-static int debug = 0;
+static int debug;
/* list of uncollectable objects */
static PyObject *garbage;
+/* Python string to use if unhandled exception occurs */
+static PyObject *gc_str;
/*** list functions ***/
@@ -435,6 +437,10 @@ collect(PyGC_Head *young, PyGC_Head *old)
* this if they insist on creating this type of structure. */
handle_finalizers(&finalizers, old);
+ if (PyErr_Occurred()) {
+ PyErr_WriteUnraisable(gc_str);
+ Py_FatalError("unexpected exception during garbage collection");
+ }
allocated = 0;
return n+m;
}
@@ -699,6 +705,9 @@ initgc(void)
if (garbage == NULL) {
garbage = PyList_New(0);
}
+ if (gc_str == NULL) {
+ gc_str = PyString_FromString("garbage collection");
+ }
PyDict_SetItemString(d, "garbage", garbage);
PyDict_SetItemString(d, "DEBUG_STATS",
PyInt_FromLong(DEBUG_STATS));