Mercurial > cpython-lru_cache-weakref
diff Python/errors.c @ 72893:793c75177d28
Instantiate the OS-related exception as soon as we raise it, so that
"except" works properly.
| author | Antoine Pitrou <solipsis@pitrou.net> |
|---|---|
| date | Wed, 12 Oct 2011 19:39:57 +0200 |
| parents | 41a1de81ef2b |
| children | 7109f31300fb |
line wrap: on
line diff
--- a/Python/errors.c Wed Oct 12 19:11:12 2011 +0200 +++ b/Python/errors.c Wed Oct 12 19:39:57 2011 +0200 @@ -341,7 +341,7 @@ 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 @@ } 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);
