mirror of https://github.com/python/cpython.git
[3.11] gh-95174: Handle missing dup() and constants in WASI (GH-95229) (GH-95272)
Co-authored-by: Christian Heimes <christian@python.org>
This commit is contained in:
parent
c7ac8b6588
commit
db13c0c1b8
|
@ -0,0 +1,2 @@
|
||||||
|
Python now detects missing ``dup`` function in WASI and works around some
|
||||||
|
missing :mod:`errno`, :mod:`select`, and :mod:`socket` constants.
|
|
@ -4691,6 +4691,8 @@ exit:
|
||||||
return return_value;
|
return return_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if ((defined(HAVE_DUP3) || defined(F_DUPFD) || defined(MS_WINDOWS)))
|
||||||
|
|
||||||
PyDoc_STRVAR(os_dup2__doc__,
|
PyDoc_STRVAR(os_dup2__doc__,
|
||||||
"dup2($module, /, fd, fd2, inheritable=True)\n"
|
"dup2($module, /, fd, fd2, inheritable=True)\n"
|
||||||
"--\n"
|
"--\n"
|
||||||
|
@ -4746,6 +4748,8 @@ exit:
|
||||||
return return_value;
|
return return_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif /* ((defined(HAVE_DUP3) || defined(F_DUPFD) || defined(MS_WINDOWS))) */
|
||||||
|
|
||||||
#if defined(HAVE_LOCKF)
|
#if defined(HAVE_LOCKF)
|
||||||
|
|
||||||
PyDoc_STRVAR(os_lockf__doc__,
|
PyDoc_STRVAR(os_lockf__doc__,
|
||||||
|
@ -9123,6 +9127,10 @@ exit:
|
||||||
#define OS_TCSETPGRP_METHODDEF
|
#define OS_TCSETPGRP_METHODDEF
|
||||||
#endif /* !defined(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
|
#ifndef OS_LOCKF_METHODDEF
|
||||||
#define OS_LOCKF_METHODDEF
|
#define OS_LOCKF_METHODDEF
|
||||||
#endif /* !defined(OS_LOCKF_METHODDEF) */
|
#endif /* !defined(OS_LOCKF_METHODDEF) */
|
||||||
|
@ -9370,4 +9378,4 @@ exit:
|
||||||
#ifndef OS_WAITSTATUS_TO_EXITCODE_METHODDEF
|
#ifndef OS_WAITSTATUS_TO_EXITCODE_METHODDEF
|
||||||
#define OS_WAITSTATUS_TO_EXITCODE_METHODDEF
|
#define OS_WAITSTATUS_TO_EXITCODE_METHODDEF
|
||||||
#endif /* !defined(OS_WAITSTATUS_TO_EXITCODE_METHODDEF) */
|
#endif /* !defined(OS_WAITSTATUS_TO_EXITCODE_METHODDEF) */
|
||||||
/*[clinic end generated code: output=2a53748bcf001a3f input=a9049054013a1b77]*/
|
/*[clinic end generated code: output=3032d9c5c3aaa165 input=a9049054013a1b77]*/
|
||||||
|
|
|
@ -280,6 +280,10 @@ errno_exec(PyObject *module)
|
||||||
#ifdef ENOANO
|
#ifdef ENOANO
|
||||||
add_errcode("ENOANO", ENOANO, "No anode");
|
add_errcode("ENOANO", ENOANO, "No anode");
|
||||||
#endif
|
#endif
|
||||||
|
#if defined(__wasi__) && !defined(ESHUTDOWN)
|
||||||
|
// WASI SDK 16 does not have ESHUTDOWN, shutdown results in EPIPE.
|
||||||
|
#define ESHUTDOWN EPIPE
|
||||||
|
#endif
|
||||||
#ifdef ESHUTDOWN
|
#ifdef ESHUTDOWN
|
||||||
add_errcode("ESHUTDOWN", ESHUTDOWN, "Cannot send after transport endpoint shutdown");
|
add_errcode("ESHUTDOWN", ESHUTDOWN, "Cannot send after transport endpoint shutdown");
|
||||||
#else
|
#else
|
||||||
|
|
|
@ -9346,7 +9346,9 @@ os_dup_impl(PyObject *module, int fd)
|
||||||
return _Py_dup(fd);
|
return _Py_dup(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// dup2() is either provided by libc or dup2.c with AC_REPLACE_FUNCS().
|
||||||
|
// dup2.c provides working dup2() if and only if F_DUPFD is available.
|
||||||
|
#if (defined(HAVE_DUP3) || defined(F_DUPFD) || defined(MS_WINDOWS))
|
||||||
/*[clinic input]
|
/*[clinic input]
|
||||||
os.dup2 -> int
|
os.dup2 -> int
|
||||||
fd: int
|
fd: int
|
||||||
|
@ -9446,6 +9448,7 @@ os_dup2_impl(PyObject *module, int fd, int fd2, int inheritable)
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#ifdef HAVE_LOCKF
|
#ifdef HAVE_LOCKF
|
||||||
|
|
|
@ -63,6 +63,11 @@ extern void bzero(void *, int);
|
||||||
# define SOCKET int
|
# define SOCKET int
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// WASI SDK 16 does not have POLLPRIO, define as no-op
|
||||||
|
#if defined(__wasi__) && !defined(POLLPRI)
|
||||||
|
# define POLLPRI 0
|
||||||
|
#endif
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
PyObject *close;
|
PyObject *close;
|
||||||
PyTypeObject *poll_Type;
|
PyTypeObject *poll_Type;
|
||||||
|
|
|
@ -7650,6 +7650,10 @@ PyInit__socket(void)
|
||||||
PyModule_AddIntMacro(m, MSG_EOR);
|
PyModule_AddIntMacro(m, MSG_EOR);
|
||||||
#endif
|
#endif
|
||||||
#ifdef MSG_TRUNC
|
#ifdef MSG_TRUNC
|
||||||
|
// workaround for https://github.com/WebAssembly/wasi-libc/issues/305
|
||||||
|
#if defined(__wasi__) && !defined(__WASI_RIFLAGS_RECV_DATA_TRUNCATED)
|
||||||
|
# define __WASI_RIFLAGS_RECV_DATA_TRUNCATED 2
|
||||||
|
#endif
|
||||||
PyModule_AddIntMacro(m, MSG_TRUNC);
|
PyModule_AddIntMacro(m, MSG_TRUNC);
|
||||||
#endif
|
#endif
|
||||||
#ifdef MSG_CTRUNC
|
#ifdef MSG_CTRUNC
|
||||||
|
|
|
@ -681,6 +681,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 if you have the 'inet_pton' function. */
|
||||||
#define HAVE_INET_PTON 1
|
#define HAVE_INET_PTON 1
|
||||||
|
|
||||||
|
/* Define to 1 if you have the `dup' function. */
|
||||||
|
#define HAVE_DUP 1
|
||||||
|
|
||||||
/* framework name */
|
/* framework name */
|
||||||
#define _PYTHONFRAMEWORK ""
|
#define _PYTHONFRAMEWORK ""
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
* Return fd2 if all went well; return BADEXIT otherwise.
|
* Return fd2 if all went well; return BADEXIT otherwise.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
@ -20,12 +21,17 @@ int
|
||||||
dup2(int fd1, int fd2)
|
dup2(int fd1, int fd2)
|
||||||
{
|
{
|
||||||
if (fd1 != fd2) {
|
if (fd1 != fd2) {
|
||||||
|
#ifdef F_DUPFD
|
||||||
if (fcntl(fd1, F_GETFL) < 0)
|
if (fcntl(fd1, F_GETFL) < 0)
|
||||||
return BADEXIT;
|
return BADEXIT;
|
||||||
if (fcntl(fd2, F_GETFL) >= 0)
|
if (fcntl(fd2, F_GETFL) >= 0)
|
||||||
close(fd2);
|
close(fd2);
|
||||||
if (fcntl(fd1, F_DUPFD, fd2) < 0)
|
if (fcntl(fd1, F_DUPFD, fd2) < 0)
|
||||||
return BADEXIT;
|
return BADEXIT;
|
||||||
|
#else
|
||||||
|
errno = ENOTSUP;
|
||||||
|
return BADEXIT;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
return fd2;
|
return fd2;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2379,7 +2379,7 @@ _Py_dup(int fd)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#elif HAVE_DUP
|
||||||
Py_BEGIN_ALLOW_THREADS
|
Py_BEGIN_ALLOW_THREADS
|
||||||
_Py_BEGIN_SUPPRESS_IPH
|
_Py_BEGIN_SUPPRESS_IPH
|
||||||
fd = dup(fd);
|
fd = dup(fd);
|
||||||
|
@ -2396,6 +2396,10 @@ _Py_dup(int fd)
|
||||||
_Py_END_SUPPRESS_IPH
|
_Py_END_SUPPRESS_IPH
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
errno = ENOTSUP;
|
||||||
|
PyErr_SetFromErrno(PyExc_OSError);
|
||||||
|
return -1;
|
||||||
#endif
|
#endif
|
||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
|
@ -14953,7 +14953,7 @@ fi
|
||||||
# checks for library functions
|
# checks for library functions
|
||||||
for ac_func in \
|
for ac_func in \
|
||||||
accept4 alarm bind_textdomain_codeset chmod chown clock close_range confstr \
|
accept4 alarm bind_textdomain_codeset chmod chown clock close_range confstr \
|
||||||
copy_file_range ctermid dup3 execv explicit_bzero explicit_memset \
|
copy_file_range ctermid dup dup3 execv explicit_bzero explicit_memset \
|
||||||
faccessat fchmod fchmodat fchown fchownat fdopendir fdwalk fexecve \
|
faccessat fchmod fchmodat fchown fchownat fdopendir fdwalk fexecve \
|
||||||
fork fork1 fpathconf fstatat ftime ftruncate futimens futimes futimesat \
|
fork fork1 fpathconf fstatat ftime ftruncate futimens futimes futimesat \
|
||||||
gai_strerror getegid getentropy geteuid getgid getgrgid getgrgid_r \
|
gai_strerror getegid getentropy geteuid getgid getgrgid getgrgid_r \
|
||||||
|
|
|
@ -4537,7 +4537,7 @@ fi
|
||||||
# checks for library functions
|
# checks for library functions
|
||||||
AC_CHECK_FUNCS([ \
|
AC_CHECK_FUNCS([ \
|
||||||
accept4 alarm bind_textdomain_codeset chmod chown clock close_range confstr \
|
accept4 alarm bind_textdomain_codeset chmod chown clock close_range confstr \
|
||||||
copy_file_range ctermid dup3 execv explicit_bzero explicit_memset \
|
copy_file_range ctermid dup dup3 execv explicit_bzero explicit_memset \
|
||||||
faccessat fchmod fchmodat fchown fchownat fdopendir fdwalk fexecve \
|
faccessat fchmod fchmodat fchown fchownat fdopendir fdwalk fexecve \
|
||||||
fork fork1 fpathconf fstatat ftime ftruncate futimens futimes futimesat \
|
fork fork1 fpathconf fstatat ftime ftruncate futimens futimes futimesat \
|
||||||
gai_strerror getegid getentropy geteuid getgid getgrgid getgrgid_r \
|
gai_strerror getegid getentropy geteuid getgid getgrgid getgrgid_r \
|
||||||
|
|
|
@ -278,6 +278,9 @@
|
||||||
/* Define to 1 if you have the `dlopen' function. */
|
/* Define to 1 if you have the `dlopen' function. */
|
||||||
#undef HAVE_DLOPEN
|
#undef HAVE_DLOPEN
|
||||||
|
|
||||||
|
/* Define to 1 if you have the `dup' function. */
|
||||||
|
#undef HAVE_DUP
|
||||||
|
|
||||||
/* Define to 1 if you have the `dup2' function. */
|
/* Define to 1 if you have the `dup2' function. */
|
||||||
#undef HAVE_DUP2
|
#undef HAVE_DUP2
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue