diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2011-10-12 19:39:57 +0200 |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2011-10-12 19:39:57 +0200 |
commit | edb19b80f00cf42741fa66efdcab2f25a9fb3f08 (patch) | |
tree | 45825087f0a0d6443c74eb3970dbff23a8bb9e36 /Python/errors.c | |
parent | b593dbbdc9041b1e5c7b1bcf032cac966651871f (diff) | |
download | cpython-edb19b80f00cf42741fa66efdcab2f25a9fb3f08.tar.gz |
Instantiate the OS-related exception as soon as we raise it, so that
"except" works properly.
Diffstat (limited to 'Python/errors.c')
-rw-r--r-- | Python/errors.c | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/Python/errors.c b/Python/errors.c index 6e69d23c30..5988e1bf89 100644 --- a/Python/errors.c +++ b/Python/errors.c @@ -341,7 +341,7 @@ PyObject * PyErr_SetFromErrnoWithFilenameObject(PyObject *exc, PyObject *filenameObject) { PyObject *message; - PyObject *v; + PyObject *v, *args; int i = errno; #ifndef MS_WINDOWS char *s; @@ -410,14 +410,18 @@ PyErr_SetFromErrnoWithFilenameObject(PyObject *exc, PyObject *filenameObject) } if (filenameObject != NULL) - v = Py_BuildValue("(iOO)", i, message, filenameObject); + args = Py_BuildValue("(iOO)", i, message, filenameObject); else - v = Py_BuildValue("(iO)", i, message); + args = Py_BuildValue("(iO)", i, message); Py_DECREF(message); - if (v != NULL) { - PyErr_SetObject(exc, v); - Py_DECREF(v); + if (args != NULL) { + v = PyObject_Call(exc, args, NULL); + Py_DECREF(args); + if (v != NULL) { + PyErr_SetObject((PyObject *) Py_TYPE(v), v); + Py_DECREF(v); + } } #ifdef MS_WINDOWS LocalFree(s_buf); |