The bunch of functions to raise windows errors have the following signatures:
PyAPI_FUNC(PyObject *) PyErr_SetFromWindowsErrWithFilename( int ierr, const char *filename /* decoded from the filesystem encoding */ ); PyAPI_FUNC(PyObject *) PyErr_SetFromWindowsErr(int); PyAPI_FUNC(PyObject *) PyErr_SetExcFromWindowsErrWithFilenameObject( PyObject *,int, PyObject *);
Note that they accept error code as signed integer. However, the GetLastError function to receive errorcode in windows returns DWORD - unsigned integer:
_Post_equals_last_error_ DWORD GetLastError();
This leads to incorrect error code handling when working with winapi,
OSError: [WinError -536870389] Windows Error 0xe000020b
Right now it looks like a bug for me…
I tried to figure out why do these functions accept signed integer, but could not find anything. Is there a reason which I do not see?
I understand that public API signatures are probably impossible to change, but at-least could we internally cast it back to unsigned?