[Python-checkins] python/dist/src/Modules selectmodule.c,2.73,2.74

bcannon at users.sourceforge.net bcannon at users.sourceforge.net
Wed Sep 10 13:37:45 EDT 2003


Update of /cvsroot/python/python/dist/src/Modules
In directory sc8-pr-cvs1:/tmp/cvs-serv12455/Modules
Modified Files:
	selectmodule.c 
Log Message:
select.select() now accepts a sequence (as defined by PySequence_Fast()) for
its first three arguments.
Closes RFE #798046 .
Index: selectmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/selectmodule.c,v
retrieving revision 2.73
retrieving revision 2.74
diff -C2 -d -r2.73 -r2.74
*** selectmodule.c	11 Feb 2003 17:18:58 -0000	2.73
--- selectmodule.c	10 Sep 2003 19:37:42 -0000	2.74
***************
*** 76,85 ****
 */
 static int
! list2set(PyObject *list, fd_set *set, pylist fd2obj[FD_SETSIZE + 1])
 {
 	int i;
 	int max = -1;
 	int index = 0;
! 	int len = PyList_Size(list);
 	PyObject* o = NULL;
 
--- 76,86 ----
 */
 static int
! seq2set(PyObject *seq, fd_set *set, pylist fd2obj[FD_SETSIZE + 1])
 {
 	int i;
 	int max = -1;
 	int index = 0;
! int len = -1;
! PyObject* fast_seq = NULL;
 	PyObject* o = NULL;
 
***************
*** 87,95 ****
 	FD_ZERO(set);
 
 	for (i = 0; i < len; i++) {
 		SOCKET v;
 
 		/* any intervening fileno() calls could decr this refcnt */
! 		if (!(o = PyList_GetItem(list, i)))
 return -1;
 
--- 88,102 ----
 	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 = PySequence_Fast_GET_ITEM(fast_seq, i)))
 return -1;
 
***************
*** 122,129 ****
--- 129,138 ----
 		fd2obj[++index].sentinel = -1;
 	}
+ Py_DECREF(fast_seq);
 	return max+1;
 
 finally:
 	Py_XDECREF(o);
+ Py_DECREF(fast_seq);
 	return -1;
 }
***************
*** 230,242 ****
 	}
 
- 	/* 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
--- 239,242 ----
***************
*** 252,266 ****
 	}
 #endif /* SELECT_USES_HEAP */
! 	/* Convert lists to fd_sets, and get maximum fd number
! 	 * propagates the Python exception set in list2set()
 	 */
 	rfd2obj[0].sentinel = -1;
 	wfd2obj[0].sentinel = -1;
 	efd2obj[0].sentinel = -1;
! 	if ((imax=list2set(ifdlist, &ifdset, rfd2obj)) < 0) 
 		goto finally;
! 	if ((omax=list2set(ofdlist, &ofdset, wfd2obj)) < 0) 
 		goto finally;
! 	if ((emax=list2set(efdlist, &efdset, efd2obj)) < 0) 
 		goto finally;
 	max = imax;
--- 252,266 ----
 	}
 #endif /* SELECT_USES_HEAP */
! 	/* 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=seq2set(ifdlist, &ifdset, rfd2obj)) < 0) 
 		goto finally;
! 	if ((omax=seq2set(ofdlist, &ofdset, wfd2obj)) < 0) 
 		goto finally;
! 	if ((emax=seq2set(efdlist, &efdset, efd2obj)) < 0) 
 		goto finally;
 	max = imax;
***************
*** 619,623 ****
 \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\
 rlist -- wait until ready for reading\n\
 wlist -- wait until ready for writing\n\
--- 619,623 ----
 \n\
 Wait until one or more file descriptors are ready for some kind of I/O.\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\


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /