Skip to content

Commit

Permalink
bpo-40280: select: Use NULL for empty fdset (GH-31865)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tiran authored Mar 14, 2022
1 parent 23abae6 commit f00ced8
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Lib/test/test_select.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
:func:`select.select` now passes ``NULL`` to ``select`` for each empty fdset.
7 changes: 6 additions & 1 deletion Modules/selectmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit f00ced8

Please sign in to comment.