summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorBrett Cannon <bcannon@gmail.com>2003-09-10 19:37:42 (GMT)
committerBrett Cannon <bcannon@gmail.com>2003-09-10 19:37:42 (GMT)
commit62dba4c2775adfb5a5a97ca012a3ab00c4e28597 (patch)
tree7f3c3e4ff4ab305aa08c547b660cf679bc3bf19f /Modules
parentfd4fa8801a75919dd711e9f750b8a405a639f2c2 (diff)
downloadcpython-62dba4c2775adfb5a5a97ca012a3ab00c4e28597.zip
cpython-62dba4c2775adfb5a5a97ca012a3ab00c4e28597.tar.gz
cpython-62dba4c2775adfb5a5a97ca012a3ab00c4e28597.tar.bz2
select.select() now accepts a sequence (as defined by PySequence_Fast()) for
its first three arguments. Closes RFE #798046 .
Diffstat (limited to 'Modules')
-rw-r--r--Modules/selectmodule.c36
1 files changed, 18 insertions, 18 deletions
diff --git a/Modules/selectmodule.c b/Modules/selectmodule.c
index 98b75f0..2b2d6a9 100644
--- a/Modules/selectmodule.c
+++ b/Modules/selectmodule.c
@@ -75,22 +75,29 @@ reap_obj(pylist fd2obj[FD_SETSIZE + 1])
returns a number >= 0
*/
static int
-list2set(PyObject *list, fd_set *set, pylist fd2obj[FD_SETSIZE + 1])
+seq2set(PyObject *seq, fd_set *set, pylist fd2obj[FD_SETSIZE + 1])
{
int i;
int max = -1;
int index = 0;
- int len = PyList_Size(list);
+ int len = -1;
+ PyObject* fast_seq = NULL;
PyObject* o = NULL;
fd2obj[0].obj = (PyObject*)0; /* set list to zero size */
FD_ZERO(set);
+ fast_seq=PySequence_Fast(seq, "arguments 1-3 must be sequences");
+ if (!fast_seq)
+ return -1;
+
+ len = PySequence_Fast_GET_SIZE(fast_seq);
+
for (i = 0; i < len; i++) {
SOCKET v;
/* any intervening fileno() calls could decr this refcnt */
- if (!(o = PyList_GetItem(list, i)))
+ if (!(o = PySequence_Fast_GET_ITEM(fast_seq, i)))
return -1;
Py_INCREF(o);
@@ -121,10 +128,12 @@ list2set(PyObject *list, fd_set *set, pylist fd2obj[FD_SETSIZE + 1])
fd2obj[index].sentinel = 0;
fd2obj[++index].sentinel = -1;
}
+ Py_DECREF(fast_seq);
return max+1;
finally:
Py_XDECREF(o);
+ Py_DECREF(fast_seq);
return -1;
}
@@ -229,15 +238,6 @@ select_select(PyObject *self, PyObject *args)
tvp = &tv;
}
- /* sanity check first three arguments */
- if (!PyList_Check(ifdlist) ||
- !PyList_Check(ofdlist) ||
- !PyList_Check(efdlist))
- {
- PyErr_SetString(PyExc_TypeError,
- "arguments 1-3 must be lists");
- return NULL;
- }
#ifdef SELECT_USES_HEAP
/* Allocate memory for the lists */
@@ -251,17 +251,17 @@ select_select(PyObject *self, PyObject *args)
return PyErr_NoMemory();
}
#endif /* SELECT_USES_HEAP */
- /* Convert lists to fd_sets, and get maximum fd number
- * propagates the Python exception set in list2set()
+ /* Convert sequences to fd_sets, and get maximum fd number
+ * propagates the Python exception set in seq2set()
*/
rfd2obj[0].sentinel = -1;
wfd2obj[0].sentinel = -1;
efd2obj[0].sentinel = -1;
- if ((imax=list2set(ifdlist, &ifdset, rfd2obj)) < 0)
+ if ((imax=seq2set(ifdlist, &ifdset, rfd2obj)) < 0)
goto finally;
- if ((omax=list2set(ofdlist, &ofdset, wfd2obj)) < 0)
+ if ((omax=seq2set(ofdlist, &ofdset, wfd2obj)) < 0)
goto finally;
- if ((emax=list2set(efdlist, &efdset, efd2obj)) < 0)
+ if ((emax=seq2set(efdlist, &efdset, efd2obj)) < 0)
goto finally;
max = imax;
if (omax > max) max = omax;
@@ -618,7 +618,7 @@ PyDoc_STRVAR(select_doc,
"select(rlist, wlist, xlist[, timeout]) -> (rlist, wlist, xlist)\n\
\n\
Wait until one or more file descriptors are ready for some kind of I/O.\n\
-The first three arguments are lists of file descriptors to be waited for:\n\
+The first three arguments are sequences of file descriptors to be waited for:\n\
rlist -- wait until ready for reading\n\
wlist -- wait until ready for writing\n\
xlist -- wait for an ``exceptional condition''\n\