comparison 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
comparison
equal deleted inserted replaced
2610:b02573eeb182 2611:01687ce43708
39 fd_set *set; 39 fd_set *set;
40 object *fd2obj[FD_SETSIZE]; 40 object *fd2obj[FD_SETSIZE];
41 { 41 {
42 int i, len, v, max = -1; 42 int i, len, v, max = -1;
43 object *o, *filenomethod, *fno; 43 object *o, *filenomethod, *fno;
44
45 for ( i=0; i<FD_SETSIZE; i++ ) {
46 fd2obj[i] = (object*)0;
47 }
44 48
45 FD_ZERO(set); 49 FD_ZERO(set);
46 len = getlistsize(list); 50 len = getlistsize(list);
47 for( i=0; i<len; i++ ) { 51 for( i=0; i<len; i++ ) {
48 o = getlistitem(list, i); 52 o = getlistitem(list, i);
68 err_setstr(ValueError, "filedescriptor out of range in select()"); 72 err_setstr(ValueError, "filedescriptor out of range in select()");
69 return -1; 73 return -1;
70 } 74 }
71 if ( v > max ) max = v; 75 if ( v > max ) max = v;
72 FD_SET(v, set); 76 FD_SET(v, set);
73 XDECREF(fd2obj[v]);
74 fd2obj[v] = o; 77 fd2obj[v] = o;
75 } 78 }
76 return max+1; 79 return max+1;
77 } 80 }
78 81
113 static object * 116 static object *
114 select_select(self, args) 117 select_select(self, args)
115 object *self; 118 object *self;
116 object *args; 119 object *args;
117 { 120 {
118 object *fd2obj[FD_SETSIZE]; 121 object *rfd2obj[FD_SETSIZE], *wfd2obj[FD_SETSIZE], *efd2obj[FD_SETSIZE];
119 object *ifdlist, *ofdlist, *efdlist; 122 object *ifdlist, *ofdlist, *efdlist;
120 object *ret, *tout; 123 object *ret, *tout;
121 fd_set ifdset, ofdset, efdset; 124 fd_set ifdset, ofdset, efdset;
122 double timeout; 125 double timeout;
123 struct timeval tv, *tvp; 126 struct timeval tv, *tvp;
150 !is_listobject(efdlist) ) { 153 !is_listobject(efdlist) ) {
151 err_badarg(); 154 err_badarg();
152 return 0; 155 return 0;
153 } 156 }
154 157
155 memset((char *)fd2obj, '\0', sizeof(fd2obj));
156
157 /* Convert lists to fd_sets, and get maximum fd number */ 158 /* Convert lists to fd_sets, and get maximum fd number */
158 if( (imax=list2set(ifdlist, &ifdset, fd2obj)) < 0 ) 159 if( (imax=list2set(ifdlist, &ifdset, rfd2obj)) < 0 )
159 return 0; 160 return 0;
160 if( (omax=list2set(ofdlist, &ofdset, fd2obj)) < 0 ) 161 if( (omax=list2set(ofdlist, &ofdset, wfd2obj)) < 0 )
161 return 0; 162 return 0;
162 if( (emax=list2set(efdlist, &efdset, fd2obj)) < 0 ) 163 if( (emax=list2set(efdlist, &efdset, efd2obj)) < 0 )
163 return 0; 164 return 0;
164 max = imax; 165 max = imax;
165 if ( omax > max ) max = omax; 166 if ( omax > max ) max = omax;
166 if ( emax > max ) max = emax; 167 if ( emax > max ) max = emax;
167 168
175 } 176 }
176 177
177 if ( n == 0 ) 178 if ( n == 0 )
178 imax = omax = emax = 0; /* Speedup hack */ 179 imax = omax = emax = 0; /* Speedup hack */
179 180
180 ifdlist = set2list(&ifdset, imax, fd2obj); 181 ifdlist = set2list(&ifdset, imax, rfd2obj);
181 ofdlist = set2list(&ofdset, omax, fd2obj); 182 ofdlist = set2list(&ofdset, omax, wfd2obj);
182 efdlist = set2list(&efdset, emax, fd2obj); 183 efdlist = set2list(&efdset, emax, efd2obj);
183 ret = mkvalue("OOO", ifdlist, ofdlist, efdlist); 184 ret = mkvalue("OOO", ifdlist, ofdlist, efdlist);
184 XDECREF(ifdlist); 185 XDECREF(ifdlist);
185 XDECREF(ofdlist); 186 XDECREF(ofdlist);
186 XDECREF(efdlist); 187 XDECREF(efdlist);
187 return ret; 188 return ret;