-
-
Notifications
You must be signed in to change notification settings - Fork 30k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
errno.EINVAL != errno.WSAEINVAL (and others) on windows #107537
Comments
Please refer to "PC/errmap.h": Lines 9 to 23 in 97a6a41
If a Winsock function (the WSA prefix is a Winsock error code) sets the last error to >>> import ctypes
>>> try: ctypes.pythonapi.PyErr_SetFromWindowsErr(10022)
... except OSError as e: err = e
...
>>> err.errno
22 You also mention We can't change the value of |
I see, thank you for explaining; so the difference in how python deals with the 6 Winsock error codes in No, I don't have an example of returning The one example I actually ran into was |
Bug report
errnomodule.c contains the following list of error codes which are #undefd on windows in favour of the WSA version;
This means that, for example, errno.EADDRINUSE is assigned a value of 10048 instead of 48 on windows, and so errno.EADDRINUSE can be used when writing platform-agnostic socket error handling code.
The problem is that the list is missing some error codes which also have preferred WSA equivalents:
EACCES, EBADF, EFAULT, EINTR, EINVAL and EMFILE have WSA equivalents that are equal to the original + 10000.
ENAMETOOLONG (38) and ENOTEMPTY (41) have WSA equivalents WSAENAMETOOLONG (10063) and WSANOTEMPTY (10066).
This problem means that, for example, errno.EINVAL cannot be used in the same way as errno.EADDRINUSE to write platform-agnostic code because on windows errno still gives it a value of 22, while windows will only ever raise errno.WSAEINVAL which has a value of 10022.
As far as I can tell from searching online, it is true that windows only uses WSAEINVAL (10022) and never uses EINVAL (22), and so it would be correct for errnomodule.c to treat it the same way as EADDRINUSE and others. I haven't checked the rest of them.
My guess would be that a later version of VS added these additional error codes and the #undef list was not updated accordingly, but I'm afraid I don't know how to find the history of VS to confirm whether or not that is true.
If there is a real reason to exclude them from the list, it should be documented in the comment.
Checklist
Reproduction
Your environment
CPython versions tested on:
Operating system and architecture: Windows 10 22H2
The text was updated successfully, but these errors were encountered: