[Python-checkins] bpo-40280: select: Use NULL for empty fdset (GH-31865)

tiran webhook-mailer at python.org
Mon Mar 14 09:40:43 EDT 2022


https://github.com/python/cpython/commit/f00ced8396f2d7683e58b9d5ebbf5797992bf477
commit: f00ced8396f2d7683e58b9d5ebbf5797992bf477
branch: main
author: Christian Heimes <christian at python.org>
committer: tiran <christian at python.org>
date: 2022-03-14T14:40:28+01:00
summary:

bpo-40280: select: Use NULL for empty fdset (GH-31865)

wasm32-emscripten does not support exceptfds and requires NULL. Python
now passes NULL instead of a fdset pointer when the input list is empty.
This works fine on all platforms and might even be a tiny bit faster.

files:
A Misc/NEWS.d/next/Library/2022-03-14-09-26-42.bpo-40280.2-k8TV.rst
M Lib/test/test_select.py
M Modules/selectmodule.c

diff --git a/Lib/test/test_select.py b/Lib/test/test_select.py
index cf32cf2f6a6f8..69421fd77558d 100644
--- a/Lib/test/test_select.py
+++ b/Lib/test/test_select.py
@@ -46,7 +46,7 @@ def test_returned_list_identity(self):
         self.assertIsNot(r, x)
         self.assertIsNot(w, x)
 
-    @unittest.skipUnless(hasattr(os, 'popen'), "need os.popen()")
+    @support.requires_fork()
     def test_select(self):
         code = textwrap.dedent('''
             import time
diff --git a/Misc/NEWS.d/next/Library/2022-03-14-09-26-42.bpo-40280.2-k8TV.rst b/Misc/NEWS.d/next/Library/2022-03-14-09-26-42.bpo-40280.2-k8TV.rst
new file mode 100644
index 0000000000000..f27c968623ff5
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2022-03-14-09-26-42.bpo-40280.2-k8TV.rst
@@ -0,0 +1 @@
+:func:`select.select` now passes ``NULL`` to ``select`` for each empty fdset.
diff --git a/Modules/selectmodule.c b/Modules/selectmodule.c
index 1a5a63249c7b8..5c36eaaedeb70 100644
--- a/Modules/selectmodule.c
+++ b/Modules/selectmodule.c
@@ -330,7 +330,12 @@ select_select_impl(PyObject *module, PyObject *rlist, PyObject *wlist,
     do {
         Py_BEGIN_ALLOW_THREADS
         errno = 0;
-        n = select(max, &ifdset, &ofdset, &efdset, tvp);
+        n = select(
+            max,
+            imax ? &ifdset : NULL,
+            omax ? &ofdset : NULL,
+            emax ? &efdset : NULL,
+            tvp);
         Py_END_ALLOW_THREADS
 
         if (errno != EINTR)



More information about the Python-checkins mailing list