diff --git a/Include/cpython/pthread_stubs.h b/Include/cpython/pthread_stubs.h new file mode 100644 index 00000000000000..77d9a58c5f482b --- /dev/null +++ b/Include/cpython/pthread_stubs.h @@ -0,0 +1,138 @@ +#ifndef Py_PTRHEAD_STUBS_H +#define Py_PTRHEAD_STUBS_H + +#ifdef HAVE_PTHREAD_STUBS + +// WASI's bits/alltypes.h provides type definitions when __NEED_ is set. +// The file can be included multiple times. +#ifdef __wasi__ +# define __NEED_pthread_cond_t 1 +# define __NEED_pthread_condattr_t 1 +# define __NEED_pthread_mutex_t 1 +# define __NEED_pthread_mutexattr_t 1 +# define __NEED_pthread_key_t 1 +# define __NEED_pthread_t 1 +# define __NEED_pthread_attr_t 1 +# include +#else +# error "HAVE_PTHREAD_STUBS not defined for this platform" +#endif + +// mutex +static inline int +pthread_mutex_init(pthread_mutex_t *restrict mutex, const pthread_mutexattr_t *restrict attr) { + return 0; +} + +static inline int +pthread_mutex_destroy(pthread_mutex_t *mutex) { + return 0; +} + +static inline int +pthread_mutex_trylock(pthread_mutex_t *mutex) { + return 0; +} + +static inline int +pthread_mutex_lock(pthread_mutex_t *mutex) { + return 0; +} + +static inline int +pthread_mutex_unlock(pthread_mutex_t *mutex) { + return 0; +} + +// condition +static inline int +pthread_condattr_init(pthread_condattr_t *attr) { + return 0; +} + +static inline int +pthread_cond_init(pthread_cond_t *restrict cond, const pthread_condattr_t *restrict attr) { + return 0; +} + +static inline int +pthread_cond_destroy(pthread_cond_t *cond) { + return 0; +} + +static inline int +pthread_condattr_setclock(pthread_condattr_t *attr, clockid_t clock_id) { + return 0; +} + +static inline int +pthread_cond_wait(pthread_cond_t *restrict cond, pthread_mutex_t *restrict mutex) { + return 0; +} + +static inline int +pthread_cond_timedwait(pthread_cond_t *restrict cond, pthread_mutex_t *restrict mutex, const struct timespec *restrict abstime) { + return 0; +} + +static inline int +pthread_cond_signal(pthread_cond_t *cond) { + return 0; +} + +// pthread attr +static inline int +pthread_attr_init(pthread_attr_t *attr) +{ + return 0; +} + +static inline int +pthread_attr_setstacksize(pthread_attr_t *attr, size_t stacksize) +{ + return 0; +} + +static inline int +pthread_attr_destroy(pthread_attr_t *attr) +{ + return 0; +} + +// pthread + +static inline int +pthread_create(pthread_t *restrict thread, const pthread_attr_t *restrict attr, void *(*start_routine)(void *), void *restrict arg) +{ + errno = EAGAIN; + return -1; +} + +static inline int +pthread_detach(pthread_t thread) +{ + errno = ESRCH; + return -1; +} + +static inline pthread_t +pthread_self(void) +{ + return (pthread_t)1; +} + +static inline _Noreturn void +pthread_exit(void *retval) +{ + exit(0); +} + +// key, implemented in thread_pthread.h +int pthread_key_create(pthread_key_t *out, void (*destructor)(void *a)); +int pthread_key_delete(pthread_key_t key); +void* pthread_getspecific(pthread_key_t key); +int pthread_setspecific(pthread_key_t key, const void *value); + +#endif // HAVE_PTHREAD_STUBS + +#endif // Py_PTRHEAD_STUBS_H diff --git a/Include/cpython/pythread.h b/Include/cpython/pythread.h index 1fd86a6a90f9af..ce4ec8f65b15ea 100644 --- a/Include/cpython/pythread.h +++ b/Include/cpython/pythread.h @@ -20,6 +20,9 @@ PyAPI_FUNC(int) _PyThread_at_fork_reinit(PyThread_type_lock *lock); but hardcode the unsigned long to avoid errors for include directive. */ # define NATIVE_TSS_KEY_T unsigned long +#elif defined(HAVE_PTHREAD_STUBS) +# include "cpython/pthread_stubs.h" +# define NATIVE_TSS_KEY_T pthread_key_t #else # error "Require native threads. See https://bugs.python.org/issue31370" #endif diff --git a/Include/internal/pycore_condvar.h b/Include/internal/pycore_condvar.h index 981c962bf7dfdf..a26b8c903b926a 100644 --- a/Include/internal/pycore_condvar.h +++ b/Include/internal/pycore_condvar.h @@ -22,11 +22,15 @@ #ifdef HAVE_PTHREAD_H # include +#elif defined(HAVE_PTHREAD_STUBS) +# include "cpython/pthread_stubs.h" #endif + #define PyMUTEX_T pthread_mutex_t #define PyCOND_T pthread_cond_t + #elif defined(NT_THREADS) /* * Windows (XP, 2003 server and later, as well as (hopefully) CE) support diff --git a/Lib/asyncore.py b/Lib/asyncore.py index 57c86871f3dcf0..76d74fa38b8220 100644 --- a/Lib/asyncore.py +++ b/Lib/asyncore.py @@ -61,7 +61,6 @@ 'Python {remove}. The recommended replacement is asyncio') warnings._deprecated(__name__, _DEPRECATION_MSG, remove=(3, 12)) - _DISCONNECTED = frozenset({ECONNRESET, ENOTCONN, ESHUTDOWN, ECONNABORTED, EPIPE, EBADF}) diff --git a/Lib/subprocess.py b/Lib/subprocess.py index e10b01047ebef5..6761f942ae5aa4 100644 --- a/Lib/subprocess.py +++ b/Lib/subprocess.py @@ -107,6 +107,15 @@ import select import selectors + # WASI does not provide these function. + def _notimplemented(*args): + raise NotImplementedError + + _waitstatus_to_exitcode = getattr(os, "waitstatus_to_exitcode", _notimplemented) + _waitpid = getattr(os, "waitpid", _notimplemented) + _WIFSTOPPED = getattr(os, "WIFSTOPPED", _notimplemented) + _WSTOPSIG = getattr(os, "WSTOPSIG", _notimplemented) + _WNOHANG = getattr(os, "WNOHANG", None) # Exception classes used by this module. class SubprocessError(Exception): pass @@ -1890,9 +1899,9 @@ def _execute_child(self, args, executable, preexec_fn, close_fds, def _handle_exitstatus(self, sts, - waitstatus_to_exitcode=os.waitstatus_to_exitcode, - _WIFSTOPPED=os.WIFSTOPPED, - _WSTOPSIG=os.WSTOPSIG): + waitstatus_to_exitcode=_waitstatus_to_exitcode, + _WIFSTOPPED=_WIFSTOPPED, + _WSTOPSIG=_WSTOPSIG): """All callers to this function MUST hold self._waitpid_lock.""" # This method is called (indirectly) by __del__, so it cannot # refer to anything outside of its local scope. @@ -1901,8 +1910,8 @@ def _handle_exitstatus(self, sts, else: self.returncode = waitstatus_to_exitcode(sts) - def _internal_poll(self, _deadstate=None, _waitpid=os.waitpid, - _WNOHANG=os.WNOHANG, _ECHILD=errno.ECHILD): + def _internal_poll(self, _deadstate=None, _waitpid=_waitpid, + _WNOHANG=_WNOHANG, _ECHILD=errno.ECHILD): """Check if child process has terminated. Returns returncode attribute. diff --git a/Lib/uuid.py b/Lib/uuid.py index f179d68e8265ac..ec452c843c1f76 100644 --- a/Lib/uuid.py +++ b/Lib/uuid.py @@ -526,7 +526,7 @@ def _arp_getnode(): import os, socket try: ip_addr = socket.gethostbyname(socket.gethostname()) - except OSError: + except (OSError, AttributeError): return None # Try getting the MAC addr from arp based on our IP address (Solaris). diff --git a/Makefile.pre.in b/Makefile.pre.in index dd0216572e6019..0c1b95c624b2f1 100644 --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -1545,6 +1545,7 @@ PYTHON_HEADERS= \ $(srcdir)/Include/cpython/objimpl.h \ $(srcdir)/Include/cpython/odictobject.h \ $(srcdir)/Include/cpython/picklebufobject.h \ + $(srcdir)/Include/cpython/pthread_stubs.h \ $(srcdir)/Include/cpython/pyctype.h \ $(srcdir)/Include/cpython/pydebug.h \ $(srcdir)/Include/cpython/pyerrors.h \ diff --git a/Modules/addrinfo.h b/Modules/addrinfo.h index c3c86248dd4360..5b6aa82f318261 100644 --- a/Modules/addrinfo.h +++ b/Modules/addrinfo.h @@ -159,6 +159,31 @@ struct sockaddr_storage { }; #endif /* !HAVE_SOCKADDR_STORAGE */ +#ifndef HAVE_NETDB_H +static int h_errno = 0; + +#define HOST_NOT_FOUND 1 +#define TRY_AGAIN 2 +#define NO_RECOVERY 3 +#define NO_DATA 4 + +struct hostent { + char *h_name; + char **h_aliases; + int h_addrtype; + int h_length; + char **h_addr_list; +}; + +struct servent { + char *s_name; + char **s_aliases; + int s_port; + char *s_proto; +}; + +#endif // HAVE_NETDB_H + #ifdef __cplusplus extern "C" { #endif diff --git a/Modules/clinic/posixmodule.c.h b/Modules/clinic/posixmodule.c.h index 1ce7d86204e6f3..e13f238253d61c 100644 --- a/Modules/clinic/posixmodule.c.h +++ b/Modules/clinic/posixmodule.c.h @@ -3100,7 +3100,7 @@ os_openpty(PyObject *module, PyObject *Py_UNUSED(ignored)) #endif /* (defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX)) */ -#if (defined(HAVE_LOGIN_TTY) || defined(HAVE_FALLBACK_LOGIN_TTY)) +#if ((defined(HAVE_LOGIN_TTY) || defined(HAVE_FALLBACK_LOGIN_TTY)) && defined(HAVE_DUP2)) PyDoc_STRVAR(os_login_tty__doc__, "login_tty($module, fd, /)\n" @@ -3133,7 +3133,7 @@ os_login_tty(PyObject *module, PyObject *arg) return return_value; } -#endif /* (defined(HAVE_LOGIN_TTY) || defined(HAVE_FALLBACK_LOGIN_TTY)) */ +#endif /* ((defined(HAVE_LOGIN_TTY) || defined(HAVE_FALLBACK_LOGIN_TTY)) && defined(HAVE_DUP2)) */ #if defined(HAVE_FORKPTY) @@ -4685,6 +4685,8 @@ os_dup(PyObject *module, PyObject *arg) return return_value; } +#if (defined(HAVE_DUP2) || defined(HAVE_DUP3)) + PyDoc_STRVAR(os_dup2__doc__, "dup2($module, /, fd, fd2, inheritable=True)\n" "--\n" @@ -4740,6 +4742,8 @@ os_dup2(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwn return return_value; } +#endif /* (defined(HAVE_DUP2) || defined(HAVE_DUP3)) */ + #if defined(HAVE_LOCKF) PyDoc_STRVAR(os_lockf__doc__, @@ -9105,6 +9109,10 @@ os_waitstatus_to_exitcode(PyObject *module, PyObject *const *args, Py_ssize_t na #define OS_TCSETPGRP_METHODDEF #endif /* !defined(OS_TCSETPGRP_METHODDEF) */ +#ifndef OS_DUP2_METHODDEF + #define OS_DUP2_METHODDEF +#endif /* !defined(OS_DUP2_METHODDEF) */ + #ifndef OS_LOCKF_METHODDEF #define OS_LOCKF_METHODDEF #endif /* !defined(OS_LOCKF_METHODDEF) */ @@ -9352,4 +9360,4 @@ os_waitstatus_to_exitcode(PyObject *module, PyObject *const *args, Py_ssize_t na #ifndef OS_WAITSTATUS_TO_EXITCODE_METHODDEF #define OS_WAITSTATUS_TO_EXITCODE_METHODDEF #endif /* !defined(OS_WAITSTATUS_TO_EXITCODE_METHODDEF) */ -/*[clinic end generated code: output=bae15f09a1b3d2e7 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=562202bcd6567446 input=a9049054013a1b77]*/ diff --git a/Modules/errnomodule.c b/Modules/errnomodule.c index bf6766e02349c0..0516e7367050c2 100644 --- a/Modules/errnomodule.c +++ b/Modules/errnomodule.c @@ -280,6 +280,10 @@ errno_exec(PyObject *module) #ifdef ENOANO add_errcode("ENOANO", ENOANO, "No anode"); #endif +#if defined(__wasi__) && !defined(ESHUTDOWN) + // WASI SDK 16 does not have ESHUTDOWN, shutdown results in EPIPE. + #define ESHUTDOWN EPIPE +#endif #ifdef ESHUTDOWN add_errcode("ESHUTDOWN", ESHUTDOWN, "Cannot send after transport endpoint shutdown"); #else diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 40229bce0f4033..ddd9237ce97ec3 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -7373,7 +7373,7 @@ os_openpty_impl(PyObject *module) #define HAVE_FALLBACK_LOGIN_TTY 1 #endif /* defined(HAVE_SETSID) && defined(TIOCSCTTY) */ -#if defined(HAVE_LOGIN_TTY) || defined(HAVE_FALLBACK_LOGIN_TTY) +#if (defined(HAVE_LOGIN_TTY) || defined(HAVE_FALLBACK_LOGIN_TTY)) && defined(HAVE_DUP2) /*[clinic input] os.login_tty @@ -9316,7 +9316,7 @@ os_dup_impl(PyObject *module, int fd) return _Py_dup(fd); } - +#if defined(HAVE_DUP2) || defined(HAVE_DUP3) /*[clinic input] os.dup2 -> int fd: int @@ -9416,6 +9416,7 @@ os_dup2_impl(PyObject *module, int fd, int fd2, int inheritable) return res; } +#endif #ifdef HAVE_LOCKF diff --git a/Modules/selectmodule.c b/Modules/selectmodule.c index 5c36eaaedeb70b..ae39d5f31aa475 100644 --- a/Modules/selectmodule.c +++ b/Modules/selectmodule.c @@ -63,6 +63,10 @@ extern void bzero(void *, int); # define SOCKET int #endif +#if defined(__wasi__) && !defined(POLLPRI) +# define POLLPRI 0 +#endif + typedef struct { PyObject *close; PyTypeObject *poll_Type; diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c index 9b4155e164f107..5530e30cff5038 100644 --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -256,7 +256,9 @@ shutdown(how) -- shut down traffic in one or both directions\n\ #ifndef MS_WINDOWS /* Non-MS WINDOWS includes */ -# include +# ifdef HAVE_NETDB_H +# include +# endif # include /* Headers needed for inet_ntoa() and inet_addr() */ @@ -434,15 +436,41 @@ remove_unusable_flags(PyObject *m) /* I know this is a bad practice, but it is the easiest... */ #if !defined(HAVE_GETADDRINFO) /* avoid clashes with the C library definition of the symbol. */ -#define getaddrinfo fake_getaddrinfo -#define gai_strerror fake_gai_strerror -#define freeaddrinfo fake_freeaddrinfo -#include "getaddrinfo.c" +# define getaddrinfo fake_getaddrinfo +# define gai_strerror fake_gai_strerror +# define freeaddrinfo fake_freeaddrinfo +# ifdef HAVE_NETDB_H +# include "getaddrinfo.c" +# else +// dummy fallback for platforms without netdb.h +static int +getaddrinfo(const char*hostname, const char*servname, + const struct addrinfo *hints, struct addrinfo **res) +{ + *res = NULL; + errno = ENOTSUP; + return EAI_SYSTEM; +} + +static void +freeaddrinfo(struct addrinfo *ai) {} +# endif #endif + #if !defined(HAVE_GETNAMEINFO) -#define getnameinfo fake_getnameinfo -#include "getnameinfo.c" -#endif +# define getnameinfo fake_getnameinfo +# ifdef HAVE_NETDB_H +# include "getnameinfo.c" +# else +static int +getnameinfo(const struct sockaddr *sa, size_t salen, char * host, size_t hostlen, + char *serv, size_t servlen, int flags) +{ + errno = ENOTSUP; + return EAI_SYSTEM; +} +# endif +#endif // HAVE_GETNAMEINFO #ifdef MS_WINDOWS #define SOCKETCLOSE closesocket @@ -623,6 +651,7 @@ set_error(void) } +#if defined(HAVE_GETHOSTBYNAME_R) || defined (HAVE_GETHOSTBYNAME) || defined (HAVE_GETHOSTBYADDR) static PyObject * set_herror(int h_error) { @@ -640,6 +669,7 @@ set_herror(int h_error) return NULL; } +#endif static PyObject * @@ -1691,6 +1721,7 @@ idna_converter(PyObject *obj, struct maybe_idna *data) return Py_CLEANUP_SUPPORTED; } +#if defined(HAVE_BIND) || defined(HAVE_CONNECTTO) || defined(CMSG_LEN) /* Parse a socket address argument according to the socket object's address family. Return 1 if the address was in the proper format, 0 of not. The address is returned through addr_ret, its length @@ -2490,6 +2521,7 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args, } } +#endif // defined(HAVE_BIND) || defined(HAVE_CONNECTTO) || defined(CMSG_LEN) /* Get the address length according to the socket object's address family. @@ -3064,6 +3096,7 @@ Returns the timeout in seconds (float) associated with socket\n\ operations. A timeout of None indicates that timeouts on socket\n\ operations are disabled."); +#ifdef HAVE_SETSOCKOPT /* s.setsockopt() method. With an integer third argument, sets an integer optval with optlen=4. With None as third argument and an integer fourth argument, set @@ -3153,7 +3186,7 @@ setsockopt(level, option, None, optlen: int)\n\ Set a socket option. See the Unix manual for level and option.\n\ The value argument can either be an integer, a string buffer, or\n\ None, optlen."); - +#endif /* s.getsockopt() method. With two arguments, retrieves an integer option. @@ -3227,6 +3260,7 @@ If a nonzero buffersize argument is given, the return value is a\n\ string of that length; otherwise it is an integer."); +#ifdef HAVE_BIND /* s.bind(sockaddr) method */ static PyObject * @@ -3258,6 +3292,7 @@ PyDoc_STRVAR(bind_doc, Bind the socket to a local address. For IP sockets, the address is a\n\ pair (host, port); the host must refer to the local host. For raw packet\n\ sockets the address is a tuple (ifname, proto [,pkttype [,hatype [,addr]]])"); +#endif /* s.close() method. @@ -3310,6 +3345,7 @@ Close the socket object without closing the underlying file descriptor.\n\ The object cannot be used after this call, but the file descriptor\n\ can be reused for other purposes. The file descriptor is returned."); +#ifdef HAVE_CONNECT static int sock_connect_impl(PySocketSockObject *s, void* Py_UNUSED(data)) { @@ -3457,7 +3493,7 @@ PyDoc_STRVAR(connect_ex_doc, \n\ This is like connect(address), but returns an error code (the errno value)\n\ instead of raising an exception when an error occurs."); - +#endif // HAVE_CONNECT /* s.fileno() method */ @@ -3473,6 +3509,7 @@ PyDoc_STRVAR(fileno_doc, Return the integer file descriptor of the socket."); +#ifdef HAVE_GETSOCKNAME /* s.getsockname() method */ static PyObject * @@ -3500,6 +3537,7 @@ PyDoc_STRVAR(getsockname_doc, Return the address of the local endpoint. The format depends on the\n\ address family. For IPv4 sockets, the address info is a pair\n\ (hostaddr, port)."); +#endif #ifdef HAVE_GETPEERNAME /* Cray APP doesn't have this :-( */ @@ -3533,6 +3571,7 @@ info is a pair (hostaddr, port)."); #endif /* HAVE_GETPEERNAME */ +#ifdef HAVE_LISTEN /* s.listen(n) method */ static PyObject * @@ -3565,6 +3604,8 @@ Enable a server to accept connections. If backlog is specified, it must be\n\ at least 0 (if it is lower, it is set to 0); it specifies the number of\n\ unaccepted connections that the system will allow before refusing new\n\ connections. If not specified, a default reasonable value is chosen."); +#endif + struct sock_recv { char *cbuf; @@ -3741,6 +3782,7 @@ struct sock_recvfrom { Py_ssize_t result; }; +#ifdef HAVE_RECVFROM static int sock_recvfrom_impl(PySocketSockObject *s, void *data) { @@ -3913,6 +3955,7 @@ PyDoc_STRVAR(recvfrom_into_doc, "recvfrom_into(buffer[, nbytes[, flags]]) -> (nbytes, address info)\n\ \n\ Like recv_into(buffer[, nbytes[, flags]]) but also return the sender's address info."); +#endif /* The sendmsg() and recvmsg[_into]() methods require a working CMSG_LEN(). See the comment near get_CMSG_LEN(). */ @@ -4379,6 +4422,7 @@ until all data is sent. If an error occurs, it's impossible\n\ to tell how much data has been sent."); +#ifdef HAVE_SENDTO struct sock_sendto { char *buf; Py_ssize_t len; @@ -4471,6 +4515,7 @@ PyDoc_STRVAR(sendto_doc, \n\ Like send(data, flags) but allows specifying the destination address.\n\ For IP sockets, the address is a pair (hostaddr, port)."); +#endif /* The sendmsg() and recvmsg[_into]() methods require a working @@ -5036,14 +5081,18 @@ socket.fromshare()."); static PyMethodDef sock_methods[] = { {"_accept", (PyCFunction)sock_accept, METH_NOARGS, accept_doc}, +#ifdef HAVE_BIND {"bind", (PyCFunction)sock_bind, METH_O, bind_doc}, +#endif {"close", (PyCFunction)sock_close, METH_NOARGS, sock_close_doc}, +#ifdef HAVE_CONNECT {"connect", (PyCFunction)sock_connect, METH_O, connect_doc}, {"connect_ex", (PyCFunction)sock_connect_ex, METH_O, connect_ex_doc}, +#endif {"detach", (PyCFunction)sock_detach, METH_NOARGS, detach_doc}, {"fileno", (PyCFunction)sock_fileno, METH_NOARGS, @@ -5052,8 +5101,10 @@ static PyMethodDef sock_methods[] = { {"getpeername", (PyCFunction)sock_getpeername, METH_NOARGS, getpeername_doc}, #endif +#ifdef HAVE_GETSOCKNAME {"getsockname", (PyCFunction)sock_getsockname, METH_NOARGS, getsockname_doc}, +#endif {"getsockopt", (PyCFunction)sock_getsockopt, METH_VARARGS, getsockopt_doc}, #if defined(MS_WINDOWS) && defined(SIO_RCVALL) @@ -5064,22 +5115,28 @@ static PyMethodDef sock_methods[] = { {"share", (PyCFunction)sock_share, METH_VARARGS, sock_share_doc}, #endif +#ifdef HAVE_LISTEN {"listen", (PyCFunction)sock_listen, METH_VARARGS, listen_doc}, +#endif {"recv", (PyCFunction)sock_recv, METH_VARARGS, recv_doc}, {"recv_into", _PyCFunction_CAST(sock_recv_into), METH_VARARGS | METH_KEYWORDS, recv_into_doc}, +#ifdef HAVE_RECVFROM {"recvfrom", (PyCFunction)sock_recvfrom, METH_VARARGS, recvfrom_doc}, {"recvfrom_into", _PyCFunction_CAST(sock_recvfrom_into), METH_VARARGS | METH_KEYWORDS, recvfrom_into_doc}, +#endif {"send", (PyCFunction)sock_send, METH_VARARGS, send_doc}, {"sendall", (PyCFunction)sock_sendall, METH_VARARGS, sendall_doc}, +#ifdef HAVE_SENDTO {"sendto", (PyCFunction)sock_sendto, METH_VARARGS, sendto_doc}, +#endif {"setblocking", (PyCFunction)sock_setblocking, METH_O, setblocking_doc}, {"getblocking", (PyCFunction)sock_getblocking, METH_NOARGS, @@ -5088,8 +5145,10 @@ static PyMethodDef sock_methods[] = { settimeout_doc}, {"gettimeout", (PyCFunction)sock_gettimeout, METH_NOARGS, gettimeout_doc}, +#ifdef HAVE_SETSOCKOPT {"setsockopt", (PyCFunction)sock_setsockopt, METH_VARARGS, setsockopt_doc}, +#endif #ifdef HAVE_SHUTDOWN {"shutdown", (PyCFunction)sock_shutdown, METH_O, shutdown_doc}, @@ -5225,6 +5284,15 @@ static int sock_cloexec_works = -1; /*ARGSUSED*/ +#ifndef HAVE_SOCKET +static int +socket(int domain, int type, int protocol) +{ + errno = ENOTSUP; + return INVALID_SOCKET; +} +#endif + /*[clinic input] _socket.socket.__init__ as sock_initobj family: int = -1 @@ -5311,6 +5379,7 @@ sock_initobj_impl(PySocketSockObject *self, int family, int type, int proto, socklen_t addrlen = sizeof(sock_addr_t); memset(&addrbuf, 0, addrlen); +#ifdef HAVE_GETSOCKNAME if (getsockname(fd, SAS2SA(&addrbuf), &addrlen) == 0) { if (family == -1) { family = SAS2SA(&addrbuf)->sa_family; @@ -5329,6 +5398,7 @@ sock_initobj_impl(PySocketSockObject *self, int family, int type, int proto, return -1; } } +#endif // HAVE_GETSOCKNAME #ifdef SO_TYPE if (type == -1) { int tmp; @@ -5507,6 +5577,7 @@ static PyTypeObject sock_type = { }; +#ifdef HAVE_GETHOSTNAME /* Python interface to gethostname(). */ /*ARGSUSED*/ @@ -5570,6 +5641,7 @@ PyDoc_STRVAR(gethostname_doc, "gethostname() -> string\n\ \n\ Return the current host name."); +#endif #ifdef HAVE_SETHOSTNAME PyDoc_STRVAR(sethostname_doc, @@ -5655,6 +5727,7 @@ sock_decode_hostname(const char *name) #endif } +#if defined(HAVE_GETHOSTBYNAME_R) || defined (HAVE_GETHOSTBYNAME) || defined (HAVE_GETHOSTBYADDR) /* Convenience function common to gethostbyname_ex and gethostbyaddr */ static PyObject * @@ -5783,8 +5856,9 @@ gethost_common(struct hostent *h, struct sockaddr *addr, size_t alen, int af) Py_XDECREF(addr_list); return rtn_tuple; } +#endif - +#if defined(HAVE_GETHOSTBYNAME_R) || defined (HAVE_GETHOSTBYNAME) /* Python interface to gethostbyname_ex(name). */ /*ARGSUSED*/ @@ -5857,8 +5931,9 @@ PyDoc_STRVAR(ghbn_ex_doc, \n\ Return the true host name, a list of aliases, and a list of IP addresses,\n\ for a host. The host argument is a string giving a host name or IP number."); +#endif - +#if defined(HAVE_GETHOSTBYNAME_R) || defined (HAVE_GETHOSTBYADDR) /* Python interface to gethostbyaddr(IP). */ /*ARGSUSED*/ @@ -5953,8 +6028,9 @@ PyDoc_STRVAR(gethostbyaddr_doc, \n\ Return the true host name, a list of aliases, and a list of IP addresses,\n\ for a host. The host argument is a string giving a host name or IP number."); +#endif - +#ifdef HAVE_GETSERVBYNAME /* Python interface to getservbyname(name). This only returns the port number, since the other info is already known or not useful (like the list of aliases). */ @@ -5988,8 +6064,9 @@ PyDoc_STRVAR(getservbyname_doc, Return a port number from a service name and protocol name.\n\ The optional protocol name, if given, should be 'tcp' or 'udp',\n\ otherwise any protocol will match."); +#endif - +#ifdef HAVE_GETSERVBYPORT /* Python interface to getservbyport(port). This only returns the service name, since the other info is already known or not useful (like the list of aliases). */ @@ -6030,7 +6107,9 @@ PyDoc_STRVAR(getservbyport_doc, Return the service name from a port number and protocol name.\n\ The optional protocol name, if given, should be 'tcp' or 'udp',\n\ otherwise any protocol will match."); +#endif +#ifdef HAVE_GETPROTOBYNAME /* Python interface to getprotobyname(name). This only returns the protocol number, since the other info is already known or not useful (like the list of aliases). */ @@ -6057,6 +6136,7 @@ PyDoc_STRVAR(getprotobyname_doc, "getprotobyname(name) -> integer\n\ \n\ Return the protocol number for the named protocol. (Rarely used.)"); +#endif static PyObject * socket_close(PyObject *self, PyObject *fdobj) @@ -6426,6 +6506,7 @@ socket_inet_aton(PyObject *self, PyObject *args) #endif } +#ifdef HAVE_INET_NTOA PyDoc_STRVAR(inet_ntoa_doc, "inet_ntoa(packed_ip) -> ip_address_string\n\ \n\ @@ -6454,6 +6535,7 @@ socket_inet_ntoa(PyObject *self, PyObject *args) SUPPRESS_DEPRECATED_CALL return PyUnicode_FromString(inet_ntoa(packed_addr)); } +#endif // HAVE_INET_NTOA #ifdef HAVE_INET_PTON @@ -7051,22 +7133,34 @@ range of values."); static PyMethodDef socket_methods[] = { {"gethostbyname", socket_gethostbyname, METH_VARARGS, gethostbyname_doc}, +#if defined(HAVE_GETHOSTBYNAME_R) || defined (HAVE_GETHOSTBYNAME) {"gethostbyname_ex", socket_gethostbyname_ex, METH_VARARGS, ghbn_ex_doc}, +#endif +#if defined(HAVE_GETHOSTBYNAME_R) || defined (HAVE_GETHOSTBYADDR) {"gethostbyaddr", socket_gethostbyaddr, METH_VARARGS, gethostbyaddr_doc}, +#endif +#ifdef HAVE_GETHOSTNAME {"gethostname", socket_gethostname, METH_NOARGS, gethostname_doc}, +#endif #ifdef HAVE_SETHOSTNAME {"sethostname", socket_sethostname, METH_VARARGS, sethostname_doc}, #endif +#ifdef HAVE_GETSERVBYNAME {"getservbyname", socket_getservbyname, METH_VARARGS, getservbyname_doc}, +#endif +#ifdef HAVE_GETSERVBYPORT {"getservbyport", socket_getservbyport, METH_VARARGS, getservbyport_doc}, +#endif +#ifdef HAVE_GETPROTOBYNAME {"getprotobyname", socket_getprotobyname, METH_VARARGS, getprotobyname_doc}, +#endif {"close", socket_close, METH_O, close_doc}, #ifndef NO_DUP @@ -7087,8 +7181,10 @@ static PyMethodDef socket_methods[] = { METH_O, htonl_doc}, {"inet_aton", socket_inet_aton, METH_VARARGS, inet_aton_doc}, +#ifdef HAVE_INET_NTOA {"inet_ntoa", socket_inet_ntoa, METH_VARARGS, inet_ntoa_doc}, +#endif #ifdef HAVE_INET_PTON {"inet_pton", socket_inet_pton, METH_VARARGS, inet_pton_doc}, @@ -7628,7 +7724,9 @@ PyInit__socket(void) /* SOCK_RAW is marked as optional in the POSIX specification */ PyModule_AddIntMacro(m, SOCK_RAW); #endif +#ifdef SOCK_SEQPACKET PyModule_AddIntMacro(m, SOCK_SEQPACKET); +#endif #if defined(SOCK_RDM) PyModule_AddIntMacro(m, SOCK_RDM); #endif @@ -7786,6 +7884,9 @@ PyInit__socket(void) PyModule_AddIntMacro(m, MSG_EOR); #endif #ifdef MSG_TRUNC +# if defined(__wasi__) && !defined(__WASI_RIFLAGS_RECV_DATA_TRUNCATED) +# define __WASI_RIFLAGS_RECV_DATA_TRUNCATED 2 +#endif PyModule_AddIntMacro(m, MSG_TRUNC); #endif #ifdef MSG_CTRUNC diff --git a/PC/pyconfig.h b/PC/pyconfig.h index 87d55fa07e51e3..0a274dad610743 100644 --- a/PC/pyconfig.h +++ b/PC/pyconfig.h @@ -675,8 +675,28 @@ Py_NO_ENABLE_SHARED to find out. Also support MS_NO_COREDLL for b/w compat */ /* Define to 1 if you have the `erfc' function. */ #define HAVE_ERFC 1 -/* Define if you have the 'inet_pton' function. */ +// netdb.h functions +#define HAVE_NETDB_H 1 +#define HAVE_GETHOSTNAME 1 +#define HAVE_GETHOSTBYADDR 1 +#define HAVE_GETHOSTBYNAME 1 +#define HAVE_GETPROTOBYNAME 1 +#define HAVE_GETSERVBYNAME 1 +#define HAVE_GETSERVBYPORT 1 +// sys/socket.h functions #define HAVE_INET_PTON 1 +#define HAVE_INET_NTOA 1 +#define HAVE_BIND 1 +#define HAVE_CONNECT 1 +#define HAVE_GETSOCKNAME 1 +#define HAVE_LISTEN 1 +#define HAVE_RECVFROM 1 +#define HAVE_SENDTO 1 +#define HAVE_SETSOCKOPT 1 +#define HAVE_SOCKET 1 + +/* Define to 1 if you have the `dup2' function. */ +#define HAVE_DUP2 1 /* framework name */ #define _PYTHONFRAMEWORK "" @@ -685,3 +705,4 @@ Py_NO_ENABLE_SHARED to find out. Also support MS_NO_COREDLL for b/w compat */ #define HAVE_X509_VERIFY_PARAM_SET1_HOST 1 #endif /* !Py_CONFIG_H */ + diff --git a/Python/dup2.c b/Python/dup2.c index 7c6bbfce11dbf8..63507f3334d44a 100644 --- a/Python/dup2.c +++ b/Python/dup2.c @@ -16,6 +16,7 @@ #define BADEXIT -1 +#ifdef F_DUPFD int dup2(int fd1, int fd2) { @@ -29,3 +30,4 @@ dup2(int fd1, int fd2) } return fd2; } +#endif diff --git a/Python/fileutils.c b/Python/fileutils.c index 7e5d01f6e63d3b..fb1e5ef9a03026 100644 --- a/Python/fileutils.c +++ b/Python/fileutils.c @@ -2366,7 +2366,7 @@ _Py_dup(int fd) return -1; } -#else +#elif HAVE_DUP Py_BEGIN_ALLOW_THREADS _Py_BEGIN_SUPPRESS_IPH fd = dup(fd); @@ -2383,6 +2383,10 @@ _Py_dup(int fd) _Py_END_SUPPRESS_IPH return -1; } +#else + errno = ENOTSUP; + PyErr_SetFromErrno(PyExc_OSError); + return -1; #endif return fd; } diff --git a/Python/thread_pthread.h b/Python/thread_pthread.h index c310d72abd2d58..4617b9f8ea3912 100644 --- a/Python/thread_pthread.h +++ b/Python/thread_pthread.h @@ -7,7 +7,67 @@ #if defined(__APPLE__) || defined(HAVE_PTHREAD_DESTRUCTOR) #define destructor xxdestructor #endif + +#ifdef HAVE_PTHREAD_H +# include +#elif defined(HAVE_PTHREAD_STUBS) +# include "cpython/pthread_stubs.h" +#endif + +#ifdef HAVE_PTHREAD_STUBS +#include "pycore_condvar.h" // stubs +#ifdef __wasi__ +#define __NEED_pthread_t 1 +#define __NEED_pthread_attr_t 1 +#define __NEED_pthread_key_t 1 +#include +#else +#error "HAVE_PTHREAD_STUBS not defined for this platform" +#endif + +#define PTHREAD_MAX_KEYS 256 +void* __pthread_key_values[PTHREAD_MAX_KEYS]; +size_t __pthread_key_next_slot; + +int +pthread_key_create(pthread_key_t *out, void (*destructor)(void *a)) +{ + if (destructor != NULL) { + errno = EAGAIN; + return -1; + } + if (__pthread_key_next_slot >= PTHREAD_MAX_KEYS) { + errno = EAGAIN; + return -1; + } + void** key = &__pthread_key_values[__pthread_key_next_slot++]; + *out = (pthread_key_t)key; + return 0; +} + +int +pthread_key_delete(pthread_key_t key) +{ + return 0; +} + +void* +pthread_getspecific(pthread_key_t key) +{ + return *(void**)key; +} + +int +pthread_setspecific(pthread_key_t key, const void *value) +{ + *(void**)key = (void*)value; + return 0; +} + +#else #include +#endif + #if defined(__APPLE__) || defined(HAVE_PTHREAD_DESTRUCTOR) #undef destructor #endif diff --git a/configure b/configure index d607c5e5d37a03..80b02c049ca4bc 100755 --- a/configure +++ b/configure @@ -9054,7 +9054,7 @@ for ac_header in \ alloca.h asm/types.h bluetooth.h conio.h crypt.h direct.h dlfcn.h endian.h errno.h fcntl.h grp.h \ ieeefp.h io.h langinfo.h libintl.h libutil.h linux/auxvec.h sys/auxv.h linux/fs.h linux/memfd.h \ linux/random.h linux/soundcard.h \ - linux/tipc.h linux/wait.h netinet/in.h netpacket/packet.h poll.h process.h pthread.h pty.h \ + linux/tipc.h linux/wait.h netdb.h netinet/in.h netpacket/packet.h poll.h process.h pthread.h pty.h \ sched.h setjmp.h shadow.h signal.h spawn.h stropts.h sys/audioio.h sys/bsdtty.h sys/devpoll.h \ sys/endian.h sys/epoll.h sys/event.h sys/eventfd.h sys/file.h sys/ioctl.h sys/kern_control.h \ sys/loadavg.h sys/lock.h sys/memfd.h sys/mkdev.h sys/mman.h sys/modem.h sys/param.h sys/poll.h \ @@ -14744,11 +14744,16 @@ if test "x$ac_cv_lib_cma_pthread_create" = xyes; then : else + case $ac_sys_system in #( + WASI) : + posix_threads=stub ;; #( + *) : as_fn_error $? "could not find pthreads on your system" "$LINENO" 5 + ;; +esac fi - fi fi @@ -14906,6 +14911,13 @@ done fi +if test "x$posix_threads" = xstub; then : + + +$as_echo "#define HAVE_PTHREAD_STUBS 1" >>confdefs.h + + +fi # Check for enable-ipv6 @@ -15549,7 +15561,7 @@ for ac_func in \ faccessat fchmod fchmodat fchown fchownat fdopendir fdwalk fexecve \ fork fork1 fpathconf fstatat ftime ftruncate futimens futimes futimesat \ gai_strerror getegid getentropy geteuid getgid getgrgid getgrgid_r \ - getgrnam_r getgrouplist getgroups getitimer getloadavg getlogin \ + getgrnam_r getgrouplist getgroups gethostname getitimer getloadavg getlogin \ getpeername getpgid getpid getppid getpriority _getpty \ getpwent getpwnam_r getpwuid getpwuid_r getresgid getresuid getrusage getsid getspent \ getspnam getuid getwd if_nameindex initgroups kill killpg lchown linkat \ @@ -15567,7 +15579,7 @@ for ac_func in \ sigwaitinfo snprintf splice strftime strlcpy strsignal symlinkat sync \ sysconf system tcgetpgrp tcsetpgrp tempnam timegm times tmpfile \ tmpnam tmpnam_r truncate ttyname umask uname unlinkat utimensat utimes vfork \ - wait wait3 wait4 waitid waitpid wcscoll wcsftime wcsxfrm wmemcmp writev \ + wait3 wait4 waitid wcscoll wcsftime wcsxfrm wmemcmp writev \ do : as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` @@ -15978,6 +15990,78 @@ fi + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for wait" >&5 +$as_echo_n "checking for wait... " >&6; } +if ${ac_cv_func_wait+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +int +main () +{ +void *x=wait + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_cv_func_wait=yes +else + ac_cv_func_wait=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_func_wait" >&5 +$as_echo "$ac_cv_func_wait" >&6; } + if test "x$ac_cv_func_wait" = xyes; then : + +$as_echo "#define HAVE_WAIT 1" >>confdefs.h + +fi + + + + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for waitpid" >&5 +$as_echo_n "checking for waitpid... " >&6; } +if ${ac_cv_func_waitpid+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +int +main () +{ +void *x=waitpid + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_cv_func_waitpid=yes +else + ac_cv_func_waitpid=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_func_waitpid" >&5 +$as_echo "$ac_cv_func_waitpid" >&6; } + if test "x$ac_cv_func_waitpid" = xyes; then : + +$as_echo "#define HAVE_WAITPID 1" >>confdefs.h + +fi + + + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for _dyld_shared_cache_contains_path" >&5 $as_echo_n "checking for _dyld_shared_cache_contains_path... " >&6; } @@ -17352,125 +17436,32 @@ $as_echo "yes" >&6; } have_liblzma=yes fi - - - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for hstrerror" >&5 -$as_echo_n "checking for hstrerror... " >&6; } -if ${ac_cv_func_hstrerror+:} false; then : - $as_echo_n "(cached) " >&6 -else - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ -#include -int -main () -{ -void *x=hstrerror - ; - return 0; -} -_ACEOF -if ac_fn_c_try_compile "$LINENO"; then : - ac_cv_func_hstrerror=yes -else - ac_cv_func_hstrerror=no -fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext - -fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_func_hstrerror" >&5 -$as_echo "$ac_cv_func_hstrerror" >&6; } - if test "x$ac_cv_func_hstrerror" = xyes; then : - -$as_echo "#define HAVE_HSTRERROR 1" >>confdefs.h - -fi - - - - - - - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for inet_aton" >&5 -$as_echo_n "checking for inet_aton... " >&6; } -if ${ac_cv_func_inet_aton+:} false; then : - $as_echo_n "(cached) " >&6 -else - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ - -#include -#include -#include -#include - -int -main () -{ -void *x=inet_aton - ; - return 0; -} +for ac_func in hstrerror getservbyname getservbyport gethostbyname gethostaddr getprotobyname +do : + as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` +ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var" +if eval test \"x\$"$as_ac_var"\" = x"yes"; then : + cat >>confdefs.h <<_ACEOF +#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1 _ACEOF -if ac_fn_c_try_compile "$LINENO"; then : - ac_cv_func_inet_aton=yes -else - ac_cv_func_inet_aton=no -fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_func_inet_aton" >&5 -$as_echo "$ac_cv_func_inet_aton" >&6; } - if test "x$ac_cv_func_inet_aton" = xyes; then : - -$as_echo "#define HAVE_INET_ATON 1" >>confdefs.h - -fi - - - - - - - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for inet_pton" >&5 -$as_echo_n "checking for inet_pton... " >&6; } -if ${ac_cv_func_inet_pton+:} false; then : - $as_echo_n "(cached) " >&6 -else - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ +done -#include -#include -#include -#include +for ac_func in \ + inet_aton inet_ntoa inet_pton getpeername getsockname bind connect \ + listen recvfrom sendto setsockopt socket \ -int -main () -{ -void *x=inet_pton - ; - return 0; -} +do : + as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` +ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var" +if eval test \"x\$"$as_ac_var"\" = x"yes"; then : + cat >>confdefs.h <<_ACEOF +#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1 _ACEOF -if ac_fn_c_try_compile "$LINENO"; then : - ac_cv_func_inet_pton=yes -else - ac_cv_func_inet_pton=no -fi -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_func_inet_pton" >&5 -$as_echo "$ac_cv_func_inet_pton" >&6; } - if test "x$ac_cv_func_inet_pton" = xyes; then : - -$as_echo "#define HAVE_INET_PTON 1" >>confdefs.h - -fi - - +done # On some systems, setgroups is in unistd.h, on others, in grp.h diff --git a/configure.ac b/configure.ac index c5924169e03a0b..cec9291929701c 100644 --- a/configure.ac +++ b/configure.ac @@ -2643,7 +2643,7 @@ AC_CHECK_HEADERS([ \ alloca.h asm/types.h bluetooth.h conio.h crypt.h direct.h dlfcn.h endian.h errno.h fcntl.h grp.h \ ieeefp.h io.h langinfo.h libintl.h libutil.h linux/auxvec.h sys/auxv.h linux/fs.h linux/memfd.h \ linux/random.h linux/soundcard.h \ - linux/tipc.h linux/wait.h netinet/in.h netpacket/packet.h poll.h process.h pthread.h pty.h \ + linux/tipc.h linux/wait.h netdb.h netinet/in.h netpacket/packet.h poll.h process.h pthread.h pty.h \ sched.h setjmp.h shadow.h signal.h spawn.h stropts.h sys/audioio.h sys/bsdtty.h sys/devpoll.h \ sys/endian.h sys/epoll.h sys/event.h sys/eventfd.h sys/file.h sys/ioctl.h sys/kern_control.h \ sys/loadavg.h sys/lock.h sys/memfd.h sys/mkdev.h sys/mman.h sys/modem.h sys/param.h sys/poll.h \ @@ -4207,9 +4207,11 @@ pthread_create (NULL, NULL, start_routine, NULL)]])],[ posix_threads=yes LIBS="$LIBS -lcma" ],[ - AC_MSG_ERROR([could not find pthreads on your system]) - ]) - ])])])])]) + AS_CASE([$ac_sys_system], + [WASI], [posix_threads=stub], + [AC_MSG_ERROR([could not find pthreads on your system])] + ) + ])])])])])]) AC_CHECK_LIB(mpc, usconfig, [ LIBS="$LIBS -lmpc" @@ -4272,6 +4274,9 @@ if test "$posix_threads" = "yes"; then AC_CHECK_FUNCS(pthread_getcpuclockid) fi +AS_VAR_IF([posix_threads], [stub], [ + AC_DEFINE([HAVE_PTHREAD_STUBS], [1], [Define if platform requires stubbed pthread]) +]) # Check for enable-ipv6 AH_TEMPLATE(ENABLE_IPV6, [Define if --enable-ipv6 is specified]) @@ -4657,7 +4662,7 @@ AC_CHECK_FUNCS([ \ faccessat fchmod fchmodat fchown fchownat fdopendir fdwalk fexecve \ fork fork1 fpathconf fstatat ftime ftruncate futimens futimes futimesat \ gai_strerror getegid getentropy geteuid getgid getgrgid getgrgid_r \ - getgrnam_r getgrouplist getgroups getitimer getloadavg getlogin \ + getgrnam_r getgrouplist getgroups gethostname getitimer getloadavg getlogin \ getpeername getpgid getpid getppid getpriority _getpty \ getpwent getpwnam_r getpwuid getpwuid_r getresgid getresuid getrusage getsid getspent \ getspnam getuid getwd if_nameindex initgroups kill killpg lchown linkat \ @@ -4675,7 +4680,7 @@ AC_CHECK_FUNCS([ \ sigwaitinfo snprintf splice strftime strlcpy strsignal symlinkat sync \ sysconf system tcgetpgrp tcsetpgrp tempnam timegm times tmpfile \ tmpnam tmpnam_r truncate ttyname umask uname unlinkat utimensat utimes vfork \ - wait wait3 wait4 waitid waitpid wcscoll wcsftime wcsxfrm wmemcmp writev \ + wait3 wait4 waitid wcscoll wcsftime wcsxfrm wmemcmp writev \ ]) # Force lchmod off for Linux. Linux disallows changing the mode of symbolic @@ -4709,6 +4714,8 @@ PY_CHECK_FUNC([prlimit], [ #include #include ]) +PY_CHECK_FUNC([wait], [#include ]) +PY_CHECK_FUNC([waitpid], [#include ]) PY_CHECK_FUNC([_dyld_shared_cache_contains_path], [#include ], [HAVE_DYLD_SHARED_CACHE_CONTAINS_PATH]) @@ -4880,20 +4887,13 @@ PKG_CHECK_MODULES([LIBLZMA], [liblzma], [have_liblzma=yes], [ ]) ]) -PY_CHECK_FUNC([hstrerror], [#include ]) - -PY_CHECK_FUNC([inet_aton], [ -#include -#include -#include -#include -]) - -PY_CHECK_FUNC([inet_pton], [ -#include -#include -#include -#include +dnl WASI does not implement most socket APIs yet. +dnl netdb.h function +AC_CHECK_FUNCS([hstrerror getservbyname getservbyport gethostbyname gethostaddr getprotobyname]) +dnl sys/socket.h functions +AC_CHECK_FUNCS([ \ + inet_aton inet_ntoa inet_pton getpeername getsockname bind connect \ + listen recvfrom sendto setsockopt socket \ ]) # On some systems, setgroups is in unistd.h, on others, in grp.h diff --git a/pyconfig.h.in b/pyconfig.h.in index aa9fc559fa2511..7273dccd401ed6 100644 --- a/pyconfig.h.in +++ b/pyconfig.h.in @@ -81,6 +81,9 @@ /* Define to 1 if you have the `atanh' function. */ #undef HAVE_ATANH +/* Define to 1 if you have the `bind' function. */ +#undef HAVE_BIND + /* Define to 1 if you have the `bind_textdomain_codeset' function. */ #undef HAVE_BIND_TEXTDOMAIN_CODESET @@ -160,6 +163,9 @@ /* Define to 1 if you have the header file. */ #undef HAVE_CONIO_H +/* Define to 1 if you have the `connect' function. */ +#undef HAVE_CONNECT + /* Define to 1 if you have the `copy_file_range' function. */ #undef HAVE_COPY_FILE_RANGE @@ -477,6 +483,9 @@ /* Define to 1 if you have the `getgroups' function. */ #undef HAVE_GETGROUPS +/* Define to 1 if you have the `gethostaddr' function. */ +#undef HAVE_GETHOSTADDR + /* Define to 1 if you have the `gethostbyname' function. */ #undef HAVE_GETHOSTBYNAME @@ -492,6 +501,9 @@ /* Define this if you have the 6-arg version of gethostbyname_r(). */ #undef HAVE_GETHOSTBYNAME_R_6_ARG +/* Define to 1 if you have the `gethostname' function. */ +#undef HAVE_GETHOSTNAME + /* Define to 1 if you have the `getitimer' function. */ #undef HAVE_GETITIMER @@ -525,6 +537,9 @@ /* Define to 1 if you have the `getpriority' function. */ #undef HAVE_GETPRIORITY +/* Define to 1 if you have the `getprotobyname' function. */ +#undef HAVE_GETPROTOBYNAME + /* Define to 1 if you have the `getpwent' function. */ #undef HAVE_GETPWENT @@ -552,9 +567,18 @@ /* Define to 1 if you have the `getrusage' function. */ #undef HAVE_GETRUSAGE +/* Define to 1 if you have the `getservbyname' function. */ +#undef HAVE_GETSERVBYNAME + +/* Define to 1 if you have the `getservbyport' function. */ +#undef HAVE_GETSERVBYPORT + /* Define to 1 if you have the `getsid' function. */ #undef HAVE_GETSID +/* Define to 1 if you have the `getsockname' function. */ +#undef HAVE_GETSOCKNAME + /* Define to 1 if you have the `getspent' function. */ #undef HAVE_GETSPENT @@ -574,7 +598,7 @@ /* Define to 1 if you have the header file. */ #undef HAVE_GRP_H -/* Define if you have the 'hstrerror' function. */ +/* Define to 1 if you have the `hstrerror' function. */ #undef HAVE_HSTRERROR /* Define this if you have le64toh() */ @@ -586,10 +610,13 @@ /* Define to 1 if you have the `if_nameindex' function. */ #undef HAVE_IF_NAMEINDEX -/* Define if you have the 'inet_aton' function. */ +/* Define to 1 if you have the `inet_aton' function. */ #undef HAVE_INET_ATON -/* Define if you have the 'inet_pton' function. */ +/* Define to 1 if you have the `inet_ntoa' function. */ +#undef HAVE_INET_NTOA + +/* Define to 1 if you have the `inet_pton' function. */ #undef HAVE_INET_PTON /* Define to 1 if you have the `initgroups' function. */ @@ -715,6 +742,9 @@ /* Define to 1 if you have the header file. */ #undef HAVE_LINUX_WAIT_H +/* Define to 1 if you have the `listen' function. */ +#undef HAVE_LISTEN + /* Define to 1 if you have the `lockf' function. */ #undef HAVE_LOCKF @@ -799,6 +829,9 @@ /* Define to 1 if you have the header file. */ #undef HAVE_NETCAN_CAN_H +/* Define to 1 if you have the header file. */ +#undef HAVE_NETDB_H + /* Define to 1 if you have the header file. */ #undef HAVE_NETINET_IN_H @@ -899,6 +932,9 @@ /* Define to 1 if you have the `pthread_sigmask' function. */ #undef HAVE_PTHREAD_SIGMASK +/* Define if platform requires stubbed pthread */ +#undef HAVE_PTHREAD_STUBS + /* Define to 1 if you have the header file. */ #undef HAVE_PTY_H @@ -926,6 +962,9 @@ /* Define to 1 if you have the `realpath' function. */ #undef HAVE_REALPATH +/* Define to 1 if you have the `recvfrom' function. */ +#undef HAVE_RECVFROM + /* Define to 1 if you have the `renameat' function. */ #undef HAVE_RENAMEAT @@ -995,6 +1034,9 @@ /* Define to 1 if you have the `sendfile' function. */ #undef HAVE_SENDFILE +/* Define to 1 if you have the `sendto' function. */ +#undef HAVE_SENDTO + /* Define to 1 if you have the `setegid' function. */ #undef HAVE_SETEGID @@ -1043,6 +1085,9 @@ /* Define to 1 if you have the `setsid' function. */ #undef HAVE_SETSID +/* Define to 1 if you have the `setsockopt' function. */ +#undef HAVE_SETSOCKOPT + /* Define to 1 if you have the `setuid' function. */ #undef HAVE_SETUID @@ -1106,6 +1151,9 @@ /* struct sockaddr_storage (sys/socket.h) */ #undef HAVE_SOCKADDR_STORAGE +/* Define to 1 if you have the `socket' function. */ +#undef HAVE_SOCKET + /* Define if you have the 'socketpair' function. */ #undef HAVE_SOCKETPAIR @@ -1421,7 +1469,7 @@ /* Define to 1 if you have the `vfork' function. */ #undef HAVE_VFORK -/* Define to 1 if you have the `wait' function. */ +/* Define if you have the 'wait' function. */ #undef HAVE_WAIT /* Define to 1 if you have the `wait3' function. */ @@ -1433,7 +1481,7 @@ /* Define to 1 if you have the `waitid' function. */ #undef HAVE_WAITID -/* Define to 1 if you have the `waitpid' function. */ +/* Define if you have the 'waitpid' function. */ #undef HAVE_WAITPID /* Define if the compiler provides a wchar.h header file. */