@@ -75,22 +75,29 @@ reap_obj(pylist fd2obj[FD_SETSIZE + 1])
7575 returns a number >= 0
7676*/
7777static int
78- list2set (PyObject * list , fd_set * set , pylist fd2obj [FD_SETSIZE + 1 ])
78+ seq2set (PyObject * seq , fd_set * set , pylist fd2obj [FD_SETSIZE + 1 ])
7979{
8080 int i ;
8181 int max = -1 ;
8282 int index = 0 ;
83- int len = PyList_Size (list );
83+ int len = -1 ;
84+ PyObject * fast_seq = NULL ;
8485 PyObject * o = NULL ;
8586
8687 fd2obj [0 ].obj = (PyObject * )0 ; /* set list to zero size */
8788 FD_ZERO (set );
8889
90+ fast_seq = PySequence_Fast (seq , "arguments 1-3 must be sequences" );
91+ if (!fast_seq )
92+ return -1 ;
93+
94+ len = PySequence_Fast_GET_SIZE (fast_seq );
95+
8996 for (i = 0 ; i < len ; i ++ ) {
9097 SOCKET v ;
9198
9299 /* any intervening fileno() calls could decr this refcnt */
93- if (!(o = PyList_GetItem ( list , i )))
100+ if (!(o = PySequence_Fast_GET_ITEM ( fast_seq , i )))
94101 return -1 ;
95102
96103 Py_INCREF (o );
@@ -121,10 +128,12 @@ list2set(PyObject *list, fd_set *set, pylist fd2obj[FD_SETSIZE + 1])
121128 fd2obj [index ].sentinel = 0 ;
122129 fd2obj [++ index ].sentinel = -1 ;
123130 }
131+ Py_DECREF (fast_seq );
124132 return max + 1 ;
125133
126134 finally :
127135 Py_XDECREF (o );
136+ Py_DECREF (fast_seq );
128137 return -1 ;
129138}
130139
@@ -229,15 +238,6 @@ select_select(PyObject *self, PyObject *args)
229238 tvp = & tv ;
230239 }
231240
232- /* sanity check first three arguments */
233- if (!PyList_Check (ifdlist ) ||
234- !PyList_Check (ofdlist ) ||
235- !PyList_Check (efdlist ))
236- {
237- PyErr_SetString (PyExc_TypeError ,
238- "arguments 1-3 must be lists" );
239- return NULL ;
240- }
241241
242242#ifdef SELECT_USES_HEAP
243243 /* Allocate memory for the lists */
@@ -251,17 +251,17 @@ select_select(PyObject *self, PyObject *args)
251251 return PyErr_NoMemory ();
252252 }
253253#endif /* SELECT_USES_HEAP */
254- /* Convert lists to fd_sets, and get maximum fd number
255- * propagates the Python exception set in list2set ()
254+ /* Convert sequences to fd_sets, and get maximum fd number
255+ * propagates the Python exception set in seq2set ()
256256 */
257257 rfd2obj [0 ].sentinel = -1 ;
258258 wfd2obj [0 ].sentinel = -1 ;
259259 efd2obj [0 ].sentinel = -1 ;
260- if ((imax = list2set (ifdlist , & ifdset , rfd2obj )) < 0 )
260+ if ((imax = seq2set (ifdlist , & ifdset , rfd2obj )) < 0 )
261261 goto finally ;
262- if ((omax = list2set (ofdlist , & ofdset , wfd2obj )) < 0 )
262+ if ((omax = seq2set (ofdlist , & ofdset , wfd2obj )) < 0 )
263263 goto finally ;
264- if ((emax = list2set (efdlist , & efdset , efd2obj )) < 0 )
264+ if ((emax = seq2set (efdlist , & efdset , efd2obj )) < 0 )
265265 goto finally ;
266266 max = imax ;
267267 if (omax > max ) max = omax ;
@@ -618,7 +618,7 @@ PyDoc_STRVAR(select_doc,
618618"select(rlist, wlist, xlist[, timeout]) -> (rlist, wlist, xlist)\n\
619619\n\
620620Wait until one or more file descriptors are ready for some kind of I/O.\n\
621- The first three arguments are lists of file descriptors to be waited for:\n\
621+ The first three arguments are sequences of file descriptors to be waited for:\n\
622622rlist -- wait until ready for reading\n\
623623wlist -- wait until ready for writing\n\
624624xlist -- wait for an ``exceptional condition''\n\
0 commit comments