Skip to content

Commit

Permalink
Issue python#18711: Add a new PyErr_FormatV function, similar to `P…
Browse files Browse the repository at this point in the history
…yErr_Format` but accepting a `va_list` argument.
  • Loading branch information
pitrou committed Sep 30, 2014
1 parent 63860e5 commit 0676a40
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 10 deletions.
8 changes: 8 additions & 0 deletions Doc/c-api/exceptions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,14 @@ in various ways. There is a separate error indicator for each thread.
string.
.. c:function:: PyObject* PyErr_FormatV(PyObject *exception, const char *format, va_list vargs)
Same as :c:func:`PyErr_Format`, but taking a `va_list` argument rather
than a variable number of arguments.
.. versionadded:: 3.5
.. c:function:: void PyErr_SetNone(PyObject *type)
This is a shorthand for ``PyErr_SetObject(type, Py_None)``.
Expand Down
5 changes: 5 additions & 0 deletions Doc/data/refcounts.dat
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,11 @@ PyErr_Format:PyObject*:exception:+1:
PyErr_Format:const char*:format::
PyErr_Format::...::

PyErr_FormatV:PyObject*::null:
PyErr_FormatV:PyObject*:exception:+1:
PyErr_FormatV:const char*:format::
PyErr_FormatV:va_list:vargs::

PyErr_WarnEx:int:::
PyErr_WarnEx:PyObject*:category:0:
PyErr_WarnEx:const char*:message::
Expand Down
6 changes: 6 additions & 0 deletions Include/pyerrors.h
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,12 @@ PyAPI_FUNC(PyObject *) PyErr_Format(
const char *format, /* ASCII-encoded string */
...
);
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03050000
PyAPI_FUNC(PyObject *) PyErr_FormatV(
PyObject *exception,
const char *format,
va_list vargs);
#endif

#ifdef MS_WINDOWS
PyAPI_FUNC(PyObject *) PyErr_SetFromWindowsErrWithFilename(
Expand Down
3 changes: 3 additions & 0 deletions Misc/NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ Release date: TBA
Core and Builtins
-----------------

- Issue #18711: Add a new `PyErr_FormatV` function, similar to `PyErr_Format`
but accepting a `va_list` argument.

- Issue #22520: Fix overflow checking when generating the repr of a unicode
object.

Expand Down
1 change: 1 addition & 0 deletions PC/python3.def
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ EXPORTS
PyErr_ExceptionMatches=python35.PyErr_ExceptionMatches
PyErr_Fetch=python35.PyErr_Fetch
PyErr_Format=python35.PyErr_Format
PyErr_FormatV=python35.PyErr_FormatV
PyErr_GivenExceptionMatches=python35.PyErr_GivenExceptionMatches
PyErr_NewException=python35.PyErr_NewException
PyErr_NewExceptionWithDoc=python35.PyErr_NewExceptionWithDoc
Expand Down
1 change: 1 addition & 0 deletions PC/python35stub.def
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ PyErr_Display
PyErr_ExceptionMatches
PyErr_Fetch
PyErr_Format
PyErr_FormatV
PyErr_GivenExceptionMatches
PyErr_NewException
PyErr_NewExceptionWithDoc
Expand Down
25 changes: 15 additions & 10 deletions Python/errors.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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)
Expand Down

0 comments on commit 0676a40

Please sign in to comment.