diff options
author | Barry Warsaw <barry@python.org> | 1998-07-23 16:05:56 +0000 |
---|---|---|
committer | Barry Warsaw <barry@python.org> | 1998-07-23 16:05:56 +0000 |
commit | e77930f2c9dbe60a41587243599d8d3acff39415 (patch) | |
tree | b36e6f32e01d3ea091db2cbe93af472e571208b7 /Python/errors.c | |
parent | 90d35210b600d308c060164d5bc919f8f72d083c (diff) | |
download | cpython-e77930f2c9dbe60a41587243599d8d3acff39415.tar.gz |
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().
Diffstat (limited to 'Python/errors.c')
-rw-r--r-- | Python/errors.c | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/Python/errors.c b/Python/errors.c index 1a643c0fac..c0efbf1b26 100644 --- a/Python/errors.c +++ b/Python/errors.c @@ -277,8 +277,9 @@ PyErr_NoMemory() } PyObject * -PyErr_SetFromErrno(exc) +PyErr_SetFromErrnoWithFilename(exc, filename) PyObject *exc; + char *filename; { PyObject *v; int i = errno; @@ -286,13 +287,24 @@ PyErr_SetFromErrno(exc) if (i == EINTR && PyErr_CheckSignals()) return NULL; #endif - v = Py_BuildValue("(is)", i, strerror(i)); + if (filename != NULL && Py_UseClassExceptionsFlag) + v = Py_BuildValue("(iss)", i, strerror(i), filename); + else + v = Py_BuildValue("(is)", i, strerror(i)); if (v != NULL) { PyErr_SetObject(exc, v); Py_DECREF(v); } return NULL; } + + +PyObject * +PyErr_SetFromErrno(exc) + PyObject *exc; +{ + return PyErr_SetFromErrnoWithFilename(exc, NULL); +} void PyErr_BadInternalCall() |