Skip to content

Commit

Permalink
pythongh-95174: WASI: skip missing sockets functions (pythonGH-95179)
Browse files Browse the repository at this point in the history
  • Loading branch information
tiran committed Jul 27, 2022
1 parent daa64d6 commit 8b24d60
Show file tree
Hide file tree
Showing 11 changed files with 864 additions and 27 deletions.
13 changes: 13 additions & 0 deletions Lib/test/test_socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -965,6 +965,19 @@ def testWindowsSpecificConstants(self):
socket.IPPROTO_L2TP
socket.IPPROTO_SCTP

@unittest.skipIf(support.is_wasi, "WASI is missing these methods")
def test_socket_methods(self):
# socket methods that depend on a configure HAVE_ check. They should
# be present on all platforms except WASI.
names = [
"_accept", "bind", "connect", "connect_ex", "getpeername",
"getsockname", "listen", "recvfrom", "recvfrom_into", "sendto",
"setsockopt", "shutdown"
]
for name in names:
if not hasattr(socket.socket, name):
self.fail(f"socket method {name} is missing")

@unittest.skipUnless(sys.platform == 'darwin', 'macOS specific test')
@unittest.skipUnless(socket_helper.IPV6_ENABLED, 'IPv6 required for this test')
def test3542SocketOptions(self):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +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.
2 changes: 2 additions & 0 deletions Modules/addrinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,9 @@ struct sockaddr_storage {
#ifdef __cplusplus
extern "C" {
#endif
#ifdef ENABLE_IPV6
extern void freehostent(struct hostent *);
#endif
#ifdef __cplusplus
}
#endif
5 changes: 5 additions & 0 deletions Modules/getaddrinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@
# define FAITH
#endif

#ifdef HAVE_NETDB_H
#define HAVE_GETADDRINFO 1

#define SUCCESS 0
#define GAI_ANY 0
#define YES 1
Expand Down Expand Up @@ -636,3 +639,5 @@ get_addr(hostname, af, res, pai, port0)
*res = NULL;
return error;
}

#endif // HAVE_NETDB_H
4 changes: 4 additions & 0 deletions Modules/getnameinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@
#include "addrinfo.h"
#endif

#ifdef HAVE_NETDB_H
#define HAVE_GETNAMEINFO 1

#define SUCCESS 0
#define YES 1
#define NO 0
Expand Down Expand Up @@ -211,3 +214,4 @@ getnameinfo(sa, salen, host, hostlen, serv, servlen, flags)
}
return SUCCESS;
}
#endif // HAVE_NETDB_H
Loading

0 comments on commit 8b24d60

Please sign in to comment.