From 4bc0bf2ac3b4e1bc85ef9b1994cdaacbaa2461ed Mon Sep 17 00:00:00 2001 From: Christian Heimes Date: Fri, 22 Jul 2022 13:55:39 +0200 Subject: [PATCH 01/13] WASI: Remove missing function --- Modules/socketmodule.c | 20 +- PC/pyconfig.h | 16 ++ configure | 403 +++++++++++++++++++++++++++++++++++++++++ configure.ac | 13 ++ pyconfig.h.in | 15 ++ 5 files changed, 465 insertions(+), 2 deletions(-) diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c index 9b4155e164f107..5fe307ad4612df 100644 --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -5954,7 +5954,7 @@ PyDoc_STRVAR(gethostbyaddr_doc, 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."); - +#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 +5988,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 +6031,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 +6060,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 +6430,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 +6459,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 @@ -7053,20 +7059,28 @@ static PyMethodDef socket_methods[] = { METH_VARARGS, gethostbyname_doc}, {"gethostbyname_ex", socket_gethostbyname_ex, METH_VARARGS, ghbn_ex_doc}, +#ifdef HAVE_GETHOSTBYADDR {"gethostbyaddr", socket_gethostbyaddr, METH_VARARGS, gethostbyaddr_doc}, +#endif {"gethostname", socket_gethostname, METH_NOARGS, gethostname_doc}, #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 +7101,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}, diff --git a/PC/pyconfig.h b/PC/pyconfig.h index 87d55fa07e51e3..9428fa5971b011 100644 --- a/PC/pyconfig.h +++ b/PC/pyconfig.h @@ -678,6 +678,21 @@ Py_NO_ENABLE_SHARED to find out. Also support MS_NO_COREDLL for b/w compat */ /* Define if you have the 'inet_pton' function. */ #define HAVE_INET_PTON 1 +/* Define if you have the 'gethostbyaddr' function. */ +#define HAVE_GETHOSTBYADDR 1 + +/* Define if you have the 'getprotobyname' function. */ +#define HAVE_GETPROTOBYNAME 1 + +/* Define if you have the 'getservbyname' function. */ +#define HAVE_GETSERVBYNAME 1 + +/* Define if you have the 'getservbyport' function. */ +#define HAVE_GETSERVBYPORT 1 + +/* Define if you have the 'inet_ntoa' function. */ +#define HAVE_INET_NTOA 1 + /* framework name */ #define _PYTHONFRAMEWORK "" @@ -685,3 +700,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/configure b/configure index d607c5e5d37a03..2492c0b83edef6 100755 --- a/configure +++ b/configure @@ -17433,6 +17433,48 @@ fi + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for inet_ntoa" >&5 +$as_echo_n "checking for inet_ntoa... " >&6; } +if ${ac_cv_func_inet_ntoa+:} 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_ntoa + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_cv_func_inet_ntoa=yes +else + ac_cv_func_inet_ntoa=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_ntoa" >&5 +$as_echo "$ac_cv_func_inet_ntoa" >&6; } + if test "x$ac_cv_func_inet_ntoa" = xyes; then : + +$as_echo "#define HAVE_INET_NTOA 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 : @@ -17473,6 +17515,367 @@ fi + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for getservbyname" >&5 +$as_echo_n "checking for getservbyname... " >&6; } +if ${ac_cv_func_getservbyname+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +int +main () +{ +void *x=getservbyname + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_cv_func_getservbyname=yes +else + ac_cv_func_getservbyname=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_getservbyname" >&5 +$as_echo "$ac_cv_func_getservbyname" >&6; } + if test "x$ac_cv_func_getservbyname" = xyes; then : + +$as_echo "#define HAVE_GETSERVBYNAME 1" >>confdefs.h + +fi + + + + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for gethostbyname" >&5 +$as_echo_n "checking for gethostbyname... " >&6; } +if ${ac_cv_func_gethostbyname+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +int +main () +{ +void *x=gethostbyname + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_cv_func_gethostbyname=yes +else + ac_cv_func_gethostbyname=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_gethostbyname" >&5 +$as_echo "$ac_cv_func_gethostbyname" >&6; } + if test "x$ac_cv_func_gethostbyname" = xyes; then : + +$as_echo "#define HAVE_GETHOSTBYNAME 1" >>confdefs.h + +fi + + + + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for gethostbyaddr" >&5 +$as_echo_n "checking for gethostbyaddr... " >&6; } +if ${ac_cv_func_gethostbyaddr+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +int +main () +{ +void *x=gethostbyaddr + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_cv_func_gethostbyaddr=yes +else + ac_cv_func_gethostbyaddr=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_gethostbyaddr" >&5 +$as_echo "$ac_cv_func_gethostbyaddr" >&6; } + if test "x$ac_cv_func_gethostbyaddr" = xyes; then : + +$as_echo "#define HAVE_GETHOSTBYADDR 1" >>confdefs.h + +fi + + + + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for getservbyport" >&5 +$as_echo_n "checking for getservbyport... " >&6; } +if ${ac_cv_func_getservbyport+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +int +main () +{ +void *x=getservbyport + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_cv_func_getservbyport=yes +else + ac_cv_func_getservbyport=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_getservbyport" >&5 +$as_echo "$ac_cv_func_getservbyport" >&6; } + if test "x$ac_cv_func_getservbyport" = xyes; then : + +$as_echo "#define HAVE_GETSERVBYPORT 1" >>confdefs.h + +fi + + + + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for gethostbyaddr" >&5 +$as_echo_n "checking for gethostbyaddr... " >&6; } +if ${ac_cv_func_gethostbyaddr+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +int +main () +{ +void *x=gethostbyaddr + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_cv_func_gethostbyaddr=yes +else + ac_cv_func_gethostbyaddr=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_gethostbyaddr" >&5 +$as_echo "$ac_cv_func_gethostbyaddr" >&6; } + if test "x$ac_cv_func_gethostbyaddr" = xyes; then : + +$as_echo "#define HAVE_GETHOSTBYADDR 1" >>confdefs.h + +fi + + + + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for gethostbyname" >&5 +$as_echo_n "checking for gethostbyname... " >&6; } +if ${ac_cv_func_gethostbyname+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +int +main () +{ +void *x=gethostbyname + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_cv_func_gethostbyname=yes +else + ac_cv_func_gethostbyname=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_gethostbyname" >&5 +$as_echo "$ac_cv_func_gethostbyname" >&6; } + if test "x$ac_cv_func_gethostbyname" = xyes; then : + +$as_echo "#define HAVE_GETHOSTBYNAME 1" >>confdefs.h + +fi + + + + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for gethostbyaddr" >&5 +$as_echo_n "checking for gethostbyaddr... " >&6; } +if ${ac_cv_func_gethostbyaddr+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +int +main () +{ +void *x=gethostbyaddr + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_cv_func_gethostbyaddr=yes +else + ac_cv_func_gethostbyaddr=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_gethostbyaddr" >&5 +$as_echo "$ac_cv_func_gethostbyaddr" >&6; } + if test "x$ac_cv_func_gethostbyaddr" = xyes; then : + +$as_echo "#define HAVE_GETHOSTBYADDR 1" >>confdefs.h + +fi + + + + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for getservbyname" >&5 +$as_echo_n "checking for getservbyname... " >&6; } +if ${ac_cv_func_getservbyname+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +int +main () +{ +void *x=getservbyname + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_cv_func_getservbyname=yes +else + ac_cv_func_getservbyname=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_getservbyname" >&5 +$as_echo "$ac_cv_func_getservbyname" >&6; } + if test "x$ac_cv_func_getservbyname" = xyes; then : + +$as_echo "#define HAVE_GETSERVBYNAME 1" >>confdefs.h + +fi + + + + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for getservbyport" >&5 +$as_echo_n "checking for getservbyport... " >&6; } +if ${ac_cv_func_getservbyport+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +int +main () +{ +void *x=getservbyport + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_cv_func_getservbyport=yes +else + ac_cv_func_getservbyport=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_getservbyport" >&5 +$as_echo "$ac_cv_func_getservbyport" >&6; } + if test "x$ac_cv_func_getservbyport" = xyes; then : + +$as_echo "#define HAVE_GETSERVBYPORT 1" >>confdefs.h + +fi + + + + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for getprotobyname" >&5 +$as_echo_n "checking for getprotobyname... " >&6; } +if ${ac_cv_func_getprotobyname+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +int +main () +{ +void *x=getprotobyname + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_cv_func_getprotobyname=yes +else + ac_cv_func_getprotobyname=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_getprotobyname" >&5 +$as_echo "$ac_cv_func_getprotobyname" >&6; } + if test "x$ac_cv_func_getprotobyname" = xyes; then : + +$as_echo "#define HAVE_GETPROTOBYNAME 1" >>confdefs.h + +fi + + + + # On some systems, setgroups is in unistd.h, on others, in grp.h diff --git a/configure.ac b/configure.ac index c5924169e03a0b..e7f20db140c7a3 100644 --- a/configure.ac +++ b/configure.ac @@ -4889,6 +4889,13 @@ PY_CHECK_FUNC([inet_aton], [ #include ]) +PY_CHECK_FUNC([inet_ntoa], [ +#include +#include +#include +#include +]) + PY_CHECK_FUNC([inet_pton], [ #include #include @@ -4896,6 +4903,12 @@ PY_CHECK_FUNC([inet_pton], [ #include ]) +PY_CHECK_FUNC([getservbyname], [#include ]) +PY_CHECK_FUNC([getservbyport], [#include ]) +PY_CHECK_FUNC([gethostbyname], [#include ]) +PY_CHECK_FUNC([gethostbyaddr], [#include ]) +PY_CHECK_FUNC([getprotobyname], [#include ]) + # On some systems, setgroups is in unistd.h, on others, in grp.h PY_CHECK_FUNC([setgroups], [ #include diff --git a/pyconfig.h.in b/pyconfig.h.in index aa9fc559fa2511..dd5291ce7639fb 100644 --- a/pyconfig.h.in +++ b/pyconfig.h.in @@ -477,6 +477,9 @@ /* Define to 1 if you have the `getgroups' function. */ #undef HAVE_GETGROUPS +/* Define if you have the 'gethostbyaddr' function. */ +#undef HAVE_GETHOSTBYADDR + /* Define to 1 if you have the `gethostbyname' function. */ #undef HAVE_GETHOSTBYNAME @@ -525,6 +528,9 @@ /* Define to 1 if you have the `getpriority' function. */ #undef HAVE_GETPRIORITY +/* Define if you have the 'getprotobyname' function. */ +#undef HAVE_GETPROTOBYNAME + /* Define to 1 if you have the `getpwent' function. */ #undef HAVE_GETPWENT @@ -552,6 +558,12 @@ /* Define to 1 if you have the `getrusage' function. */ #undef HAVE_GETRUSAGE +/* Define if you have the 'getservbyname' function. */ +#undef HAVE_GETSERVBYNAME + +/* Define if you have the 'getservbyport' function. */ +#undef HAVE_GETSERVBYPORT + /* Define to 1 if you have the `getsid' function. */ #undef HAVE_GETSID @@ -589,6 +601,9 @@ /* Define if you have the 'inet_aton' function. */ #undef HAVE_INET_ATON +/* Define if you have the 'inet_ntoa' function. */ +#undef HAVE_INET_NTOA + /* Define if you have the 'inet_pton' function. */ #undef HAVE_INET_PTON From c26d1fd1312c7e30d1b69b14593623da27ba5212 Mon Sep 17 00:00:00 2001 From: Christian Heimes Date: Fri, 22 Jul 2022 15:29:43 +0200 Subject: [PATCH 02/13] More socket related functions --- Modules/addrinfo.h | 25 +++ Modules/selectmodule.c | 4 + Modules/socketmodule.c | 105 +++++++++-- PC/pyconfig.h | 27 +++ configure | 408 +++++++++++++++++++++++++++++++++-------- configure.ac | 52 +++++- pyconfig.h.in | 33 +++- 7 files changed, 558 insertions(+), 96 deletions(-) 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/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 5fe307ad4612df..caef3e8a68639c 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 * @@ -3064,6 +3094,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 +3184,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 +3258,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 +3290,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 +3343,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 +3491,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 +3507,7 @@ PyDoc_STRVAR(fileno_doc, Return the integer file descriptor of the socket."); +#ifdef HAVE_GETSOCKNAME /* s.getsockname() method */ static PyObject * @@ -3500,6 +3535,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 +3569,7 @@ info is a pair (hostaddr, port)."); #endif /* HAVE_GETPEERNAME */ +#ifdef HAVE_LISTEN /* s.listen(n) method */ static PyObject * @@ -3565,6 +3602,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 +3780,7 @@ struct sock_recvfrom { Py_ssize_t result; }; +#ifdef HAVE_RECVFROM static int sock_recvfrom_impl(PySocketSockObject *s, void *data) { @@ -3913,6 +3953,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 +4420,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 +4513,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 +5079,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 +5099,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 +5113,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 +5143,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 +5282,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 +5377,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 +5396,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; @@ -5655,6 +5723,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 +5852,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 +5927,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,6 +6024,7 @@ 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). @@ -7057,9 +7129,11 @@ 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}, -#ifdef HAVE_GETHOSTBYADDR +#endif +#if defined(HAVE_GETHOSTBYNAME_R) || defined (HAVE_GETHOSTBYADDR) {"gethostbyaddr", socket_gethostbyaddr, METH_VARARGS, gethostbyaddr_doc}, #endif @@ -7644,7 +7718,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 @@ -7802,6 +7878,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 9428fa5971b011..a606c0b5b991c5 100644 --- a/PC/pyconfig.h +++ b/PC/pyconfig.h @@ -678,6 +678,9 @@ Py_NO_ENABLE_SHARED to find out. Also support MS_NO_COREDLL for b/w compat */ /* Define if you have the 'inet_pton' function. */ #define HAVE_INET_PTON 1 +/* Define to 1 if you have the header file. */ +#define HAVE_NETDB_H 1 + /* Define if you have the 'gethostbyaddr' function. */ #define HAVE_GETHOSTBYADDR 1 @@ -693,6 +696,30 @@ Py_NO_ENABLE_SHARED to find out. Also support MS_NO_COREDLL for b/w compat */ /* Define if you have the 'inet_ntoa' function. */ #define HAVE_INET_NTOA 1 +/* Define if you have the 'bind' function. */ +#define HAVE_BIND 1 + +/* Define if you have the 'connect' function. */ +#define HAVE_CONNECT 1 + +/* Define if you have the 'getsockname' function. */ +#define HAVE_GETSOCKNAME 1 + +/* Define if you have the 'listen' function. */ +#define HAVE_LISTEN 1 + +/* Define if you have the 'recvfrom' function. */ +#define HAVE_RECVFROM 1 + +/* Define if you have the 'sendto' function. */ +#define HAVE_SENDTO 1 + +/* Define if you have the 'setsockopt' function. */ +#define HAVE_SETSOCKOPT 1 + +/* Define if you have the 'socket' function. */ +#define HAVE_SOCKET 1 + /* framework name */ #define _PYTHONFRAMEWORK "" diff --git a/configure b/configure index 2492c0b83edef6..31578e163d1ab7 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 \ @@ -15567,7 +15567,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 +15978,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 &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 &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; } @@ -17553,6 +17625,42 @@ fi + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for getservbyport" >&5 +$as_echo_n "checking for getservbyport... " >&6; } +if ${ac_cv_func_getservbyport+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +int +main () +{ +void *x=getservbyport + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_cv_func_getservbyport=yes +else + ac_cv_func_getservbyport=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_getservbyport" >&5 +$as_echo "$ac_cv_func_getservbyport" >&6; } + if test "x$ac_cv_func_getservbyport" = xyes; then : + +$as_echo "#define HAVE_GETSERVBYPORT 1" >>confdefs.h + +fi + + + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for gethostbyname" >&5 $as_echo_n "checking for gethostbyname... " >&6; } if ${ac_cv_func_gethostbyname+:} false; then : @@ -17625,9 +17733,9 @@ fi - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for getservbyport" >&5 -$as_echo_n "checking for getservbyport... " >&6; } -if ${ac_cv_func_getservbyport+:} false; then : + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for getprotobyname" >&5 +$as_echo_n "checking for getprotobyname... " >&6; } +if ${ac_cv_func_getprotobyname+:} false; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext @@ -17636,24 +17744,24 @@ else int main () { -void *x=getservbyport +void *x=getprotobyname ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : - ac_cv_func_getservbyport=yes + ac_cv_func_getprotobyname=yes else - ac_cv_func_getservbyport=no + ac_cv_func_getprotobyname=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_getservbyport" >&5 -$as_echo "$ac_cv_func_getservbyport" >&6; } - if test "x$ac_cv_func_getservbyport" = xyes; then : +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_func_getprotobyname" >&5 +$as_echo "$ac_cv_func_getprotobyname" >&6; } + if test "x$ac_cv_func_getprotobyname" = xyes; then : -$as_echo "#define HAVE_GETSERVBYPORT 1" >>confdefs.h +$as_echo "#define HAVE_GETPROTOBYNAME 1" >>confdefs.h fi @@ -17661,35 +17769,39 @@ fi - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for gethostbyaddr" >&5 -$as_echo_n "checking for gethostbyaddr... " >&6; } -if ${ac_cv_func_gethostbyaddr+:} false; then : + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for getpeername" >&5 +$as_echo_n "checking for getpeername... " >&6; } +if ${ac_cv_func_getpeername+:} false; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ -#include + +#include +#include + int main () { -void *x=gethostbyaddr +void *x=getpeername ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : - ac_cv_func_gethostbyaddr=yes + ac_cv_func_getpeername=yes else - ac_cv_func_gethostbyaddr=no + ac_cv_func_getpeername=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_gethostbyaddr" >&5 -$as_echo "$ac_cv_func_gethostbyaddr" >&6; } - if test "x$ac_cv_func_gethostbyaddr" = xyes; then : +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_func_getpeername" >&5 +$as_echo "$ac_cv_func_getpeername" >&6; } + if test "x$ac_cv_func_getpeername" = xyes; then : -$as_echo "#define HAVE_GETHOSTBYADDR 1" >>confdefs.h +$as_echo "#define HAVE_GETPEERNAME 1" >>confdefs.h fi @@ -17697,35 +17809,39 @@ fi - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for gethostbyname" >&5 -$as_echo_n "checking for gethostbyname... " >&6; } -if ${ac_cv_func_gethostbyname+:} false; then : + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for getsockname" >&5 +$as_echo_n "checking for getsockname... " >&6; } +if ${ac_cv_func_getsockname+:} false; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ -#include + +#include +#include + int main () { -void *x=gethostbyname +void *x=getsockname ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : - ac_cv_func_gethostbyname=yes + ac_cv_func_getsockname=yes else - ac_cv_func_gethostbyname=no + ac_cv_func_getsockname=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_gethostbyname" >&5 -$as_echo "$ac_cv_func_gethostbyname" >&6; } - if test "x$ac_cv_func_gethostbyname" = xyes; then : +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_func_getsockname" >&5 +$as_echo "$ac_cv_func_getsockname" >&6; } + if test "x$ac_cv_func_getsockname" = xyes; then : -$as_echo "#define HAVE_GETHOSTBYNAME 1" >>confdefs.h +$as_echo "#define HAVE_GETSOCKNAME 1" >>confdefs.h fi @@ -17733,35 +17849,39 @@ fi - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for gethostbyaddr" >&5 -$as_echo_n "checking for gethostbyaddr... " >&6; } -if ${ac_cv_func_gethostbyaddr+:} false; then : + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for bind" >&5 +$as_echo_n "checking for bind... " >&6; } +if ${ac_cv_func_bind+:} false; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ -#include + +#include +#include + int main () { -void *x=gethostbyaddr +void *x=bind ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : - ac_cv_func_gethostbyaddr=yes + ac_cv_func_bind=yes else - ac_cv_func_gethostbyaddr=no + ac_cv_func_bind=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_gethostbyaddr" >&5 -$as_echo "$ac_cv_func_gethostbyaddr" >&6; } - if test "x$ac_cv_func_gethostbyaddr" = xyes; then : +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_func_bind" >&5 +$as_echo "$ac_cv_func_bind" >&6; } + if test "x$ac_cv_func_bind" = xyes; then : -$as_echo "#define HAVE_GETHOSTBYADDR 1" >>confdefs.h +$as_echo "#define HAVE_BIND 1" >>confdefs.h fi @@ -17769,35 +17889,39 @@ fi - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for getservbyname" >&5 -$as_echo_n "checking for getservbyname... " >&6; } -if ${ac_cv_func_getservbyname+:} false; then : + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for connect" >&5 +$as_echo_n "checking for connect... " >&6; } +if ${ac_cv_func_connect+:} false; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ -#include + +#include +#include + int main () { -void *x=getservbyname +void *x=connect ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : - ac_cv_func_getservbyname=yes + ac_cv_func_connect=yes else - ac_cv_func_getservbyname=no + ac_cv_func_connect=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_getservbyname" >&5 -$as_echo "$ac_cv_func_getservbyname" >&6; } - if test "x$ac_cv_func_getservbyname" = xyes; then : +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_func_connect" >&5 +$as_echo "$ac_cv_func_connect" >&6; } + if test "x$ac_cv_func_connect" = xyes; then : -$as_echo "#define HAVE_GETSERVBYNAME 1" >>confdefs.h +$as_echo "#define HAVE_CONNECT 1" >>confdefs.h fi @@ -17805,35 +17929,39 @@ fi - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for getservbyport" >&5 -$as_echo_n "checking for getservbyport... " >&6; } -if ${ac_cv_func_getservbyport+:} false; then : + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for listen" >&5 +$as_echo_n "checking for listen... " >&6; } +if ${ac_cv_func_listen+:} false; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ -#include + +#include +#include + int main () { -void *x=getservbyport +void *x=listen ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : - ac_cv_func_getservbyport=yes + ac_cv_func_listen=yes else - ac_cv_func_getservbyport=no + ac_cv_func_listen=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_getservbyport" >&5 -$as_echo "$ac_cv_func_getservbyport" >&6; } - if test "x$ac_cv_func_getservbyport" = xyes; then : +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_func_listen" >&5 +$as_echo "$ac_cv_func_listen" >&6; } + if test "x$ac_cv_func_listen" = xyes; then : -$as_echo "#define HAVE_GETSERVBYPORT 1" >>confdefs.h +$as_echo "#define HAVE_LISTEN 1" >>confdefs.h fi @@ -17841,35 +17969,159 @@ fi - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for getprotobyname" >&5 -$as_echo_n "checking for getprotobyname... " >&6; } -if ${ac_cv_func_getprotobyname+:} false; then : + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for recvfrom" >&5 +$as_echo_n "checking for recvfrom... " >&6; } +if ${ac_cv_func_recvfrom+:} false; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ -#include + +#include +#include + int main () { -void *x=getprotobyname +void *x=recvfrom ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : - ac_cv_func_getprotobyname=yes + ac_cv_func_recvfrom=yes else - ac_cv_func_getprotobyname=no + ac_cv_func_recvfrom=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_getprotobyname" >&5 -$as_echo "$ac_cv_func_getprotobyname" >&6; } - if test "x$ac_cv_func_getprotobyname" = xyes; then : +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_func_recvfrom" >&5 +$as_echo "$ac_cv_func_recvfrom" >&6; } + if test "x$ac_cv_func_recvfrom" = xyes; then : -$as_echo "#define HAVE_GETPROTOBYNAME 1" >>confdefs.h +$as_echo "#define HAVE_RECVFROM 1" >>confdefs.h + +fi + + + + + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for sendto" >&5 +$as_echo_n "checking for sendto... " >&6; } +if ${ac_cv_func_sendto+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +#include +#include + +int +main () +{ +void *x=sendto + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_cv_func_sendto=yes +else + ac_cv_func_sendto=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_sendto" >&5 +$as_echo "$ac_cv_func_sendto" >&6; } + if test "x$ac_cv_func_sendto" = xyes; then : + +$as_echo "#define HAVE_SENDTO 1" >>confdefs.h + +fi + + + + + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for setsockopt" >&5 +$as_echo_n "checking for setsockopt... " >&6; } +if ${ac_cv_func_setsockopt+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +#include +#include + +int +main () +{ +void *x=setsockopt + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_cv_func_setsockopt=yes +else + ac_cv_func_setsockopt=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_setsockopt" >&5 +$as_echo "$ac_cv_func_setsockopt" >&6; } + if test "x$ac_cv_func_setsockopt" = xyes; then : + +$as_echo "#define HAVE_SETSOCKOPT 1" >>confdefs.h + +fi + + + + + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for socket" >&5 +$as_echo_n "checking for socket... " >&6; } +if ${ac_cv_func_socket+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +#include +#include + +int +main () +{ +void *x=socket + ; + return 0; +} +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + ac_cv_func_socket=yes +else + ac_cv_func_socket=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_socket" >&5 +$as_echo "$ac_cv_func_socket" >&6; } + if test "x$ac_cv_func_socket" = xyes; then : + +$as_echo "#define HAVE_SOCKET 1" >>confdefs.h fi diff --git a/configure.ac b/configure.ac index e7f20db140c7a3..a370566dc7d1c0 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 \ @@ -4675,7 +4675,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 +4709,8 @@ PY_CHECK_FUNC([prlimit], [ #include #include ]) +PY_CHECK_FUNC([wait], [#include ], [HAVE_DYLD_SHARED_CACHE_CONTAINS_PATH]) @@ -4903,12 +4905,58 @@ PY_CHECK_FUNC([inet_pton], [ #include ]) +dnl socket function that are not available on WASI PY_CHECK_FUNC([getservbyname], [#include ]) PY_CHECK_FUNC([getservbyport], [#include ]) PY_CHECK_FUNC([gethostbyname], [#include ]) PY_CHECK_FUNC([gethostbyaddr], [#include ]) PY_CHECK_FUNC([getprotobyname], [#include ]) +PY_CHECK_FUNC([getpeername], [ +#include +#include +]) + +PY_CHECK_FUNC([getsockname], [ +#include +#include +]) + +PY_CHECK_FUNC([bind], [ +#include +#include +]) + +PY_CHECK_FUNC([connect], [ +#include +#include +]) + +PY_CHECK_FUNC([listen], [ +#include +#include +]) + +PY_CHECK_FUNC([recvfrom], [ +#include +#include +]) + +PY_CHECK_FUNC([sendto], [ +#include +#include +]) + +PY_CHECK_FUNC([setsockopt], [ +#include +#include +]) + +PY_CHECK_FUNC([socket], [ +#include +#include +]) + # On some systems, setgroups is in unistd.h, on others, in grp.h PY_CHECK_FUNC([setgroups], [ #include diff --git a/pyconfig.h.in b/pyconfig.h.in index dd5291ce7639fb..e1b334de273d8e 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 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 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 @@ -510,7 +516,7 @@ /* Define if you have the 'getpagesize' function. */ #undef HAVE_GETPAGESIZE -/* Define to 1 if you have the `getpeername' function. */ +/* Define if you have the 'getpeername' function. */ #undef HAVE_GETPEERNAME /* Define to 1 if you have the `getpgid' function. */ @@ -567,6 +573,9 @@ /* Define to 1 if you have the `getsid' function. */ #undef HAVE_GETSID +/* Define if you have the 'getsockname' function. */ +#undef HAVE_GETSOCKNAME + /* Define to 1 if you have the `getspent' function. */ #undef HAVE_GETSPENT @@ -730,6 +739,9 @@ /* Define to 1 if you have the header file. */ #undef HAVE_LINUX_WAIT_H +/* Define if you have the 'listen' function. */ +#undef HAVE_LISTEN + /* Define to 1 if you have the `lockf' function. */ #undef HAVE_LOCKF @@ -814,6 +826,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 @@ -941,6 +956,9 @@ /* Define to 1 if you have the `realpath' function. */ #undef HAVE_REALPATH +/* Define if you have the 'recvfrom' function. */ +#undef HAVE_RECVFROM + /* Define to 1 if you have the `renameat' function. */ #undef HAVE_RENAMEAT @@ -1010,6 +1028,9 @@ /* Define to 1 if you have the `sendfile' function. */ #undef HAVE_SENDFILE +/* Define if you have the 'sendto' function. */ +#undef HAVE_SENDTO + /* Define to 1 if you have the `setegid' function. */ #undef HAVE_SETEGID @@ -1058,6 +1079,9 @@ /* Define to 1 if you have the `setsid' function. */ #undef HAVE_SETSID +/* Define if you have the 'setsockopt' function. */ +#undef HAVE_SETSOCKOPT + /* Define to 1 if you have the `setuid' function. */ #undef HAVE_SETUID @@ -1121,6 +1145,9 @@ /* struct sockaddr_storage (sys/socket.h) */ #undef HAVE_SOCKADDR_STORAGE +/* Define if you have the 'socket' function. */ +#undef HAVE_SOCKET + /* Define if you have the 'socketpair' function. */ #undef HAVE_SOCKETPAIR @@ -1436,7 +1463,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. */ @@ -1448,7 +1475,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. */ From 493d35f231ec446bf4aa655a1e867f7b0e1074d7 Mon Sep 17 00:00:00 2001 From: Christian Heimes Date: Fri, 22 Jul 2022 17:19:13 +0200 Subject: [PATCH 03/13] dup and socket --- Lib/asyncore.py | 14 +++++++++++--- Lib/test/test_exception_hierarchy.py | 5 ++++- Modules/clinic/posixmodule.c.h | 14 +++++++++++--- Modules/posixmodule.c | 5 +++-- Modules/socketmodule.c | 6 ++++++ PC/pyconfig.h | 3 +++ Python/dup2.c | 2 ++ Python/fileutils.c | 6 +++++- configure | 2 +- configure.ac | 2 +- pyconfig.h.in | 3 +++ 11 files changed, 50 insertions(+), 12 deletions(-) diff --git a/Lib/asyncore.py b/Lib/asyncore.py index 57c86871f3dcf0..4efff8faa1cffe 100644 --- a/Lib/asyncore.py +++ b/Lib/asyncore.py @@ -46,6 +46,7 @@ sophisticated high-performance network servers and clients a snap. """ +from builtins import frozenset import select import socket import sys @@ -54,16 +55,23 @@ import os from errno import EALREADY, EINPROGRESS, EWOULDBLOCK, ECONNRESET, EINVAL, \ - ENOTCONN, ESHUTDOWN, EISCONN, EBADF, ECONNABORTED, EPIPE, EAGAIN, \ + ENOTCONN, EISCONN, EBADF, ECONNABORTED, EPIPE, EAGAIN, \ errorcode _DEPRECATION_MSG = ('The {name} module is deprecated and will be removed in ' 'Python {remove}. The recommended replacement is asyncio') warnings._deprecated(__name__, _DEPRECATION_MSG, remove=(3, 12)) +_DISCONNECTED = {ECONNRESET, ENOTCONN, ECONNABORTED, EPIPE, EBADF} -_DISCONNECTED = frozenset({ECONNRESET, ENOTCONN, ESHUTDOWN, ECONNABORTED, EPIPE, - EBADF}) +try: + from errno import ESHUTDOWN +except ImportError: + pass +else: + _DISCONNECTED.add(ESHUTDOWN) + +_DISCONNECTED = frozenset(_DISCONNECTED) try: socket_map diff --git a/Lib/test/test_exception_hierarchy.py b/Lib/test/test_exception_hierarchy.py index 89fe9ddcefba3e..6d34e8ab8910ee 100644 --- a/Lib/test/test_exception_hierarchy.py +++ b/Lib/test/test_exception_hierarchy.py @@ -75,7 +75,10 @@ def _make_map(s): continue excname, _, errnames = line.partition(' ') for errname in filter(None, errnames.strip().split(', ')): - _map[getattr(errno, errname)] = getattr(builtins, excname) + errval = getattr(errno, errname, None) + if errval is None: + continue + _map[errval] = getattr(builtins, excname) return _map _map = _make_map(_pep_map) 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/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/socketmodule.c b/Modules/socketmodule.c index caef3e8a68639c..5530e30cff5038 100644 --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -1721,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 @@ -2520,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. @@ -5575,6 +5577,7 @@ static PyTypeObject sock_type = { }; +#ifdef HAVE_GETHOSTNAME /* Python interface to gethostname(). */ /*ARGSUSED*/ @@ -5638,6 +5641,7 @@ PyDoc_STRVAR(gethostname_doc, "gethostname() -> string\n\ \n\ Return the current host name."); +#endif #ifdef HAVE_SETHOSTNAME PyDoc_STRVAR(sethostname_doc, @@ -7137,8 +7141,10 @@ static PyMethodDef socket_methods[] = { {"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}, diff --git a/PC/pyconfig.h b/PC/pyconfig.h index a606c0b5b991c5..f3b6d4e08a1da5 100644 --- a/PC/pyconfig.h +++ b/PC/pyconfig.h @@ -681,6 +681,9 @@ Py_NO_ENABLE_SHARED to find out. Also support MS_NO_COREDLL for b/w compat */ /* Define to 1 if you have the header file. */ #define HAVE_NETDB_H 1 +/* Define if you have the 'gethostname' function. */ +#define HAVE_GETHOSTNAME 1 + /* Define if you have the 'gethostbyaddr' function. */ #define HAVE_GETHOSTBYADDR 1 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/configure b/configure index 31578e163d1ab7..7c3bbb2f68138a 100755 --- a/configure +++ b/configure @@ -15549,7 +15549,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 \ diff --git a/configure.ac b/configure.ac index a370566dc7d1c0..a61e3fdc6a0ff5 100644 --- a/configure.ac +++ b/configure.ac @@ -4657,7 +4657,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 \ diff --git a/pyconfig.h.in b/pyconfig.h.in index e1b334de273d8e..326825d7899a29 100644 --- a/pyconfig.h.in +++ b/pyconfig.h.in @@ -501,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 From 9ef2c7badb63f9c953fe153e8fba1021d0b7695f Mon Sep 17 00:00:00 2001 From: Christian Heimes Date: Fri, 22 Jul 2022 17:25:43 +0200 Subject: [PATCH 04/13] hack subprocess --- Lib/subprocess.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/Lib/subprocess.py b/Lib/subprocess.py index e10b01047ebef5..0287f0a3a963fe 100644 --- a/Lib/subprocess.py +++ b/Lib/subprocess.py @@ -40,6 +40,7 @@ then returns a (exitcode, output) tuple """ +from builtins import NotImplementedError import builtins import errno import io @@ -107,6 +108,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 +1900,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 +1911,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. From f9a571da5e59eae17593ecc9b2bc31975c456a23 Mon Sep 17 00:00:00 2001 From: Christian Heimes Date: Fri, 22 Jul 2022 20:34:08 +0200 Subject: [PATCH 05/13] stub pthreads --- Include/cpython/pthread_stubs.h | 138 ++++++++++++++++++++++++++++++ Include/cpython/pythread.h | 3 + Include/internal/pycore_condvar.h | 4 + Makefile.pre.in | 1 + Python/thread_pthread.h | 60 +++++++++++++ configure | 7 +- configure.ac | 11 ++- 7 files changed, 220 insertions(+), 4 deletions(-) create mode 100644 Include/cpython/pthread_stubs.h 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/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/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 7c3bbb2f68138a..919dc3899030a3 100755 --- a/configure +++ b/configure @@ -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 diff --git a/configure.ac b/configure.ac index a61e3fdc6a0ff5..79184e0723b2fb 100644 --- a/configure.ac +++ b/configure.ac @@ -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_STUB], [1], [Define if platform requires stubbed pthread]) +]) # Check for enable-ipv6 AH_TEMPLATE(ENABLE_IPV6, [Define if --enable-ipv6 is specified]) From fce8459f7fc8420607b5d2207f5c9ed44685c478 Mon Sep 17 00:00:00 2001 From: Christian Heimes Date: Fri, 22 Jul 2022 20:34:23 +0200 Subject: [PATCH 06/13] Fix uuid without gethostname --- Lib/uuid.py | 2 +- pyconfig.h.in | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) 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/pyconfig.h.in b/pyconfig.h.in index 326825d7899a29..25602d73be3ed0 100644 --- a/pyconfig.h.in +++ b/pyconfig.h.in @@ -932,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_STUB + /* Define to 1 if you have the header file. */ #undef HAVE_PTY_H From 461f0a68c06e50a44ae9f9c45d62bd1ce28f6b32 Mon Sep 17 00:00:00 2001 From: Christian Heimes Date: Fri, 22 Jul 2022 20:36:20 +0200 Subject: [PATCH 07/13] py func helpers for socket/netdb --- configure | 246 +++++++++++++++++++++++++++------------------------ configure.ac | 95 ++++++-------------- 2 files changed, 159 insertions(+), 182 deletions(-) diff --git a/configure b/configure index 919dc3899030a3..d995b37f53fd18 100755 --- a/configure +++ b/configure @@ -14911,6 +14911,13 @@ done fi +if test "x$posix_threads" = xstub; then : + + +$as_echo "#define HAVE_PTHREAD_STUB 1" >>confdefs.h + + +fi # Check for enable-ipv6 @@ -17431,6 +17438,10 @@ 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 : @@ -17467,41 +17478,35 @@ 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 "$as_me:${as_lineno-$LINENO}: checking for getservbyname" >&5 +$as_echo_n "checking for getservbyname... " >&6; } +if ${ac_cv_func_getservbyname+:} false; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ - -#include -#include -#include -#include - +#include int main () { -void *x=inet_aton +void *x=getservbyname ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : - ac_cv_func_inet_aton=yes + ac_cv_func_getservbyname=yes else - ac_cv_func_inet_aton=no + ac_cv_func_getservbyname=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 "$as_me:${as_lineno-$LINENO}: result: $ac_cv_func_getservbyname" >&5 +$as_echo "$ac_cv_func_getservbyname" >&6; } + if test "x$ac_cv_func_getservbyname" = xyes; then : -$as_echo "#define HAVE_INET_ATON 1" >>confdefs.h +$as_echo "#define HAVE_GETSERVBYNAME 1" >>confdefs.h fi @@ -17509,41 +17514,35 @@ fi - - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for inet_ntoa" >&5 -$as_echo_n "checking for inet_ntoa... " >&6; } -if ${ac_cv_func_inet_ntoa+:} false; then : + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for getservbyport" >&5 +$as_echo_n "checking for getservbyport... " >&6; } +if ${ac_cv_func_getservbyport+:} false; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ - -#include -#include -#include -#include - +#include int main () { -void *x=inet_ntoa +void *x=getservbyport ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : - ac_cv_func_inet_ntoa=yes + ac_cv_func_getservbyport=yes else - ac_cv_func_inet_ntoa=no + ac_cv_func_getservbyport=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_ntoa" >&5 -$as_echo "$ac_cv_func_inet_ntoa" >&6; } - if test "x$ac_cv_func_inet_ntoa" = xyes; then : +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_func_getservbyport" >&5 +$as_echo "$ac_cv_func_getservbyport" >&6; } + if test "x$ac_cv_func_getservbyport" = xyes; then : -$as_echo "#define HAVE_INET_NTOA 1" >>confdefs.h +$as_echo "#define HAVE_GETSERVBYPORT 1" >>confdefs.h fi @@ -17551,41 +17550,35 @@ 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 "$as_me:${as_lineno-$LINENO}: checking for gethostbyname" >&5 +$as_echo_n "checking for gethostbyname... " >&6; } +if ${ac_cv_func_gethostbyname+:} false; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ - -#include -#include -#include -#include - +#include int main () { -void *x=inet_pton +void *x=gethostbyname ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : - ac_cv_func_inet_pton=yes + ac_cv_func_gethostbyname=yes else - ac_cv_func_inet_pton=no + ac_cv_func_gethostbyname=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 "$as_me:${as_lineno-$LINENO}: result: $ac_cv_func_gethostbyname" >&5 +$as_echo "$ac_cv_func_gethostbyname" >&6; } + if test "x$ac_cv_func_gethostbyname" = xyes; then : -$as_echo "#define HAVE_INET_PTON 1" >>confdefs.h +$as_echo "#define HAVE_GETHOSTBYNAME 1" >>confdefs.h fi @@ -17593,10 +17586,9 @@ fi - - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for getservbyname" >&5 -$as_echo_n "checking for getservbyname... " >&6; } -if ${ac_cv_func_getservbyname+:} false; then : + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for gethostbyaddr" >&5 +$as_echo_n "checking for gethostbyaddr... " >&6; } +if ${ac_cv_func_gethostbyaddr+:} false; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext @@ -17605,24 +17597,24 @@ else int main () { -void *x=getservbyname +void *x=gethostbyaddr ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : - ac_cv_func_getservbyname=yes + ac_cv_func_gethostbyaddr=yes else - ac_cv_func_getservbyname=no + ac_cv_func_gethostbyaddr=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_getservbyname" >&5 -$as_echo "$ac_cv_func_getservbyname" >&6; } - if test "x$ac_cv_func_getservbyname" = xyes; then : +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_func_gethostbyaddr" >&5 +$as_echo "$ac_cv_func_gethostbyaddr" >&6; } + if test "x$ac_cv_func_gethostbyaddr" = xyes; then : -$as_echo "#define HAVE_GETSERVBYNAME 1" >>confdefs.h +$as_echo "#define HAVE_GETHOSTBYADDR 1" >>confdefs.h fi @@ -17630,9 +17622,9 @@ fi - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for getservbyport" >&5 -$as_echo_n "checking for getservbyport... " >&6; } -if ${ac_cv_func_getservbyport+:} false; then : + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for getprotobyname" >&5 +$as_echo_n "checking for getprotobyname... " >&6; } +if ${ac_cv_func_getprotobyname+:} false; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext @@ -17641,24 +17633,24 @@ else int main () { -void *x=getservbyport +void *x=getprotobyname ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : - ac_cv_func_getservbyport=yes + ac_cv_func_getprotobyname=yes else - ac_cv_func_getservbyport=no + ac_cv_func_getprotobyname=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_getservbyport" >&5 -$as_echo "$ac_cv_func_getservbyport" >&6; } - if test "x$ac_cv_func_getservbyport" = xyes; then : +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_func_getprotobyname" >&5 +$as_echo "$ac_cv_func_getprotobyname" >&6; } + if test "x$ac_cv_func_getprotobyname" = xyes; then : -$as_echo "#define HAVE_GETSERVBYPORT 1" >>confdefs.h +$as_echo "#define HAVE_GETPROTOBYNAME 1" >>confdefs.h fi @@ -17666,35 +17658,42 @@ fi - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for gethostbyname" >&5 -$as_echo_n "checking for gethostbyname... " >&6; } -if ${ac_cv_func_gethostbyname+:} false; then : + + + { $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 +#include + int main () { -void *x=gethostbyname +void *x=inet_aton ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : - ac_cv_func_gethostbyname=yes + ac_cv_func_inet_aton=yes else - ac_cv_func_gethostbyname=no + 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_gethostbyname" >&5 -$as_echo "$ac_cv_func_gethostbyname" >&6; } - if test "x$ac_cv_func_gethostbyname" = xyes; then : +{ $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_GETHOSTBYNAME 1" >>confdefs.h +$as_echo "#define HAVE_INET_ATON 1" >>confdefs.h fi @@ -17702,35 +17701,40 @@ fi - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for gethostbyaddr" >&5 -$as_echo_n "checking for gethostbyaddr... " >&6; } -if ${ac_cv_func_gethostbyaddr+:} false; then : + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for inet_ntoa" >&5 +$as_echo_n "checking for inet_ntoa... " >&6; } +if ${ac_cv_func_inet_ntoa+:} false; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ -#include + +#include +#include +#include +#include + int main () { -void *x=gethostbyaddr +void *x=inet_ntoa ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : - ac_cv_func_gethostbyaddr=yes + ac_cv_func_inet_ntoa=yes else - ac_cv_func_gethostbyaddr=no + ac_cv_func_inet_ntoa=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_gethostbyaddr" >&5 -$as_echo "$ac_cv_func_gethostbyaddr" >&6; } - if test "x$ac_cv_func_gethostbyaddr" = xyes; then : +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_func_inet_ntoa" >&5 +$as_echo "$ac_cv_func_inet_ntoa" >&6; } + if test "x$ac_cv_func_inet_ntoa" = xyes; then : -$as_echo "#define HAVE_GETHOSTBYADDR 1" >>confdefs.h +$as_echo "#define HAVE_INET_NTOA 1" >>confdefs.h fi @@ -17738,35 +17742,40 @@ fi - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for getprotobyname" >&5 -$as_echo_n "checking for getprotobyname... " >&6; } -if ${ac_cv_func_getprotobyname+:} false; then : + { $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. */ -#include + +#include +#include +#include +#include + int main () { -void *x=getprotobyname +void *x=inet_pton ; return 0; } _ACEOF if ac_fn_c_try_compile "$LINENO"; then : - ac_cv_func_getprotobyname=yes + ac_cv_func_inet_pton=yes else - ac_cv_func_getprotobyname=no + 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_getprotobyname" >&5 -$as_echo "$ac_cv_func_getprotobyname" >&6; } - if test "x$ac_cv_func_getprotobyname" = xyes; then : +{ $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_GETPROTOBYNAME 1" >>confdefs.h +$as_echo "#define HAVE_INET_PTON 1" >>confdefs.h fi @@ -17774,7 +17783,6 @@ fi - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for getpeername" >&5 $as_echo_n "checking for getpeername... " >&6; } if ${ac_cv_func_getpeername+:} false; then : @@ -17785,6 +17793,8 @@ else #include #include +#include +#include int main () @@ -17814,7 +17824,6 @@ fi - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for getsockname" >&5 $as_echo_n "checking for getsockname... " >&6; } if ${ac_cv_func_getsockname+:} false; then : @@ -17825,6 +17834,8 @@ else #include #include +#include +#include int main () @@ -17854,7 +17865,6 @@ fi - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for bind" >&5 $as_echo_n "checking for bind... " >&6; } if ${ac_cv_func_bind+:} false; then : @@ -17865,6 +17875,8 @@ else #include #include +#include +#include int main () @@ -17894,7 +17906,6 @@ fi - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for connect" >&5 $as_echo_n "checking for connect... " >&6; } if ${ac_cv_func_connect+:} false; then : @@ -17905,6 +17916,8 @@ else #include #include +#include +#include int main () @@ -17934,7 +17947,6 @@ fi - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for listen" >&5 $as_echo_n "checking for listen... " >&6; } if ${ac_cv_func_listen+:} false; then : @@ -17945,6 +17957,8 @@ else #include #include +#include +#include int main () @@ -17974,7 +17988,6 @@ fi - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for recvfrom" >&5 $as_echo_n "checking for recvfrom... " >&6; } if ${ac_cv_func_recvfrom+:} false; then : @@ -17985,6 +17998,8 @@ else #include #include +#include +#include int main () @@ -18014,7 +18029,6 @@ fi - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for sendto" >&5 $as_echo_n "checking for sendto... " >&6; } if ${ac_cv_func_sendto+:} false; then : @@ -18025,6 +18039,8 @@ else #include #include +#include +#include int main () @@ -18054,7 +18070,6 @@ fi - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for setsockopt" >&5 $as_echo_n "checking for setsockopt... " >&6; } if ${ac_cv_func_setsockopt+:} false; then : @@ -18065,6 +18080,8 @@ else #include #include +#include +#include int main () @@ -18094,7 +18111,6 @@ fi - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for socket" >&5 $as_echo_n "checking for socket... " >&6; } if ${ac_cv_func_socket+:} false; then : @@ -18105,6 +18121,8 @@ else #include #include +#include +#include int main () diff --git a/configure.ac b/configure.ac index 79184e0723b2fb..e1db07ee124da9 100644 --- a/configure.ac +++ b/configure.ac @@ -4887,80 +4887,39 @@ PKG_CHECK_MODULES([LIBLZMA], [liblzma], [have_liblzma=yes], [ ]) ]) -PY_CHECK_FUNC([hstrerror], [#include ]) +dnl PY_CHECK_NETDB_FUNC(FUNCTION) +AC_DEFUN([PY_CHECK_NETDB_FUNC], [PY_CHECK_FUNC([$1], [#include ])]) -PY_CHECK_FUNC([inet_aton], [ +dnl PY_CHECK_SOCKET_FUNC(FUNCTION) +AC_DEFUN([PY_CHECK_SOCKET_FUNC], [PY_CHECK_FUNC([$1], [ #include #include #include #include -]) - -PY_CHECK_FUNC([inet_ntoa], [ -#include -#include -#include -#include -]) - -PY_CHECK_FUNC([inet_pton], [ -#include -#include -#include -#include -]) - -dnl socket function that are not available on WASI -PY_CHECK_FUNC([getservbyname], [#include ]) -PY_CHECK_FUNC([getservbyport], [#include ]) -PY_CHECK_FUNC([gethostbyname], [#include ]) -PY_CHECK_FUNC([gethostbyaddr], [#include ]) -PY_CHECK_FUNC([getprotobyname], [#include ]) - -PY_CHECK_FUNC([getpeername], [ -#include -#include -]) - -PY_CHECK_FUNC([getsockname], [ -#include -#include -]) - -PY_CHECK_FUNC([bind], [ -#include -#include -]) - -PY_CHECK_FUNC([connect], [ -#include -#include -]) - -PY_CHECK_FUNC([listen], [ -#include -#include -]) - -PY_CHECK_FUNC([recvfrom], [ -#include -#include -]) - -PY_CHECK_FUNC([sendto], [ -#include -#include -]) - -PY_CHECK_FUNC([setsockopt], [ -#include -#include -]) +])]) -PY_CHECK_FUNC([socket], [ -#include -#include -]) +PY_CHECK_NETDB_FUNC([hstrerror]) +dnl not available in WASI yet +PY_CHECK_NETDB_FUNC([getservbyname]) +PY_CHECK_NETDB_FUNC([getservbyport]) +PY_CHECK_NETDB_FUNC([gethostbyname]) +PY_CHECK_NETDB_FUNC([gethostbyaddr]) +PY_CHECK_NETDB_FUNC([getprotobyname]) + + +PY_CHECK_SOCKET_FUNC([inet_aton]) +PY_CHECK_SOCKET_FUNC([inet_ntoa]) +PY_CHECK_SOCKET_FUNC([inet_pton]) +dnl not available in WASI yet +PY_CHECK_SOCKET_FUNC([getpeername]) +PY_CHECK_SOCKET_FUNC([getsockname]) +PY_CHECK_SOCKET_FUNC([bind]) +PY_CHECK_SOCKET_FUNC([connect]) +PY_CHECK_SOCKET_FUNC([listen]) +PY_CHECK_SOCKET_FUNC([recvfrom]) +PY_CHECK_SOCKET_FUNC([sendto]) +PY_CHECK_SOCKET_FUNC([setsockopt]) +PY_CHECK_SOCKET_FUNC([socket]) # On some systems, setgroups is in unistd.h, on others, in grp.h PY_CHECK_FUNC([setgroups], [ From 64d76b9b3ba9f5ac4c7e56d9e7397c0fd9980903 Mon Sep 17 00:00:00 2001 From: Christian Heimes Date: Fri, 22 Jul 2022 21:31:24 +0200 Subject: [PATCH 08/13] fix wait check --- configure | 4 ++-- configure.ac | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/configure b/configure index d995b37f53fd18..b7e1cc6d404545 100755 --- a/configure +++ b/configure @@ -15997,7 +15997,7 @@ if ${ac_cv_func_wait+:} false; then : else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ -#include int main () { @@ -16033,7 +16033,7 @@ if ${ac_cv_func_waitpid+:} false; then : else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ -#include int main () { diff --git a/configure.ac b/configure.ac index e1db07ee124da9..07a82951ea3ccb 100644 --- a/configure.ac +++ b/configure.ac @@ -4714,8 +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]) From 4f08a9d99a0172c80931df60fa7e45b9f3170045 Mon Sep 17 00:00:00 2001 From: Christian Heimes Date: Fri, 22 Jul 2022 21:35:58 +0200 Subject: [PATCH 09/13] Enable dup2 and gethostbyname on Windows --- PC/pyconfig.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/PC/pyconfig.h b/PC/pyconfig.h index f3b6d4e08a1da5..af5d91a9f208be 100644 --- a/PC/pyconfig.h +++ b/PC/pyconfig.h @@ -687,6 +687,9 @@ Py_NO_ENABLE_SHARED to find out. Also support MS_NO_COREDLL for b/w compat */ /* Define if you have the 'gethostbyaddr' function. */ #define HAVE_GETHOSTBYADDR 1 +/* Define if you have the 'gethostbyname' function. */ +#define HAVE_GETHOSTBYNAME 1 + /* Define if you have the 'getprotobyname' function. */ #define HAVE_GETPROTOBYNAME 1 @@ -723,6 +726,9 @@ Py_NO_ENABLE_SHARED to find out. Also support MS_NO_COREDLL for b/w compat */ /* Define if you have the 'socket' function. */ #define HAVE_SOCKET 1 +/* Define to 1 if you have the `dup2' function. */ +#define HAVE_DUP2 1 + /* framework name */ #define _PYTHONFRAMEWORK "" From 8e1914ed6154c9d4b940b22e28977a4e8ffc9b56 Mon Sep 17 00:00:00 2001 From: Christian Heimes Date: Fri, 22 Jul 2022 21:55:10 +0200 Subject: [PATCH 10/13] Stray import --- Lib/subprocess.py | 1 - 1 file changed, 1 deletion(-) diff --git a/Lib/subprocess.py b/Lib/subprocess.py index 0287f0a3a963fe..6761f942ae5aa4 100644 --- a/Lib/subprocess.py +++ b/Lib/subprocess.py @@ -40,7 +40,6 @@ then returns a (exitcode, output) tuple """ -from builtins import NotImplementedError import builtins import errno import io From 329fdb745679b88c7377e2f799f8b71f32d06d19 Mon Sep 17 00:00:00 2001 From: Christian Heimes Date: Sat, 23 Jul 2022 11:48:10 +0200 Subject: [PATCH 11/13] Use AC_CHECK_FUNCS --- PC/pyconfig.h | 37 +-- configure | 723 ++------------------------------------------------ configure.ac | 41 +-- pyconfig.h.in | 36 +-- 4 files changed, 47 insertions(+), 790 deletions(-) diff --git a/PC/pyconfig.h b/PC/pyconfig.h index af5d91a9f208be..0a274dad610743 100644 --- a/PC/pyconfig.h +++ b/PC/pyconfig.h @@ -675,55 +675,24 @@ 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. */ -#define HAVE_INET_PTON 1 - -/* Define to 1 if you have the header file. */ +// netdb.h functions #define HAVE_NETDB_H 1 - -/* Define if you have the 'gethostname' function. */ #define HAVE_GETHOSTNAME 1 - -/* Define if you have the 'gethostbyaddr' function. */ #define HAVE_GETHOSTBYADDR 1 - -/* Define if you have the 'gethostbyname' function. */ #define HAVE_GETHOSTBYNAME 1 - -/* Define if you have the 'getprotobyname' function. */ #define HAVE_GETPROTOBYNAME 1 - -/* Define if you have the 'getservbyname' function. */ #define HAVE_GETSERVBYNAME 1 - -/* Define if you have the 'getservbyport' function. */ #define HAVE_GETSERVBYPORT 1 - -/* Define if you have the 'inet_ntoa' function. */ +// sys/socket.h functions +#define HAVE_INET_PTON 1 #define HAVE_INET_NTOA 1 - -/* Define if you have the 'bind' function. */ #define HAVE_BIND 1 - -/* Define if you have the 'connect' function. */ #define HAVE_CONNECT 1 - -/* Define if you have the 'getsockname' function. */ #define HAVE_GETSOCKNAME 1 - -/* Define if you have the 'listen' function. */ #define HAVE_LISTEN 1 - -/* Define if you have the 'recvfrom' function. */ #define HAVE_RECVFROM 1 - -/* Define if you have the 'sendto' function. */ #define HAVE_SENDTO 1 - -/* Define if you have the 'setsockopt' function. */ #define HAVE_SETSOCKOPT 1 - -/* Define if you have the 'socket' function. */ #define HAVE_SOCKET 1 /* Define to 1 if you have the `dup2' function. */ diff --git a/configure b/configure index b7e1cc6d404545..f24c459551dece 100755 --- a/configure +++ b/configure @@ -17436,719 +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 getservbyname" >&5 -$as_echo_n "checking for getservbyname... " >&6; } -if ${ac_cv_func_getservbyname+:} false; then : - $as_echo_n "(cached) " >&6 -else - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ -#include -int -main () -{ -void *x=getservbyname - ; - return 0; -} -_ACEOF -if ac_fn_c_try_compile "$LINENO"; then : - ac_cv_func_getservbyname=yes -else - ac_cv_func_getservbyname=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_getservbyname" >&5 -$as_echo "$ac_cv_func_getservbyname" >&6; } - if test "x$ac_cv_func_getservbyname" = xyes; then : - -$as_echo "#define HAVE_GETSERVBYNAME 1" >>confdefs.h - -fi - - - - - - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for getservbyport" >&5 -$as_echo_n "checking for getservbyport... " >&6; } -if ${ac_cv_func_getservbyport+:} false; then : - $as_echo_n "(cached) " >&6 -else - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ -#include -int -main () -{ -void *x=getservbyport - ; - return 0; -} -_ACEOF -if ac_fn_c_try_compile "$LINENO"; then : - ac_cv_func_getservbyport=yes -else - ac_cv_func_getservbyport=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_getservbyport" >&5 -$as_echo "$ac_cv_func_getservbyport" >&6; } - if test "x$ac_cv_func_getservbyport" = xyes; then : - -$as_echo "#define HAVE_GETSERVBYPORT 1" >>confdefs.h - -fi - - - - - - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for gethostbyname" >&5 -$as_echo_n "checking for gethostbyname... " >&6; } -if ${ac_cv_func_gethostbyname+:} false; then : - $as_echo_n "(cached) " >&6 -else - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ -#include -int -main () -{ -void *x=gethostbyname - ; - return 0; -} -_ACEOF -if ac_fn_c_try_compile "$LINENO"; then : - ac_cv_func_gethostbyname=yes -else - ac_cv_func_gethostbyname=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_gethostbyname" >&5 -$as_echo "$ac_cv_func_gethostbyname" >&6; } - if test "x$ac_cv_func_gethostbyname" = xyes; then : - -$as_echo "#define HAVE_GETHOSTBYNAME 1" >>confdefs.h - -fi - - - - - - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for gethostbyaddr" >&5 -$as_echo_n "checking for gethostbyaddr... " >&6; } -if ${ac_cv_func_gethostbyaddr+:} false; then : - $as_echo_n "(cached) " >&6 -else - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ -#include -int -main () -{ -void *x=gethostbyaddr - ; - return 0; -} -_ACEOF -if ac_fn_c_try_compile "$LINENO"; then : - ac_cv_func_gethostbyaddr=yes -else - ac_cv_func_gethostbyaddr=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_gethostbyaddr" >&5 -$as_echo "$ac_cv_func_gethostbyaddr" >&6; } - if test "x$ac_cv_func_gethostbyaddr" = xyes; then : - -$as_echo "#define HAVE_GETHOSTBYADDR 1" >>confdefs.h - -fi - - - - - - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for getprotobyname" >&5 -$as_echo_n "checking for getprotobyname... " >&6; } -if ${ac_cv_func_getprotobyname+:} false; then : - $as_echo_n "(cached) " >&6 -else - cat confdefs.h - <<_ACEOF >conftest.$ac_ext -/* end confdefs.h. */ -#include -int -main () -{ -void *x=getprotobyname - ; - return 0; -} -_ACEOF -if ac_fn_c_try_compile "$LINENO"; then : - ac_cv_func_getprotobyname=yes -else - ac_cv_func_getprotobyname=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_getprotobyname" >&5 -$as_echo "$ac_cv_func_getprotobyname" >&6; } - if test "x$ac_cv_func_getprotobyname" = xyes; then : - -$as_echo "#define HAVE_GETPROTOBYNAME 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; -} -_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_ntoa" >&5 -$as_echo_n "checking for inet_ntoa... " >&6; } -if ${ac_cv_func_inet_ntoa+:} 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_ntoa - ; - return 0; -} -_ACEOF -if ac_fn_c_try_compile "$LINENO"; then : - ac_cv_func_inet_ntoa=yes -else - ac_cv_func_inet_ntoa=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_ntoa" >&5 -$as_echo "$ac_cv_func_inet_ntoa" >&6; } - if test "x$ac_cv_func_inet_ntoa" = xyes; then : - -$as_echo "#define HAVE_INET_NTOA 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. */ - -#include -#include -#include -#include - -int -main () -{ -void *x=inet_pton - ; - return 0; -} -_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 - - - - - - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for getpeername" >&5 -$as_echo_n "checking for getpeername... " >&6; } -if ${ac_cv_func_getpeername+:} 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=getpeername - ; - return 0; -} -_ACEOF -if ac_fn_c_try_compile "$LINENO"; then : - ac_cv_func_getpeername=yes -else - ac_cv_func_getpeername=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_getpeername" >&5 -$as_echo "$ac_cv_func_getpeername" >&6; } - if test "x$ac_cv_func_getpeername" = xyes; then : - -$as_echo "#define HAVE_GETPEERNAME 1" >>confdefs.h - -fi - - - - - - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for getsockname" >&5 -$as_echo_n "checking for getsockname... " >&6; } -if ${ac_cv_func_getsockname+:} 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=getsockname - ; - return 0; -} -_ACEOF -if ac_fn_c_try_compile "$LINENO"; then : - ac_cv_func_getsockname=yes -else - ac_cv_func_getsockname=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_getsockname" >&5 -$as_echo "$ac_cv_func_getsockname" >&6; } - if test "x$ac_cv_func_getsockname" = xyes; then : - -$as_echo "#define HAVE_GETSOCKNAME 1" >>confdefs.h - -fi - - - - - - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for bind" >&5 -$as_echo_n "checking for bind... " >&6; } -if ${ac_cv_func_bind+:} 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=bind - ; - return 0; -} -_ACEOF -if ac_fn_c_try_compile "$LINENO"; then : - ac_cv_func_bind=yes -else - ac_cv_func_bind=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_bind" >&5 -$as_echo "$ac_cv_func_bind" >&6; } - if test "x$ac_cv_func_bind" = xyes; then : - -$as_echo "#define HAVE_BIND 1" >>confdefs.h - -fi - - - - - - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for connect" >&5 -$as_echo_n "checking for connect... " >&6; } -if ${ac_cv_func_connect+:} 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=connect - ; - return 0; -} -_ACEOF -if ac_fn_c_try_compile "$LINENO"; then : - ac_cv_func_connect=yes -else - ac_cv_func_connect=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_connect" >&5 -$as_echo "$ac_cv_func_connect" >&6; } - if test "x$ac_cv_func_connect" = xyes; then : - -$as_echo "#define HAVE_CONNECT 1" >>confdefs.h - -fi - - - - - - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for listen" >&5 -$as_echo_n "checking for listen... " >&6; } -if ${ac_cv_func_listen+:} 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=listen - ; - return 0; -} -_ACEOF -if ac_fn_c_try_compile "$LINENO"; then : - ac_cv_func_listen=yes -else - ac_cv_func_listen=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_listen" >&5 -$as_echo "$ac_cv_func_listen" >&6; } - if test "x$ac_cv_func_listen" = xyes; then : - -$as_echo "#define HAVE_LISTEN 1" >>confdefs.h - -fi - - - - - - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for recvfrom" >&5 -$as_echo_n "checking for recvfrom... " >&6; } -if ${ac_cv_func_recvfrom+:} 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=recvfrom - ; - return 0; -} -_ACEOF -if ac_fn_c_try_compile "$LINENO"; then : - ac_cv_func_recvfrom=yes -else - ac_cv_func_recvfrom=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_recvfrom" >&5 -$as_echo "$ac_cv_func_recvfrom" >&6; } - if test "x$ac_cv_func_recvfrom" = xyes; then : - -$as_echo "#define HAVE_RECVFROM 1" >>confdefs.h - -fi - - - - - - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for sendto" >&5 -$as_echo_n "checking for sendto... " >&6; } -if ${ac_cv_func_sendto+:} 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=sendto - ; - return 0; -} -_ACEOF -if ac_fn_c_try_compile "$LINENO"; then : - ac_cv_func_sendto=yes -else - ac_cv_func_sendto=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_sendto" >&5 -$as_echo "$ac_cv_func_sendto" >&6; } - if test "x$ac_cv_func_sendto" = xyes; then : - -$as_echo "#define HAVE_SENDTO 1" >>confdefs.h - -fi - - - - - - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for setsockopt" >&5 -$as_echo_n "checking for setsockopt... " >&6; } -if ${ac_cv_func_setsockopt+:} 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=setsockopt - ; - 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_setsockopt=yes -else - ac_cv_func_setsockopt=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_setsockopt" >&5 -$as_echo "$ac_cv_func_setsockopt" >&6; } - if test "x$ac_cv_func_setsockopt" = xyes; then : - -$as_echo "#define HAVE_SETSOCKOPT 1" >>confdefs.h fi +done +for ac_func in \ + inet_aton inet_ntoa inet_pton getpeername getsockname bind connect \ + listen recvfrom sendto setsockopt socket \ - - - - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for socket" >&5 -$as_echo_n "checking for socket... " >&6; } -if ${ac_cv_func_socket+:} 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=socket - ; - 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_socket=yes -else - ac_cv_func_socket=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_socket" >&5 -$as_echo "$ac_cv_func_socket" >&6; } - if test "x$ac_cv_func_socket" = xyes; then : - -$as_echo "#define HAVE_SOCKET 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 07a82951ea3ccb..ae9e338fe3d10c 100644 --- a/configure.ac +++ b/configure.ac @@ -4887,39 +4887,14 @@ PKG_CHECK_MODULES([LIBLZMA], [liblzma], [have_liblzma=yes], [ ]) ]) -dnl PY_CHECK_NETDB_FUNC(FUNCTION) -AC_DEFUN([PY_CHECK_NETDB_FUNC], [PY_CHECK_FUNC([$1], [#include ])]) - -dnl PY_CHECK_SOCKET_FUNC(FUNCTION) -AC_DEFUN([PY_CHECK_SOCKET_FUNC], [PY_CHECK_FUNC([$1], [ -#include -#include -#include -#include -])]) - -PY_CHECK_NETDB_FUNC([hstrerror]) -dnl not available in WASI yet -PY_CHECK_NETDB_FUNC([getservbyname]) -PY_CHECK_NETDB_FUNC([getservbyport]) -PY_CHECK_NETDB_FUNC([gethostbyname]) -PY_CHECK_NETDB_FUNC([gethostbyaddr]) -PY_CHECK_NETDB_FUNC([getprotobyname]) - - -PY_CHECK_SOCKET_FUNC([inet_aton]) -PY_CHECK_SOCKET_FUNC([inet_ntoa]) -PY_CHECK_SOCKET_FUNC([inet_pton]) -dnl not available in WASI yet -PY_CHECK_SOCKET_FUNC([getpeername]) -PY_CHECK_SOCKET_FUNC([getsockname]) -PY_CHECK_SOCKET_FUNC([bind]) -PY_CHECK_SOCKET_FUNC([connect]) -PY_CHECK_SOCKET_FUNC([listen]) -PY_CHECK_SOCKET_FUNC([recvfrom]) -PY_CHECK_SOCKET_FUNC([sendto]) -PY_CHECK_SOCKET_FUNC([setsockopt]) -PY_CHECK_SOCKET_FUNC([socket]) +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 PY_CHECK_FUNC([setgroups], [ diff --git a/pyconfig.h.in b/pyconfig.h.in index 25602d73be3ed0..b3466fcb11c12b 100644 --- a/pyconfig.h.in +++ b/pyconfig.h.in @@ -81,7 +81,7 @@ /* Define to 1 if you have the `atanh' function. */ #undef HAVE_ATANH -/* Define if you have the 'bind' function. */ +/* Define to 1 if you have the `bind' function. */ #undef HAVE_BIND /* Define to 1 if you have the `bind_textdomain_codeset' function. */ @@ -163,7 +163,7 @@ /* Define to 1 if you have the header file. */ #undef HAVE_CONIO_H -/* Define if you have the 'connect' function. */ +/* Define to 1 if you have the `connect' function. */ #undef HAVE_CONNECT /* Define to 1 if you have the `copy_file_range' function. */ @@ -483,8 +483,8 @@ /* Define to 1 if you have the `getgroups' function. */ #undef HAVE_GETGROUPS -/* Define if you have the 'gethostbyaddr' function. */ -#undef HAVE_GETHOSTBYADDR +/* Define to 1 if you have the `gethostaddr' function. */ +#undef HAVE_GETHOSTADDR /* Define to 1 if you have the `gethostbyname' function. */ #undef HAVE_GETHOSTBYNAME @@ -519,7 +519,7 @@ /* Define if you have the 'getpagesize' function. */ #undef HAVE_GETPAGESIZE -/* Define if you have the 'getpeername' function. */ +/* Define to 1 if you have the `getpeername' function. */ #undef HAVE_GETPEERNAME /* Define to 1 if you have the `getpgid' function. */ @@ -537,7 +537,7 @@ /* Define to 1 if you have the `getpriority' function. */ #undef HAVE_GETPRIORITY -/* Define if you have the 'getprotobyname' function. */ +/* Define to 1 if you have the `getprotobyname' function. */ #undef HAVE_GETPROTOBYNAME /* Define to 1 if you have the `getpwent' function. */ @@ -567,16 +567,16 @@ /* Define to 1 if you have the `getrusage' function. */ #undef HAVE_GETRUSAGE -/* Define if you have the 'getservbyname' function. */ +/* Define to 1 if you have the `getservbyname' function. */ #undef HAVE_GETSERVBYNAME -/* Define if you have the 'getservbyport' function. */ +/* 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 if you have the 'getsockname' function. */ +/* Define to 1 if you have the `getsockname' function. */ #undef HAVE_GETSOCKNAME /* Define to 1 if you have the `getspent' function. */ @@ -598,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() */ @@ -610,13 +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_ntoa' function. */ +/* Define to 1 if you have the `inet_ntoa' function. */ #undef HAVE_INET_NTOA -/* Define if you have the 'inet_pton' function. */ +/* Define to 1 if you have the `inet_pton' function. */ #undef HAVE_INET_PTON /* Define to 1 if you have the `initgroups' function. */ @@ -742,7 +742,7 @@ /* Define to 1 if you have the header file. */ #undef HAVE_LINUX_WAIT_H -/* Define if you have the 'listen' function. */ +/* Define to 1 if you have the `listen' function. */ #undef HAVE_LISTEN /* Define to 1 if you have the `lockf' function. */ @@ -962,7 +962,7 @@ /* Define to 1 if you have the `realpath' function. */ #undef HAVE_REALPATH -/* Define if you have the 'recvfrom' function. */ +/* Define to 1 if you have the `recvfrom' function. */ #undef HAVE_RECVFROM /* Define to 1 if you have the `renameat' function. */ @@ -1034,7 +1034,7 @@ /* Define to 1 if you have the `sendfile' function. */ #undef HAVE_SENDFILE -/* Define if you have the 'sendto' function. */ +/* Define to 1 if you have the `sendto' function. */ #undef HAVE_SENDTO /* Define to 1 if you have the `setegid' function. */ @@ -1085,7 +1085,7 @@ /* Define to 1 if you have the `setsid' function. */ #undef HAVE_SETSID -/* Define if you have the 'setsockopt' function. */ +/* Define to 1 if you have the `setsockopt' function. */ #undef HAVE_SETSOCKOPT /* Define to 1 if you have the `setuid' function. */ @@ -1151,7 +1151,7 @@ /* struct sockaddr_storage (sys/socket.h) */ #undef HAVE_SOCKADDR_STORAGE -/* Define if you have the 'socket' function. */ +/* Define to 1 if you have the `socket' function. */ #undef HAVE_SOCKET /* Define if you have the 'socketpair' function. */ From b50b83bf3fc978b7424bf0f430fe02aa76120e55 Mon Sep 17 00:00:00 2001 From: Christian Heimes Date: Sat, 23 Jul 2022 12:36:29 +0200 Subject: [PATCH 12/13] HAVE_PTHREAD_STUBS --- configure | 2 +- configure.ac | 2 +- pyconfig.h.in | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/configure b/configure index f24c459551dece..80b02c049ca4bc 100755 --- a/configure +++ b/configure @@ -14914,7 +14914,7 @@ fi if test "x$posix_threads" = xstub; then : -$as_echo "#define HAVE_PTHREAD_STUB 1" >>confdefs.h +$as_echo "#define HAVE_PTHREAD_STUBS 1" >>confdefs.h fi diff --git a/configure.ac b/configure.ac index ae9e338fe3d10c..cec9291929701c 100644 --- a/configure.ac +++ b/configure.ac @@ -4275,7 +4275,7 @@ if test "$posix_threads" = "yes"; then fi AS_VAR_IF([posix_threads], [stub], [ - AC_DEFINE([HAVE_PTHREAD_STUB], [1], [Define if platform requires stubbed pthread]) + AC_DEFINE([HAVE_PTHREAD_STUBS], [1], [Define if platform requires stubbed pthread]) ]) # Check for enable-ipv6 diff --git a/pyconfig.h.in b/pyconfig.h.in index b3466fcb11c12b..7273dccd401ed6 100644 --- a/pyconfig.h.in +++ b/pyconfig.h.in @@ -933,7 +933,7 @@ #undef HAVE_PTHREAD_SIGMASK /* Define if platform requires stubbed pthread */ -#undef HAVE_PTHREAD_STUB +#undef HAVE_PTHREAD_STUBS /* Define to 1 if you have the header file. */ #undef HAVE_PTY_H From a2f80e52aa8826352aa255f2b16075ebda7a6dd9 Mon Sep 17 00:00:00 2001 From: Christian Heimes Date: Sat, 23 Jul 2022 13:03:57 +0200 Subject: [PATCH 13/13] Map ESHUTDOWN to EPIPE --- Lib/asyncore.py | 15 +++------------ Lib/test/test_exception_hierarchy.py | 5 +---- Modules/errnomodule.c | 4 ++++ 3 files changed, 8 insertions(+), 16 deletions(-) diff --git a/Lib/asyncore.py b/Lib/asyncore.py index 4efff8faa1cffe..76d74fa38b8220 100644 --- a/Lib/asyncore.py +++ b/Lib/asyncore.py @@ -46,7 +46,6 @@ sophisticated high-performance network servers and clients a snap. """ -from builtins import frozenset import select import socket import sys @@ -55,23 +54,15 @@ import os from errno import EALREADY, EINPROGRESS, EWOULDBLOCK, ECONNRESET, EINVAL, \ - ENOTCONN, EISCONN, EBADF, ECONNABORTED, EPIPE, EAGAIN, \ + ENOTCONN, ESHUTDOWN, EISCONN, EBADF, ECONNABORTED, EPIPE, EAGAIN, \ errorcode _DEPRECATION_MSG = ('The {name} module is deprecated and will be removed in ' 'Python {remove}. The recommended replacement is asyncio') warnings._deprecated(__name__, _DEPRECATION_MSG, remove=(3, 12)) -_DISCONNECTED = {ECONNRESET, ENOTCONN, ECONNABORTED, EPIPE, EBADF} - -try: - from errno import ESHUTDOWN -except ImportError: - pass -else: - _DISCONNECTED.add(ESHUTDOWN) - -_DISCONNECTED = frozenset(_DISCONNECTED) +_DISCONNECTED = frozenset({ECONNRESET, ENOTCONN, ESHUTDOWN, ECONNABORTED, EPIPE, + EBADF}) try: socket_map diff --git a/Lib/test/test_exception_hierarchy.py b/Lib/test/test_exception_hierarchy.py index 6d34e8ab8910ee..89fe9ddcefba3e 100644 --- a/Lib/test/test_exception_hierarchy.py +++ b/Lib/test/test_exception_hierarchy.py @@ -75,10 +75,7 @@ def _make_map(s): continue excname, _, errnames = line.partition(' ') for errname in filter(None, errnames.strip().split(', ')): - errval = getattr(errno, errname, None) - if errval is None: - continue - _map[errval] = getattr(builtins, excname) + _map[getattr(errno, errname)] = getattr(builtins, excname) return _map _map = _make_map(_pep_map) 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