comparison Python/errors.c @ 14330:6dee1985c681 legacy-trunk

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.
author Jeremy Hylton <jeremy@alum.mit.edu>
date Fri, 01 Sep 2000 02:47:25 +0000
parents 019265b3a856
children 951eb3af3494
comparison
equal deleted inserted replaced
14329:b57e360a6d16 14330:6dee1985c681
448 Py_XDECREF(mydict); 448 Py_XDECREF(mydict);
449 Py_XDECREF(classname); 449 Py_XDECREF(classname);
450 Py_XDECREF(modulename); 450 Py_XDECREF(modulename);
451 return result; 451 return result;
452 } 452 }
453
454 /* Call when an exception has occurred but there is no way for Python
455 to handle it. Examples: exception in __del__ or during GC. */
456 void
457 PyErr_WriteUnraisable(PyObject *obj)
458 {
459 PyObject *f, *t, *v, *tb;
460 PyErr_Fetch(&t, &v, &tb);
461 f = PySys_GetObject("stderr");
462 if (f != NULL) {
463 PyFile_WriteString("Exception ", f);
464 if (t) {
465 PyFile_WriteObject(t, f, Py_PRINT_RAW);
466 if (v && v != Py_None) {
467 PyFile_WriteString(": ", f);
468 PyFile_WriteObject(v, f, 0);
469 }
470 }
471 PyFile_WriteString(" in ", f);
472 PyFile_WriteObject(obj, f, 0);
473 PyFile_WriteString(" ignored\n", f);
474 PyErr_Clear(); /* Just in case */
475 }
476 Py_XDECREF(t);
477 Py_XDECREF(v);
478 Py_XDECREF(tb);
479 }