Skip to content

Commit 0788456

Browse files
committed
[3.11] gh-95174: WASI: skip missing sockets functions (GH-95179).
(cherry picked from commit 8b24d60) Co-authored-by: Christian Heimes <[email protected]>
1 parent 820904e commit 0788456

11 files changed

+868
-29
lines changed

Lib/test/test_socket.py

+13
Original file line numberDiff line numberDiff line change
@@ -956,6 +956,19 @@ def testWindowsSpecificConstants(self):
956956
socket.IPPROTO_L2TP
957957
socket.IPPROTO_SCTP
958958

959+
@unittest.skipIf(support.is_wasi, "WASI is missing these methods")
960+
def test_socket_methods(self):
961+
# socket methods that depend on a configure HAVE_ check. They should
962+
# be present on all platforms except WASI.
963+
names = [
964+
"_accept", "bind", "connect", "connect_ex", "getpeername",
965+
"getsockname", "listen", "recvfrom", "recvfrom_into", "sendto",
966+
"setsockopt", "shutdown"
967+
]
968+
for name in names:
969+
if not hasattr(socket.socket, name):
970+
self.fail(f"socket method {name} is missing")
971+
959972
@unittest.skipUnless(sys.platform == 'darwin', 'macOS specific test')
960973
@unittest.skipUnless(socket_helper.IPV6_ENABLED, 'IPv6 required for this test')
961974
def test3542SocketOptions(self):
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Python now skips missing :mod:`socket` functions and methods on WASI. WASI can only create sockets from existing fd / accept and has no netdb.

Modules/addrinfo.h

+2
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,9 @@ struct sockaddr_storage {
162162
#ifdef __cplusplus
163163
extern "C" {
164164
#endif
165+
#ifdef ENABLE_IPV6
165166
extern void freehostent(struct hostent *);
167+
#endif
166168
#ifdef __cplusplus
167169
}
168170
#endif

Modules/getaddrinfo.c

+5
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@
6161
# define FAITH
6262
#endif
6363

64+
#ifdef HAVE_NETDB_H
65+
#define HAVE_GETADDRINFO 1
66+
6467
#define SUCCESS 0
6568
#define GAI_ANY 0
6669
#define YES 1
@@ -636,3 +639,5 @@ get_addr(hostname, af, res, pai, port0)
636639
*res = NULL;
637640
return error;
638641
}
642+
643+
#endif // HAVE_NETDB_H

Modules/getnameinfo.c

+4
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@
4848
#include "addrinfo.h"
4949
#endif
5050

51+
#ifdef HAVE_NETDB_H
52+
#define HAVE_GETNAMEINFO 1
53+
5154
#define SUCCESS 0
5255
#define YES 1
5356
#define NO 0
@@ -211,3 +214,4 @@ getnameinfo(sa, salen, host, hostlen, serv, servlen, flags)
211214
}
212215
return SUCCESS;
213216
}
217+
#endif // HAVE_NETDB_H

0 commit comments

Comments
 (0)