Mercurial > cpython-lru_cache-weakref
comparison Python/errors.c @ 48474:2ee09afee126
implement chained exception tracebacks
patch from Antoine Pitrou #3112
| author | Benjamin Peterson <benjamin@python.org> |
|---|---|
| date | Tue, 15 Jul 2008 15:32:09 +0000 |
| parents | 7ba7901dad7f |
| children | 1ec38b707cd6 |
comparison
equal
deleted
inserted
replaced
| 48473:7d570df5e90a | 48474:2ee09afee126 |
|---|---|
| 82 Py_XDECREF(value); | 82 Py_XDECREF(value); |
| 83 if (fixed_value == NULL) | 83 if (fixed_value == NULL) |
| 84 return; | 84 return; |
| 85 value = fixed_value; | 85 value = fixed_value; |
| 86 } | 86 } |
| 87 Py_INCREF(tstate->exc_value); | 87 /* Avoid reference cycles through the context chain. |
| 88 PyException_SetContext(value, tstate->exc_value); | 88 This is O(chain length) but context chains are |
| 89 usually very short. Sensitive readers may try | |
| 90 to inline the call to PyException_GetContext. */ | |
| 91 if (tstate->exc_value != value) { | |
| 92 PyObject *o = tstate->exc_value, *context; | |
| 93 while ((context = PyException_GetContext(o))) { | |
| 94 Py_DECREF(context); | |
| 95 if (context == value) { | |
| 96 PyException_SetContext(o, NULL); | |
| 97 break; | |
| 98 } | |
| 99 o = context; | |
| 100 } | |
| 101 Py_INCREF(tstate->exc_value); | |
| 102 PyException_SetContext(value, tstate->exc_value); | |
| 103 } | |
| 89 } | 104 } |
| 90 if (value != NULL && PyExceptionInstance_Check(value)) | 105 if (value != NULL && PyExceptionInstance_Check(value)) |
| 91 tb = PyException_GetTraceback(value); | 106 tb = PyException_GetTraceback(value); |
| 92 Py_XINCREF(exception); | 107 Py_XINCREF(exception); |
| 93 PyErr_Restore(exception, value, tb); | 108 PyErr_Restore(exception, value, tb); |
| 158 } | 173 } |
| 159 | 174 |
| 160 | 175 |
| 161 /* Used in many places to normalize a raised exception, including in | 176 /* Used in many places to normalize a raised exception, including in |
| 162 eval_code2(), do_raise(), and PyErr_Print() | 177 eval_code2(), do_raise(), and PyErr_Print() |
| 178 | |
| 179 XXX: should PyErr_NormalizeException() also call | |
| 180 PyException_SetTraceback() with the resulting value and tb? | |
| 163 */ | 181 */ |
| 164 void | 182 void |
| 165 PyErr_NormalizeException(PyObject **exc, PyObject **val, PyObject **tb) | 183 PyErr_NormalizeException(PyObject **exc, PyObject **val, PyObject **tb) |
| 166 { | 184 { |
| 167 PyObject *type = *exc; | 185 PyObject *type = *exc; |
