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

Skip to content

Commit 97d9515

Browse files
committed
PyErr_SetFromErrnoWithFilename(): New function which supports setting
an exception from errno, with a supplied filename (primarily used by IOError and OSError). If class exceptions are used then the exception is instantiated with a 3-tuple: (errno, strerror, filename). For backwards compatibility reasons, if string exceptions are used, filename is ignored. PyErr_SetFromErrno(): Implement in terms of PyErr_SetFromErrnoWithFilename().
1 parent 2dfe4de commit 97d9515

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

Python/errors.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,22 +277,34 @@ PyErr_NoMemory()
277277
}
278278

279279
PyObject *
280-
PyErr_SetFromErrno(exc)
280+
PyErr_SetFromErrnoWithFilename(exc, filename)
281281
PyObject *exc;
282+
char *filename;
282283
{
283284
PyObject *v;
284285
int i = errno;
285286
#ifdef EINTR
286287
if (i == EINTR && PyErr_CheckSignals())
287288
return NULL;
288289
#endif
289-
v = Py_BuildValue("(is)", i, strerror(i));
290+
if (filename != NULL && Py_UseClassExceptionsFlag)
291+
v = Py_BuildValue("(iss)", i, strerror(i), filename);
292+
else
293+
v = Py_BuildValue("(is)", i, strerror(i));
290294
if (v != NULL) {
291295
PyErr_SetObject(exc, v);
292296
Py_DECREF(v);
293297
}
294298
return NULL;
295299
}
300+
301+
302+
PyObject *
303+
PyErr_SetFromErrno(exc)
304+
PyObject *exc;
305+
{
306+
return PyErr_SetFromErrnoWithFilename(exc, NULL);
307+
}
296308

297309
void
298310
PyErr_BadInternalCall()

0 commit comments

Comments
 (0)