Mercurial > cpython-lru_cache-weakref
comparison Python/errors.c @ 72965:84aed9ef7aaf
Instantiate the OS-related exception as soon as we raise it, so that "except"
works properly.
PyErr_SetFromErrnoWithFilenameObject() was already fixed by the changeset
793c75177d28. This commit fixes PyErr_SetExcFromWindowsErrWithFilenameObject(),
used on Windows.
| author | Victor Stinner <victor.stinner@haypocalc.com> |
|---|---|
| date | Mon, 17 Oct 2011 20:18:58 +0200 |
| parents | db4aa878cea2 |
| children | 021e5bb297d1 |
comparison
equal
deleted
inserted
replaced
| 72964:f6b8e4226260 | 72965:84aed9ef7aaf |
|---|---|
| 466 PyObject *filenameObject) | 466 PyObject *filenameObject) |
| 467 { | 467 { |
| 468 int len; | 468 int len; |
| 469 WCHAR *s_buf = NULL; /* Free via LocalFree */ | 469 WCHAR *s_buf = NULL; /* Free via LocalFree */ |
| 470 PyObject *message; | 470 PyObject *message; |
| 471 PyObject *v; | 471 PyObject *args, *v; |
| 472 DWORD err = (DWORD)ierr; | 472 DWORD err = (DWORD)ierr; |
| 473 if (err==0) err = GetLastError(); | 473 if (err==0) err = GetLastError(); |
| 474 len = FormatMessageW( | 474 len = FormatMessageW( |
| 475 /* Error API error */ | 475 /* Error API error */ |
| 476 FORMAT_MESSAGE_ALLOCATE_BUFFER | | 476 FORMAT_MESSAGE_ALLOCATE_BUFFER | |
| 502 | 502 |
| 503 if (filenameObject == NULL) | 503 if (filenameObject == NULL) |
| 504 filenameObject = Py_None; | 504 filenameObject = Py_None; |
| 505 /* This is the constructor signature for passing a Windows error code. | 505 /* This is the constructor signature for passing a Windows error code. |
| 506 The POSIX translation will be figured out by the constructor. */ | 506 The POSIX translation will be figured out by the constructor. */ |
| 507 v = Py_BuildValue("(iOOi)", 0, message, filenameObject, err); | 507 args = Py_BuildValue("(iOOi)", 0, message, filenameObject, err); |
| 508 Py_DECREF(message); | 508 Py_DECREF(message); |
| 509 | 509 |
| 510 if (v != NULL) { | 510 if (args != NULL) { |
| 511 PyErr_SetObject(exc, v); | 511 v = PyObject_Call(exc, args, NULL); |
| 512 Py_DECREF(v); | 512 Py_DECREF(args); |
| 513 if (v != NULL) { | |
| 514 PyErr_SetObject((PyObject *) Py_TYPE(v), v); | |
| 515 Py_DECREF(v); | |
| 516 } | |
| 513 } | 517 } |
| 514 LocalFree(s_buf); | 518 LocalFree(s_buf); |
| 515 return NULL; | 519 return NULL; |
| 516 } | 520 } |
| 517 | 521 |
