Commit 97d95153 authored by Barry Warsaw's avatar Barry Warsaw

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().
parent 2dfe4de6
...@@ -277,8 +277,9 @@ PyErr_NoMemory() ...@@ -277,8 +277,9 @@ PyErr_NoMemory()
} }
PyObject * PyObject *
PyErr_SetFromErrno(exc) PyErr_SetFromErrnoWithFilename(exc, filename)
PyObject *exc; PyObject *exc;
char *filename;
{ {
PyObject *v; PyObject *v;
int i = errno; int i = errno;
...@@ -286,6 +287,9 @@ PyErr_SetFromErrno(exc) ...@@ -286,6 +287,9 @@ PyErr_SetFromErrno(exc)
if (i == EINTR && PyErr_CheckSignals()) if (i == EINTR && PyErr_CheckSignals())
return NULL; return NULL;
#endif #endif
if (filename != NULL && Py_UseClassExceptionsFlag)
v = Py_BuildValue("(iss)", i, strerror(i), filename);
else
v = Py_BuildValue("(is)", i, strerror(i)); v = Py_BuildValue("(is)", i, strerror(i));
if (v != NULL) { if (v != NULL) {
PyErr_SetObject(exc, v); PyErr_SetObject(exc, v);
...@@ -294,6 +298,14 @@ PyErr_SetFromErrno(exc) ...@@ -294,6 +298,14 @@ PyErr_SetFromErrno(exc)
return NULL; return NULL;
} }
PyObject *
PyErr_SetFromErrno(exc)
PyObject *exc;
{
return PyErr_SetFromErrnoWithFilename(exc, NULL);
}
void void
PyErr_BadInternalCall() PyErr_BadInternalCall()
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment