summaryrefslogtreecommitdiffstats
path: root/Python/errors.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 /Python/errors.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 'Python/errors.c')
-rw-r--r--Python/errors.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/Python/errors.c b/Python/errors.c
index 8486423..355ec9c 100644
--- a/Python/errors.c
+++ b/Python/errors.c
@@ -450,3 +450,30 @@ PyErr_NewException(char *name, PyObject *base, PyObject *dict)
Py_XDECREF(modulename);
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);
+}