Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 257d38f

Browse files
author
Victor Stinner
committed
Issue #9738: Document PyErr_SetString() and PyErr_SetFromErrnoWithFilename()
encodings
1 parent fc8408c commit 257d38f

3 files changed

Lines changed: 13 additions & 3 deletions

File tree

Doc/c-api/exceptions.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ in various ways. There is a separate error indicator for each thread.
134134
This is the most common way to set the error indicator. The first argument
135135
specifies the exception type; it is normally one of the standard exceptions,
136136
e.g. :c:data:`PyExc_RuntimeError`. You need not increment its reference count.
137-
The second argument is an error message; it is converted to a string object.
137+
The second argument is an error message; it is decoded from ``'utf-8``'.
138138
139139
140140
.. c:function:: void PyErr_SetObject(PyObject *type, PyObject *value)
@@ -261,6 +261,8 @@ in various ways. There is a separate error indicator for each thread.
261261
*filename* is not *NULL*, it is passed to the constructor of *type* as a third
262262
parameter. In the case of exceptions such as :exc:`IOError` and :exc:`OSError`,
263263
this is used to define the :attr:`filename` attribute of the exception instance.
264+
*filename* is decoded from the filesystem encoding
265+
(:func:`sys.getfilesystemencoding`).
264266
265267
266268
.. c:function:: PyObject* PyErr_SetFromWindowsErr(int ierr)

Include/pyerrors.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,10 @@ typedef struct {
6060

6161
PyAPI_FUNC(void) PyErr_SetNone(PyObject *);
6262
PyAPI_FUNC(void) PyErr_SetObject(PyObject *, PyObject *);
63-
PyAPI_FUNC(void) PyErr_SetString(PyObject *, const char *);
63+
PyAPI_FUNC(void) PyErr_SetString(
64+
PyObject *exception,
65+
const char *string /* decoded from utf-8 */
66+
);
6467
PyAPI_FUNC(PyObject *) PyErr_Occurred(void);
6568
PyAPI_FUNC(void) PyErr_Clear(void);
6669
PyAPI_FUNC(void) PyErr_Fetch(PyObject **, PyObject **, PyObject **);
@@ -177,7 +180,9 @@ PyAPI_FUNC(PyObject *) PyErr_SetFromErrno(PyObject *);
177180
PyAPI_FUNC(PyObject *) PyErr_SetFromErrnoWithFilenameObject(
178181
PyObject *, PyObject *);
179182
PyAPI_FUNC(PyObject *) PyErr_SetFromErrnoWithFilename(
180-
PyObject *, const char *);
183+
PyObject *exc,
184+
const char *filename /* decoded from the filesystem encoding */
185+
);
181186
#ifdef MS_WINDOWS
182187
PyAPI_FUNC(PyObject *) PyErr_SetFromErrnoWithUnicodeFilename(
183188
PyObject *, const Py_UNICODE *);

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ What's New in Python 3.2 Alpha 3?
1010
Core and Builtins
1111
-----------------
1212

13+
- Issue #9738: Document PyErr_SetString() and PyErr_SetFromErrnoWithFilename()
14+
encodings
15+
1316
- ast.literal_eval() can now handle negative numbers. It is also a little
1417
more liberal in what it accepts without compromising the safety of the
1518
evaluation. For example, 3j+4 and 3+4+5 are both accepted.

0 commit comments

Comments
 (0)