Mercurial > cpython-lru_cache-weakref
comparison Python/errors.c @ 84704:48a869a39e2d
Issue #18408: PyEval_EvalFrameEx() and PyEval_CallObjectWithKeywords() now fail
with an assertion error if they are called with an exception set
(PyErr_Occurred()).
If these functions are called with an exception set, the exception may be
cleared and so the caller looses its exception.
Add also assertions to PyEval_CallObjectWithKeywords() and call_function() to
check if the function succeed with no exception set, or the function failed
with an exception set.
| author | Victor Stinner <victor.stinner@gmail.com> |
|---|---|
| date | Thu, 18 Jul 2013 01:41:08 +0200 |
| parents | 573f7d485ce8 |
| children | 9b77b3ee6fb8 |
comparison
equal
deleted
inserted
replaced
| 84703:a2214ab0812e | 84704:48a869a39e2d |
|---|---|
| 69 /* Implicit exception chaining */ | 69 /* Implicit exception chaining */ |
| 70 Py_INCREF(exc_value); | 70 Py_INCREF(exc_value); |
| 71 if (value == NULL || !PyExceptionInstance_Check(value)) { | 71 if (value == NULL || !PyExceptionInstance_Check(value)) { |
| 72 /* We must normalize the value right now */ | 72 /* We must normalize the value right now */ |
| 73 PyObject *args, *fixed_value; | 73 PyObject *args, *fixed_value; |
| 74 #ifdef Py_DEBUG | |
| 75 /* in debug mode, PyEval_EvalFrameEx() fails with an assertion | |
| 76 error if an exception is set when it is called */ | |
| 77 PyErr_Clear(); | |
| 78 #endif | |
| 74 if (value == NULL || value == Py_None) | 79 if (value == NULL || value == Py_None) |
| 75 args = PyTuple_New(0); | 80 args = PyTuple_New(0); |
| 76 else if (PyTuple_Check(value)) { | 81 else if (PyTuple_Check(value)) { |
| 77 Py_INCREF(value); | 82 Py_INCREF(value); |
| 78 args = value; | 83 args = value; |
| 705 va_start(vargs, format); | 710 va_start(vargs, format); |
| 706 #else | 711 #else |
| 707 va_start(vargs); | 712 va_start(vargs); |
| 708 #endif | 713 #endif |
| 709 | 714 |
| 715 #ifdef Py_DEBUG | |
| 716 /* in debug mode, PyEval_EvalFrameEx() fails with an assertion error | |
| 717 if an exception is set when it is called */ | |
| 718 PyErr_Clear(); | |
| 719 #endif | |
| 720 | |
| 710 string = PyUnicode_FromFormatV(format, vargs); | 721 string = PyUnicode_FromFormatV(format, vargs); |
| 711 PyErr_SetObject(exception, string); | 722 PyErr_SetObject(exception, string); |
| 712 Py_XDECREF(string); | 723 Py_XDECREF(string); |
| 713 va_end(vargs); | 724 va_end(vargs); |
| 714 return NULL; | 725 return NULL; |
