[Python-checkins] gh-92658: AF_HYPERV is only supported on Windows (#93192)
vstinner
webhook-mailer at python.org
Tue May 24 22:45:06 EDT 2022
https://github.com/python/cpython/commit/08e4e887f2d4650972272b2f4441485f3e1e9aab
commit: 08e4e887f2d4650972272b2f4441485f3e1e9aab
branch: main
author: Victor Stinner <vstinner at python.org>
committer: vstinner <vstinner at python.org>
date: 2022-05-25T04:44:57+02:00
summary:
gh-92658: AF_HYPERV is only supported on Windows (#93192)
Only build the AF_HYPERV support on Windows for the _socket extension.
FreeBSD defines the AF_HYPERV macro but doesn't have the SOCKADDR_HV
type.
files:
M Modules/socketmodule.c
M Modules/socketmodule.h
diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c
index 0bc99011b2c4e..002762e2e41ef 100644
--- a/Modules/socketmodule.c
+++ b/Modules/socketmodule.c
@@ -1582,7 +1582,7 @@ makesockaddr(SOCKET_T sockfd, struct sockaddr *addr, size_t addrlen, int proto)
}
#endif /* HAVE_SOCKADDR_ALG */
-#ifdef AF_HYPERV
+#ifdef HAVE_AF_HYPERV
case AF_HYPERV:
{
SOCKADDR_HV *a = (SOCKADDR_HV *) addr;
@@ -2407,7 +2407,7 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args,
return 1;
}
#endif /* HAVE_SOCKADDR_ALG */
-#ifdef AF_HYPERV
+#ifdef HAVE_AF_HYPERV
case AF_HYPERV:
{
switch (s->sock_proto) {
@@ -2476,7 +2476,7 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args,
return 0;
}
}
-#endif /* AF_HYPERV */
+#endif /* HAVE_AF_HYPERV */
/* More cases here... */
@@ -2626,13 +2626,13 @@ getsockaddrlen(PySocketSockObject *s, socklen_t *len_ret)
return 1;
}
#endif /* HAVE_SOCKADDR_ALG */
-#ifdef AF_HYPERV
+#ifdef HAVE_AF_HYPERV
case AF_HYPERV:
{
*len_ret = sizeof (SOCKADDR_HV);
return 1;
}
-#endif /* AF_HYPERV */
+#endif /* HAVE_AF_HYPERV */
/* More cases here... */
@@ -7460,7 +7460,7 @@ PyInit__socket(void)
/* Linux LLC */
PyModule_AddIntMacro(m, AF_LLC);
#endif
-#ifdef AF_HYPERV
+#ifdef HAVE_AF_HYPERV
/* Hyper-V sockets */
PyModule_AddIntMacro(m, AF_HYPERV);
@@ -7481,7 +7481,7 @@ PyInit__socket(void)
PyModule_AddStringConstant(m, "HV_GUID_CHILDREN", "90DB8B89-0D35-4F79-8CE9-49EA0AC8B7CD");
PyModule_AddStringConstant(m, "HV_GUID_LOOPBACK", "E0E16197-DD56-4A10-9195-5EE7A155A838");
PyModule_AddStringConstant(m, "HV_GUID_PARENT", "A42E7CDA-D03F-480C-9CC2-A4DE20ABB878");
-#endif /* AF_HYPERV */
+#endif /* HAVE_AF_HYPERV */
#ifdef USE_BLUETOOTH
PyModule_AddIntMacro(m, AF_BLUETOOTH);
diff --git a/Modules/socketmodule.h b/Modules/socketmodule.h
index 66d9ccf24e3fd..f31ba532a6c60 100644
--- a/Modules/socketmodule.h
+++ b/Modules/socketmodule.h
@@ -249,6 +249,11 @@ typedef int SOCKET_T;
#define PyLong_AsSocket_t(fd) (SOCKET_T)PyLong_AsLongLong(fd)
#endif
+// AF_HYPERV is only supported on Windows
+#if defined(AF_HYPERV) && defined(MS_WINDOWS)
+# define HAVE_AF_HYPERV
+#endif
+
/* Socket address */
typedef union sock_addr {
struct sockaddr_in in;
@@ -297,7 +302,7 @@ typedef union sock_addr {
#ifdef HAVE_LINUX_TIPC_H
struct sockaddr_tipc tipc;
#endif
-#ifdef AF_HYPERV
+#ifdef HAVE_AF_HYPERV
SOCKADDR_HV hv;
#endif
} sock_addr_t;
More information about the Python-checkins
mailing list