Mercurial > cpython-lru_cache-weakref
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 72892:c589c6546071 | 72893:793c75177d28 |
|---|---|
| 339 | 339 |
| 340 PyObject * | 340 PyObject * |
| 341 PyErr_SetFromErrnoWithFilenameObject(PyObject *exc, PyObject *filenameObject) | 341 PyErr_SetFromErrnoWithFilenameObject(PyObject *exc, PyObject *filenameObject) |
| 342 { | 342 { |
| 343 PyObject *message; | 343 PyObject *message; |
| 344 PyObject *v; | 344 PyObject *v, *args; |
| 345 int i = errno; | 345 int i = errno; |
| 346 #ifndef MS_WINDOWS | 346 #ifndef MS_WINDOWS |
| 347 char *s; | 347 char *s; |
| 348 #else | 348 #else |
| 349 WCHAR *s_buf = NULL; | 349 WCHAR *s_buf = NULL; |
| 408 #endif | 408 #endif |
| 409 return NULL; | 409 return NULL; |
| 410 } | 410 } |
| 411 | 411 |
| 412 if (filenameObject != NULL) | 412 if (filenameObject != NULL) |
| 413 v = Py_BuildValue("(iOO)", i, message, filenameObject); | 413 args = Py_BuildValue("(iOO)", i, message, filenameObject); |
| 414 else | 414 else |
| 415 v = Py_BuildValue("(iO)", i, message); | 415 args = Py_BuildValue("(iO)", i, message); |
| 416 Py_DECREF(message); | 416 Py_DECREF(message); |
| 417 | 417 |
| 418 if (v != NULL) { | 418 if (args != NULL) { |
| 419 PyErr_SetObject(exc, v); | 419 v = PyObject_Call(exc, args, NULL); |
| 420 Py_DECREF(v); | 420 Py_DECREF(args); |
| 421 if (v != NULL) { | |
| 422 PyErr_SetObject((PyObject *) Py_TYPE(v), v); | |
| 423 Py_DECREF(v); | |
| 424 } | |
| 421 } | 425 } |
| 422 #ifdef MS_WINDOWS | 426 #ifdef MS_WINDOWS |
| 423 LocalFree(s_buf); | 427 LocalFree(s_buf); |
| 424 #endif | 428 #endif |
| 425 return NULL; | 429 return NULL; |
