annotate Modules/selectmodule.c @ 2611:01687ce43708 legacy-trunk

fix subtle refcnt bug
author Guido van Rossum <guido@python.org>
date Wed, 29 Mar 1995 16:47:45 +0000
parents 172ba04a5191
children d617de15774b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
902
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
1 /***********************************************************
2061
172ba04a5191 Added 1995 to copyright message.
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
2 Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
172ba04a5191 Added 1995 to copyright message.
Guido van Rossum <guido@python.org>
parents: 1746
diff changeset
3 The Netherlands.
902
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
4
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
5 All Rights Reserved
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
6
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
7 Permission to use, copy, modify, and distribute this software and its
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
8 documentation for any purpose and without fee is hereby granted,
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
9 provided that the above copyright notice appear in all copies and that
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
10 both that copyright notice and this permission notice appear in
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
11 supporting documentation, and that the names of Stichting Mathematisch
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
12 Centrum or CWI not be used in advertising or publicity pertaining to
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
13 distribution of the software without specific, written prior permission.
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
14
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
15 STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
16 THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
17 FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
18 FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
19 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
20 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
21 OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
22
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
23 ******************************************************************/
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
24
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
25 /* select - Module containing unix select(2) call */
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
26
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
27 #include "allobjects.h"
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
28 #include "modsupport.h"
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
29 #include "ceval.h"
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
30
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1392
diff changeset
31 #include <sys/types.h>
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1392
diff changeset
32 #include "myselect.h" /* Also includes mytime.h */
902
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
33
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
34 static object *SelectError;
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
35
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
36 static
922
c12b445cdace * myselect.h: bzero -> memset
Guido van Rossum <guido@python.org>
parents: 904
diff changeset
37 list2set(list, set, fd2obj)
902
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
38 object *list;
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
39 fd_set *set;
922
c12b445cdace * myselect.h: bzero -> memset
Guido van Rossum <guido@python.org>
parents: 904
diff changeset
40 object *fd2obj[FD_SETSIZE];
902
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
41 {
927
aacbd4b558c7 Replaced max=-1 by max = -1.
Guido van Rossum <guido@python.org>
parents: 926
diff changeset
42 int i, len, v, max = -1;
902
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
43 object *o, *filenomethod, *fno;
2611
01687ce43708 fix subtle refcnt bug
Guido van Rossum <guido@python.org>
parents: 2061
diff changeset
44
01687ce43708 fix subtle refcnt bug
Guido van Rossum <guido@python.org>
parents: 2061
diff changeset
45 for ( i=0; i<FD_SETSIZE; i++ ) {
01687ce43708 fix subtle refcnt bug
Guido van Rossum <guido@python.org>
parents: 2061
diff changeset
46 fd2obj[i] = (object*)0;
01687ce43708 fix subtle refcnt bug
Guido van Rossum <guido@python.org>
parents: 2061
diff changeset
47 }
902
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
48
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
49 FD_ZERO(set);
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
50 len = getlistsize(list);
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
51 for( i=0; i<len; i++ ) {
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
52 o = getlistitem(list, i);
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
53 if ( is_intobject(o) ) {
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
54 v = getintvalue(o);
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
55 } else if ( (filenomethod = getattr(o, "fileno")) != NULL ) {
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
56 fno = call_object(filenomethod, NULL);
1284
dbce72afe261 * selectmodule.c: fix (another!) two memory leaks -- this time in list2set
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
57 DECREF(filenomethod);
902
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
58 if ( fno == NULL )
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
59 return -1;
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
60 if ( !is_intobject(fno) ) {
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
61 err_badarg();
1284
dbce72afe261 * selectmodule.c: fix (another!) two memory leaks -- this time in list2set
Guido van Rossum <guido@python.org>
parents: 1252
diff changeset
62 DECREF(fno);
902
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
63 return -1;
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
64 }
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
65 v = getintvalue(fno);
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
66 DECREF(fno);
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
67 } else {
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
68 err_badarg();
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
69 return -1;
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
70 }
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1392
diff changeset
71 if ( v < 0 || v >= FD_SETSIZE ) {
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1392
diff changeset
72 err_setstr(ValueError, "filedescriptor out of range in select()");
902
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
73 return -1;
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
74 }
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
75 if ( v > max ) max = v;
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
76 FD_SET(v, set);
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
77 fd2obj[v] = o;
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
78 }
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
79 return max+1;
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
80 }
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
81
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
82 static object *
922
c12b445cdace * myselect.h: bzero -> memset
Guido van Rossum <guido@python.org>
parents: 904
diff changeset
83 set2list(set, max, fd2obj)
902
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
84 fd_set *set;
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
85 int max;
922
c12b445cdace * myselect.h: bzero -> memset
Guido van Rossum <guido@python.org>
parents: 904
diff changeset
86 object *fd2obj[FD_SETSIZE];
902
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
87 {
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
88 int i, num=0;
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
89 object *list, *o;
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
90
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
91 for(i=0; i<max; i++)
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
92 if ( FD_ISSET(i,set) )
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
93 num++;
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
94 list = newlistobject(num);
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
95 num = 0;
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
96 for(i=0; i<max; i++)
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
97 if ( FD_ISSET(i,set) ) {
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
98 if ( i > FD_SETSIZE ) {
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1392
diff changeset
99 err_setstr(SystemError,
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1392
diff changeset
100 "filedescriptor out of range returned in select()");
902
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
101 return NULL;
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
102 }
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
103 o = fd2obj[i];
1746
1940892d2fe3 Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents: 1392
diff changeset
104 if ( o == NULL ) {
902
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
105 err_setstr(SystemError,
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
106 "Bad filedescriptor returned from select()");
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
107 return NULL;
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
108 }
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
109 INCREF(o);
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
110 setlistitem(list, num, o);
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
111 num++;
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
112 }
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
113 return list;
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
114 }
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
115
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
116 static object *
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
117 select_select(self, args)
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
118 object *self;
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
119 object *args;
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
120 {
2611
01687ce43708 fix subtle refcnt bug
Guido van Rossum <guido@python.org>
parents: 2061
diff changeset
121 object *rfd2obj[FD_SETSIZE], *wfd2obj[FD_SETSIZE], *efd2obj[FD_SETSIZE];
902
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
122 object *ifdlist, *ofdlist, *efdlist;
1390
cffe8d6b2f09 * selectmodule.c (select_select): timeout argument may be None with same
Guido van Rossum <guido@python.org>
parents: 1284
diff changeset
123 object *ret, *tout;
902
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
124 fd_set ifdset, ofdset, efdset;
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
125 double timeout;
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
126 struct timeval tv, *tvp;
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
127 int seconds;
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
128 int imax, omax, emax, max;
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
129 int n;
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
130
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
131
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
132 /* Get args. Looks funny because of optional timeout argument */
1390
cffe8d6b2f09 * selectmodule.c (select_select): timeout argument may be None with same
Guido van Rossum <guido@python.org>
parents: 1284
diff changeset
133 if ( getargs(args, "(OOOO)", &ifdlist, &ofdlist, &efdlist, &tout) ) {
cffe8d6b2f09 * selectmodule.c (select_select): timeout argument may be None with same
Guido van Rossum <guido@python.org>
parents: 1284
diff changeset
134 if (tout == None)
cffe8d6b2f09 * selectmodule.c (select_select): timeout argument may be None with same
Guido van Rossum <guido@python.org>
parents: 1284
diff changeset
135 tvp = (struct timeval *)0;
cffe8d6b2f09 * selectmodule.c (select_select): timeout argument may be None with same
Guido van Rossum <guido@python.org>
parents: 1284
diff changeset
136 else {
1392
0ffff40d13ff Fixed a couple of bugs: getargs doesn't use % escapes, and seconds
Sjoerd Mullender <sjoerd@acm.org>
parents: 1390
diff changeset
137 if (!getargs(tout, "d;timeout must be float or None", &timeout))
1390
cffe8d6b2f09 * selectmodule.c (select_select): timeout argument may be None with same
Guido van Rossum <guido@python.org>
parents: 1284
diff changeset
138 return NULL;
1392
0ffff40d13ff Fixed a couple of bugs: getargs doesn't use % escapes, and seconds
Sjoerd Mullender <sjoerd@acm.org>
parents: 1390
diff changeset
139 seconds = (int)timeout;
1390
cffe8d6b2f09 * selectmodule.c (select_select): timeout argument may be None with same
Guido van Rossum <guido@python.org>
parents: 1284
diff changeset
140 timeout = timeout - (double)seconds;
cffe8d6b2f09 * selectmodule.c (select_select): timeout argument may be None with same
Guido van Rossum <guido@python.org>
parents: 1284
diff changeset
141 tv.tv_sec = seconds;
cffe8d6b2f09 * selectmodule.c (select_select): timeout argument may be None with same
Guido van Rossum <guido@python.org>
parents: 1284
diff changeset
142 tv.tv_usec = (int)(timeout*1000000.0);
cffe8d6b2f09 * selectmodule.c (select_select): timeout argument may be None with same
Guido van Rossum <guido@python.org>
parents: 1284
diff changeset
143 tvp = &tv;
cffe8d6b2f09 * selectmodule.c (select_select): timeout argument may be None with same
Guido van Rossum <guido@python.org>
parents: 1284
diff changeset
144 }
902
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
145 } else {
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
146 /* Doesn't have 4 args, that means no timeout */
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
147 err_clear();
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
148 if (!getargs(args, "(OOO)", &ifdlist, &ofdlist, &efdlist) )
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
149 return 0;
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
150 tvp = (struct timeval *)0;
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
151 }
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
152 if ( !is_listobject(ifdlist) || !is_listobject(ofdlist) ||
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
153 !is_listobject(efdlist) ) {
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
154 err_badarg();
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
155 return 0;
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
156 }
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
157
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
158 /* Convert lists to fd_sets, and get maximum fd number */
2611
01687ce43708 fix subtle refcnt bug
Guido van Rossum <guido@python.org>
parents: 2061
diff changeset
159 if( (imax=list2set(ifdlist, &ifdset, rfd2obj)) < 0 )
902
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
160 return 0;
2611
01687ce43708 fix subtle refcnt bug
Guido van Rossum <guido@python.org>
parents: 2061
diff changeset
161 if( (omax=list2set(ofdlist, &ofdset, wfd2obj)) < 0 )
902
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
162 return 0;
2611
01687ce43708 fix subtle refcnt bug
Guido van Rossum <guido@python.org>
parents: 2061
diff changeset
163 if( (emax=list2set(efdlist, &efdset, efd2obj)) < 0 )
902
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
164 return 0;
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
165 max = imax;
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
166 if ( omax > max ) max = omax;
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
167 if ( emax > max ) max = emax;
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
168
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 922
diff changeset
169 BGN_SAVE
902
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
170 n = select(max, &ifdset, &ofdset, &efdset, tvp);
926
c156d4960c2b * Makefile: cosmetics
Guido van Rossum <guido@python.org>
parents: 922
diff changeset
171 END_SAVE
902
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
172
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
173 if ( n < 0 ) {
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
174 err_errno(SelectError);
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
175 return 0;
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
176 }
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
177
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
178 if ( n == 0 )
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
179 imax = omax = emax = 0; /* Speedup hack */
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
180
2611
01687ce43708 fix subtle refcnt bug
Guido van Rossum <guido@python.org>
parents: 2061
diff changeset
181 ifdlist = set2list(&ifdset, imax, rfd2obj);
01687ce43708 fix subtle refcnt bug
Guido van Rossum <guido@python.org>
parents: 2061
diff changeset
182 ofdlist = set2list(&ofdset, omax, wfd2obj);
01687ce43708 fix subtle refcnt bug
Guido van Rossum <guido@python.org>
parents: 2061
diff changeset
183 efdlist = set2list(&efdset, emax, efd2obj);
1207
b564bd4e57e1 * ceval.c: ifdef out the last argument passing compat hack.
Guido van Rossum <guido@python.org>
parents: 927
diff changeset
184 ret = mkvalue("OOO", ifdlist, ofdlist, efdlist);
b564bd4e57e1 * ceval.c: ifdef out the last argument passing compat hack.
Guido van Rossum <guido@python.org>
parents: 927
diff changeset
185 XDECREF(ifdlist);
b564bd4e57e1 * ceval.c: ifdef out the last argument passing compat hack.
Guido van Rossum <guido@python.org>
parents: 927
diff changeset
186 XDECREF(ofdlist);
b564bd4e57e1 * ceval.c: ifdef out the last argument passing compat hack.
Guido van Rossum <guido@python.org>
parents: 927
diff changeset
187 XDECREF(efdlist);
b564bd4e57e1 * ceval.c: ifdef out the last argument passing compat hack.
Guido van Rossum <guido@python.org>
parents: 927
diff changeset
188 return ret;
902
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
189 }
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
190
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
191
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
192 static struct methodlist select_methods[] = {
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
193 { "select", select_select },
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
194 { 0, 0 },
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
195 };
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
196
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
197
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
198 void
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
199 initselect()
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
200 {
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
201 object *m, *d;
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
202 m = initmodule("select", select_methods);
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
203 d = getmoduledict(m);
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
204 SelectError = newstringobject("select.error");
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
205 if ( SelectError == NULL || dictinsert(d, "error", SelectError) )
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
206 fatal("Cannot define select.error");
a4793ae26682 Changes for new UNIX-specific built-in module 'select' and new header for
Guido van Rossum <guido@python.org>
parents:
diff changeset
207 }