jenkins-core-weekly: update to 2.491
[oi-userland.git] / components / python / python37 / patches / 07-closerange.patch
blob0b8a2f9ab55d091fd35558313ce1c91a54dd8467
1 Use fdwalk(3c) within os.closerange() impl to close file descriptors if available.
3 This patch was submitted and accepted by upstream and is part of the Python 3.8 and later.
4 https://github.com/python/cpython/pull/15224
5 https://bugs.python.org/issue38110
7 --- Python-3.7.5/Modules/posixmodule.c
8 +++ Python-3.7.5/Modules/posixmodule.c
9 @@ -7793,6 +7793,21 @@ os_close_impl(PyObject *module, int fd)
13 +#ifdef HAVE_FDWALK
14 +static int
15 +_fdwalk_close_func(void *lohi, int fd)
17 + int lo = ((int *)lohi)[0];
18 + int hi = ((int *)lohi)[1];
20 + if (fd >= hi)
21 + return 1;
22 + else if (fd >= lo)
23 + close(fd);
24 + return 0;
26 +#endif /* HAVE_FDWALK */
28 /*[clinic input]
29 os.closerange
31 @@ -7807,11 +7822,21 @@ static PyObject *
32 os_closerange_impl(PyObject *module, int fd_low, int fd_high)
33 /*[clinic end generated code: output=0ce5c20fcda681c2 input=5855a3d053ebd4ec]*/
35 +#ifdef HAVE_FDWALK
36 + int lohi[2];
37 +#else
38 int i;
39 +#endif
40 Py_BEGIN_ALLOW_THREADS
41 _Py_BEGIN_SUPPRESS_IPH
42 +#ifdef HAVE_FDWALK
43 + lohi[0] = Py_MAX(fd_low, 0);
44 + lohi[1] = fd_high;
45 + fdwalk(_fdwalk_close_func, lohi);
46 +#else
47 for (i = Py_MAX(fd_low, 0); i < fd_high; i++)
48 close(i);
49 +#endif
50 _Py_END_SUPPRESS_IPH
51 Py_END_ALLOW_THREADS
52 Py_RETURN_NONE;
53 --- Python-3.7.5/configure
54 +++ Python-3.7.5/configure
55 @@ -11462,7 +11462,7 @@ fi
56 # checks for library functions
57 for ac_func in alarm accept4 setitimer getitimer bind_textdomain_codeset chown \
58 clock confstr ctermid dup3 execv faccessat fchmod fchmodat fchown fchownat \
59 - fexecve fdopendir fork fpathconf fstatat ftime ftruncate futimesat \
60 + fdwalk fexecve fdopendir fork fpathconf fstatat ftime ftruncate futimesat \
61 futimens futimes gai_strerror getentropy \
62 getgrouplist getgroups getlogin getloadavg getpeername getpgid getpid \
63 getpriority getresuid getresgid getpwent getspnam getspent getsid getwd \
64 --- Python-3.7.5/configure.ac
65 +++ Python-3.7.5/configure.ac
66 @@ -3557,7 +3557,7 @@ fi
67 # checks for library functions
68 AC_CHECK_FUNCS(alarm accept4 setitimer getitimer bind_textdomain_codeset chown \
69 clock confstr ctermid dup3 execv faccessat fchmod fchmodat fchown fchownat \
70 - fexecve fdopendir fork fpathconf fstatat ftime ftruncate futimesat \
71 + fdwalk fexecve fdopendir fork fpathconf fstatat ftime ftruncate futimesat \
72 futimens futimes gai_strerror getentropy \
73 getgrouplist getgroups getlogin getloadavg getpeername getpgid getpid \
74 getpriority getresuid getresgid getpwent getspnam getspent getsid getwd \
75 --- Python-3.7.5/pyconfig.h.in
76 +++ Python-3.7.5/pyconfig.h.in
77 @@ -324,6 +324,9 @@
78 /* Define to 1 if you have the `fdopendir' function. */
79 #undef HAVE_FDOPENDIR
81 +/* Define to 1 if you have the `fdwalk' function. */
82 +#undef HAVE_FDWALK
84 /* Define to 1 if you have the `fexecve' function. */
85 #undef HAVE_FEXECVE