summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorChristian Heimes <christian@python.org>2022-07-31 15:39:41 (GMT)
committerGitHub <noreply@github.com>2022-07-31 15:39:41 (GMT)
commitdb13c0c1b8bc8c15d920a94ca008aabea4037697 (patch)
tree88b24924603fcffab9c1be7005c4622ba67e7a14 /Modules
parentc7ac8b65884a79e6a976811bca10527613b1396a (diff)
downloadcpython-db13c0c1b8bc8c15d920a94ca008aabea4037697.zip
cpython-db13c0c1b8bc8c15d920a94ca008aabea4037697.tar.gz
cpython-db13c0c1b8bc8c15d920a94ca008aabea4037697.tar.bz2
[3.11] gh-95174: Handle missing dup() and constants in WASI (GH-95229) (GH-95272)
Co-authored-by: Christian Heimes <christian@python.org>
Diffstat (limited to 'Modules')
-rw-r--r--Modules/clinic/posixmodule.c.h10
-rw-r--r--Modules/errnomodule.c4
-rw-r--r--Modules/posixmodule.c5
-rw-r--r--Modules/selectmodule.c5
-rw-r--r--Modules/socketmodule.c4
5 files changed, 26 insertions, 2 deletions
diff --git a/Modules/clinic/posixmodule.c.h b/Modules/clinic/posixmodule.c.h
index aaf3bf3..ca2699b 100644
--- a/Modules/clinic/posixmodule.c.h
+++ b/Modules/clinic/posixmodule.c.h
@@ -4691,6 +4691,8 @@ exit:
return return_value;
}
+#if ((defined(HAVE_DUP3) || defined(F_DUPFD) || defined(MS_WINDOWS)))
+
PyDoc_STRVAR(os_dup2__doc__,
"dup2($module, /, fd, fd2, inheritable=True)\n"
"--\n"
@@ -4746,6 +4748,8 @@ exit:
return return_value;
}
+#endif /* ((defined(HAVE_DUP3) || defined(F_DUPFD) || defined(MS_WINDOWS))) */
+
#if defined(HAVE_LOCKF)
PyDoc_STRVAR(os_lockf__doc__,
@@ -9123,6 +9127,10 @@ exit:
#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) */
@@ -9370,4 +9378,4 @@ exit:
#ifndef OS_WAITSTATUS_TO_EXITCODE_METHODDEF
#define 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]*/
diff --git a/Modules/errnomodule.c b/Modules/errnomodule.c
index bf6766e..0516e73 100644
--- a/Modules/errnomodule.c
+++ b/Modules/errnomodule.c
@@ -280,6 +280,10 @@ errno_exec(PyObject *module)
#ifdef ENOANO
add_errcode("ENOANO", ENOANO, "No anode");
#endif
+#if defined(__wasi__) && !defined(ESHUTDOWN)
+ // WASI SDK 16 does not have ESHUTDOWN, shutdown results in EPIPE.
+ #define ESHUTDOWN EPIPE
+#endif
#ifdef ESHUTDOWN
add_errcode("ESHUTDOWN", ESHUTDOWN, "Cannot send after transport endpoint shutdown");
#else
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index f97013f..3780325 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -9346,7 +9346,9 @@ os_dup_impl(PyObject *module, int 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]
os.dup2 -> int
fd: int
@@ -9446,6 +9448,7 @@ os_dup2_impl(PyObject *module, int fd, int fd2, int inheritable)
return res;
}
+#endif
#ifdef HAVE_LOCKF
diff --git a/Modules/selectmodule.c b/Modules/selectmodule.c
index 5c36eaa..4eea928 100644
--- a/Modules/selectmodule.c
+++ b/Modules/selectmodule.c
@@ -63,6 +63,11 @@ extern void bzero(void *, int);
# define SOCKET int
#endif
+// WASI SDK 16 does not have POLLPRIO, define as no-op
+#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 4e936e2..7240739 100644
--- a/Modules/socketmodule.c
+++ b/Modules/socketmodule.c
@@ -7650,6 +7650,10 @@ PyInit__socket(void)
PyModule_AddIntMacro(m, MSG_EOR);
#endif
#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);
#endif
#ifdef MSG_CTRUNC