gh-102336: Remove code specifically for handling Windows 7 (GH-102337)

This commit is contained in:
Max Bachmann 2023-03-01 01:31:21 +01:00 committed by GitHub
parent 360ef843d8
commit 938e36f824
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 56 additions and 159 deletions

View file

@ -606,11 +606,6 @@ select_error(void)
# define SUPPRESS_DEPRECATED_CALL
#endif
#ifdef MS_WINDOWS
/* Does WSASocket() support the WSA_FLAG_NO_HANDLE_INHERIT flag? */
static int support_wsa_no_inherit = -1;
#endif
/* Convenience function to raise an error according to errno
and return a NULL pointer from a function. */
@ -5342,6 +5337,13 @@ sock_initobj_impl(PySocketSockObject *self, int family, int type, int proto,
set_error();
return -1;
}
if (!SetHandleInformation((HANDLE)fd, HANDLE_FLAG_INHERIT, 0)) {
closesocket(fd);
PyErr_SetFromWindowsErr(0);
return -1;
}
family = info.iAddressFamily;
type = info.iSocketType;
proto = info.iProtocol;
@ -5438,33 +5440,15 @@ sock_initobj_impl(PySocketSockObject *self, int family, int type, int proto,
#endif
Py_BEGIN_ALLOW_THREADS
if (support_wsa_no_inherit) {
fd = WSASocketW(family, type, proto,
NULL, 0,
WSA_FLAG_OVERLAPPED | WSA_FLAG_NO_HANDLE_INHERIT);
if (fd == INVALID_SOCKET) {
/* Windows 7 or Windows 2008 R2 without SP1 or the hotfix */
support_wsa_no_inherit = 0;
fd = socket(family, type, proto);
}
}
else {
fd = socket(family, type, proto);
}
fd = WSASocketW(family, type, proto,
NULL, 0,
WSA_FLAG_OVERLAPPED | WSA_FLAG_NO_HANDLE_INHERIT);
Py_END_ALLOW_THREADS
if (fd == INVALID_SOCKET) {
set_error();
return -1;
}
if (!support_wsa_no_inherit) {
if (!SetHandleInformation((HANDLE)fd, HANDLE_FLAG_INHERIT, 0)) {
closesocket(fd);
PyErr_SetFromWindowsErr(0);
return -1;
}
}
#else
/* UNIX */
Py_BEGIN_ALLOW_THREADS
@ -7340,12 +7324,6 @@ PyInit__socket(void)
if (!os_init())
return NULL;
#ifdef MS_WINDOWS
if (support_wsa_no_inherit == -1) {
support_wsa_no_inherit = IsWindows7SP1OrGreater();
}
#endif
Py_SET_TYPE(&sock_type, &PyType_Type);
m = PyModule_Create(&socketmodule);
if (m == NULL)