From dbf5294cd5f6a2360be77f4c5ed964b7f146d04f Mon Sep 17 00:00:00 2001 From: Antoine Pitrou Date: Tue, 30 Sep 2014 21:16:27 +0200 Subject: Issue #18711: Add a new `PyErr_FormatV` function, similar to `PyErr_Format` but accepting a `va_list` argument. --- Python/errors.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) (limited to 'Python/errors.c') diff --git a/Python/errors.c b/Python/errors.c index 996292a044..fd55142525 100644 --- a/Python/errors.c +++ b/Python/errors.c @@ -749,19 +749,11 @@ PyErr_BadInternalCall(void) #define PyErr_BadInternalCall() _PyErr_BadInternalCall(__FILE__, __LINE__) - PyObject * -PyErr_Format(PyObject *exception, const char *format, ...) +PyErr_FormatV(PyObject *exception, const char *format, va_list vargs) { - va_list vargs; PyObject* string; -#ifdef HAVE_STDARG_PROTOTYPES - va_start(vargs, format); -#else - va_start(vargs); -#endif - #ifdef Py_DEBUG /* in debug mode, PyEval_EvalFrameEx() fails with an assertion error if an exception is set when it is called */ @@ -771,11 +763,24 @@ PyErr_Format(PyObject *exception, const char *format, ...) string = PyUnicode_FromFormatV(format, vargs); PyErr_SetObject(exception, string); Py_XDECREF(string); - va_end(vargs); return NULL; } +PyObject * +PyErr_Format(PyObject *exception, const char *format, ...) +{ + va_list vargs; +#ifdef HAVE_STDARG_PROTOTYPES + va_start(vargs, format); +#else + va_start(vargs); +#endif + PyErr_FormatV(exception, format, vargs); + va_end(vargs); + return NULL; +} + PyObject * PyErr_NewException(const char *name, PyObject *base, PyObject *dict) -- cgit v1.2.1 From b76e79ce344cf60aeeff69c4ca5c96302890ea3c Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 18 Mar 2015 01:39:23 +0100 Subject: Issue #23694: Enhance _Py_fopen(), it now raises an exception on error * If fopen() fails, OSError is raised with the original filename object. * The GIL is now released while calling fopen() --- Python/errors.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'Python/errors.c') diff --git a/Python/errors.c b/Python/errors.c index 940aef33a2..1d64efd315 100644 --- a/Python/errors.c +++ b/Python/errors.c @@ -1126,6 +1126,10 @@ PyErr_ProgramTextObject(PyObject *filename, int lineno) if (filename == NULL || lineno <= 0) return NULL; fp = _Py_fopen_obj(filename, "r" PY_STDIOTEXTMODE); + if (fp == NULL) { + PyErr_Clear(); + return NULL; + } return err_programtext(fp, lineno); } -- cgit v1.2.1 From 7b2a6ea6331bc0c44f0ae5b25e020214f4bd1be7 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 24 Mar 2015 12:41:23 +0100 Subject: Issue #23571: PyErr_FormatV() and PyErr_SetObject() now always clear the current exception because they can run arbitrary Python code and so no exception must be set. --- Python/errors.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'Python/errors.c') diff --git a/Python/errors.c b/Python/errors.c index 1d64efd315..17e3bcce83 100644 --- a/Python/errors.c +++ b/Python/errors.c @@ -74,11 +74,11 @@ PyErr_SetObject(PyObject *exception, PyObject *value) if (value == NULL || !PyExceptionInstance_Check(value)) { /* We must normalize the value right now */ PyObject *args, *fixed_value; -#ifdef Py_DEBUG - /* in debug mode, PyEval_EvalFrameEx() fails with an assertion - error if an exception is set when it is called */ + + /* Issue #23571: PyEval_CallObject() must not be called with an + exception set */ PyErr_Clear(); -#endif + if (value == NULL || value == Py_None) args = PyTuple_New(0); else if (PyTuple_Check(value)) { @@ -778,13 +778,12 @@ PyErr_FormatV(PyObject *exception, const char *format, va_list vargs) { PyObject* string; -#ifdef Py_DEBUG - /* in debug mode, PyEval_EvalFrameEx() fails with an assertion error - if an exception is set when it is called */ + /* Issue #23571: PyUnicode_FromFormatV() must not be called with an + exception set, it calls arbitrary Python code like PyObject_Repr() */ PyErr_Clear(); -#endif string = PyUnicode_FromFormatV(format, vargs); + PyErr_SetObject(exception, string); Py_XDECREF(string); return NULL; -- cgit v1.2.1 From 1f0eea05f78b032be72ee5b5787421acef61588d Mon Sep 17 00:00:00 2001 From: Yury Selivanov Date: Fri, 3 Jul 2015 01:04:23 -0400 Subject: Issue #19235: Add new RecursionError exception. Patch by Georg Brandl. --- Python/errors.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Python/errors.c') diff --git a/Python/errors.c b/Python/errors.c index 1172c59047..aed2bdc12d 100644 --- a/Python/errors.c +++ b/Python/errors.c @@ -319,7 +319,7 @@ finally: Py_DECREF(*exc); Py_DECREF(*val); /* ... and use the recursion error instead */ - *exc = PyExc_RuntimeError; + *exc = PyExc_RecursionError; *val = PyExc_RecursionErrorInst; Py_INCREF(*exc); Py_INCREF(*val); -- cgit v1.2.1