Skip to content

Commit 8b24d60

Browse files
authored
gh-95174: WASI: skip missing sockets functions (GH-95179)
1 parent daa64d6 commit 8b24d60

11 files changed

+864
-27
lines changed

Lib/test/test_socket.py

+13
Original file line numberDiff line numberDiff line change
@@ -965,6 +965,19 @@ def testWindowsSpecificConstants(self):
965965
socket.IPPROTO_L2TP
966966
socket.IPPROTO_SCTP
967967

968+
@unittest.skipIf(support.is_wasi, "WASI is missing these methods")
969+
def test_socket_methods(self):
970+
# socket methods that depend on a configure HAVE_ check. They should
971+
# be present on all platforms except WASI.
972+
names = [
973+
"_accept", "bind", "connect", "connect_ex", "getpeername",
974+
"getsockname", "listen", "recvfrom", "recvfrom_into", "sendto",
975+
"setsockopt", "shutdown"
976+
]
977+
for name in names:
978+
if not hasattr(socket.socket, name):
979+
self.fail(f"socket method {name} is missing")
980+
968981
@unittest.skipUnless(sys.platform == 'darwin', 'macOS specific test')
969982
@unittest.skipUnless(socket_helper.IPV6_ENABLED, 'IPv6 required for this test')
970983
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)