mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
Patch by Christian Tismer for Win32, to use FormatMessage() instead of
strerror(). This improves the quality of the error messages.
This commit is contained in:
parent
085b8121eb
commit
743007d2fe
1 changed files with 29 additions and 2 deletions
|
@ -49,6 +49,11 @@ extern char *strerror Py_PROTO((int));
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef MS_WIN32
|
||||||
|
#include "windows.h"
|
||||||
|
#include "winbase.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
void
|
void
|
||||||
PyErr_Restore(type, value, traceback)
|
PyErr_Restore(type, value, traceback)
|
||||||
PyObject *type;
|
PyObject *type;
|
||||||
|
@ -142,7 +147,7 @@ PyErr_GivenExceptionMatches(err, exc)
|
||||||
|
|
||||||
return err == exc;
|
return err == exc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
PyErr_ExceptionMatches(exc)
|
PyErr_ExceptionMatches(exc)
|
||||||
|
@ -291,7 +296,26 @@ PyErr_SetFromErrnoWithFilename(exc, filename)
|
||||||
if (i == 0)
|
if (i == 0)
|
||||||
s = "Error"; /* Sometimes errno didn't get set */
|
s = "Error"; /* Sometimes errno didn't get set */
|
||||||
else
|
else
|
||||||
|
#ifndef MS_WIN32
|
||||||
s = strerror(i);
|
s = strerror(i);
|
||||||
|
#else
|
||||||
|
{
|
||||||
|
int len = FormatMessage(
|
||||||
|
FORMAT_MESSAGE_ALLOCATE_BUFFER |
|
||||||
|
FORMAT_MESSAGE_FROM_SYSTEM |
|
||||||
|
FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||||
|
NULL, /* no message source */
|
||||||
|
i,
|
||||||
|
MAKELANGID(LANG_NEUTRAL,
|
||||||
|
SUBLANG_DEFAULT), /* Default language */
|
||||||
|
(LPTSTR) &s,
|
||||||
|
0, /* size not used */
|
||||||
|
NULL); /* no args */
|
||||||
|
/* remove trailing cr/lf and dots */
|
||||||
|
while (len > 0 && s[len-1] <= '.')
|
||||||
|
s[--len] = '\0';
|
||||||
|
}
|
||||||
|
#endif
|
||||||
if (filename != NULL && Py_UseClassExceptionsFlag)
|
if (filename != NULL && Py_UseClassExceptionsFlag)
|
||||||
v = Py_BuildValue("(iss)", i, s, filename);
|
v = Py_BuildValue("(iss)", i, s, filename);
|
||||||
else
|
else
|
||||||
|
@ -300,9 +324,12 @@ PyErr_SetFromErrnoWithFilename(exc, filename)
|
||||||
PyErr_SetObject(exc, v);
|
PyErr_SetObject(exc, v);
|
||||||
Py_DECREF(v);
|
Py_DECREF(v);
|
||||||
}
|
}
|
||||||
|
#ifdef MS_WIN32
|
||||||
|
LocalFree(s);
|
||||||
|
#endif
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PyObject *
|
PyObject *
|
||||||
PyErr_SetFromErrno(exc)
|
PyErr_SetFromErrno(exc)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue