Sat Mar 4 22:07:14 2017 UTC ()
merge our local change to ensure FD_SETSIZE is set before <sys/select.h>
is included, using the new version of the code to set XFD_SETSIZE.


(mrg)
diff -r1.3 -r1.4 xsrc/external/mit/xproto/dist/Xpoll.h.in

cvs diff -r1.3 -r1.4 xsrc/external/mit/xproto/dist/Attic/Xpoll.h.in (switch to unified diff)

--- xsrc/external/mit/xproto/dist/Attic/Xpoll.h.in 2015/07/17 07:02:40 1.3
+++ xsrc/external/mit/xproto/dist/Attic/Xpoll.h.in 2017/03/04 22:07:14 1.4
@@ -1,227 +1,230 @@ @@ -1,227 +1,230 @@
1/* 1/*
2 2
3Copyright 1994, 1998 The Open Group 3Copyright 1994, 1998 The Open Group
4 4
5Permission to use, copy, modify, distribute, and sell this software and its 5Permission to use, copy, modify, distribute, and sell this software and its
6documentation for any purpose is hereby granted without fee, provided that 6documentation for any purpose is hereby granted without fee, provided that
7the above copyright notice appear in all copies and that both that 7the above copyright notice appear in all copies and that both that
8copyright notice and this permission notice appear in supporting 8copyright notice and this permission notice appear in supporting
9documentation. 9documentation.
10 10
11The above copyright notice and this permission notice shall be included 11The above copyright notice and this permission notice shall be included
12in all copies or substantial portions of the Software. 12in all copies or substantial portions of the Software.
13 13
14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 15OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR 17IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
18OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 18OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 19ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20OTHER DEALINGS IN THE SOFTWARE. 20OTHER DEALINGS IN THE SOFTWARE.
21 21
22Except as contained in this notice, the name of The Open Group shall 22Except as contained in this notice, the name of The Open Group shall
23not be used in advertising or otherwise to promote the sale, use or 23not be used in advertising or otherwise to promote the sale, use or
24other dealings in this Software without prior written authorization 24other dealings in this Software without prior written authorization
25from The Open Group. 25from The Open Group.
26 26
27*/ 27*/
28 28
29/* 29/*
30 * Copyright © 2005 Daniel Stone 30 * Copyright © 2005 Daniel Stone
31 *  31 *
32 * Permission to use, copy, modify, distribute, and sell this software and its 32 * Permission to use, copy, modify, distribute, and sell this software and its
33 * documentation for any purpose is hereby granted without fee, provided that 33 * documentation for any purpose is hereby granted without fee, provided that
34 * the above copyright notice appear in all copies and that both that 34 * the above copyright notice appear in all copies and that both that
35 * copyright notice and this permission notice appear in supporting 35 * copyright notice and this permission notice appear in supporting
36 * documentation, and that the name of Daniel Stone not be used in advertising 36 * documentation, and that the name of Daniel Stone not be used in advertising
37 * or publicity pertaining to distribution of the software without specific, 37 * or publicity pertaining to distribution of the software without specific,
38 * written prior permission. Daniel Stone makes no representations about the 38 * written prior permission. Daniel Stone makes no representations about the
39 * suitability of this software for any purpose. It is provided "as is" 39 * suitability of this software for any purpose. It is provided "as is"
40 * without express or implied warranty. 40 * without express or implied warranty.
41 * 41 *
42 * DANIEL STONE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING 42 * DANIEL STONE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
43 * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL 43 * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
44 * DANIEL STONE BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR 44 * DANIEL STONE BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
45 * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER 45 * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
46 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 46 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
47 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 47 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
48*/ 48*/
49 49
50#ifndef _XPOLL_H_ 50#ifndef _XPOLL_H_
51#define _XPOLL_H_ 51#define _XPOLL_H_
52 52
53#if !defined(WIN32) || defined(__CYGWIN__) 53#if !defined(WIN32) || defined(__CYGWIN__)
54 54
55#ifndef USE_POLL 55#ifndef USE_POLL
56 56
57#define XFD_SETSIZE 512 57#if defined(FD_SETSIZE) && FD_SETSIZE < 512
58 58# define XFD_SETSIZE FD_SETSIZE
59#ifndef FD_SETSIZE 59#else
60#define FD_SETSIZE XFD_SETSIZE 60# define XFD_SETSIZE 512
 61# ifndef FD_SETSIZE
 62# define FD_SETSIZE XFD_SETSIZE
 63# endif
61#endif 64#endif
62 65
63#include <X11/Xos.h> 66#include <X11/Xos.h>
64 67
65#include <sys/select.h> /* Get the FD_* macros. */ 68#include <sys/select.h> /* Get the FD_* macros. */
66 69
67#include <X11/Xmd.h> 70#include <X11/Xmd.h>
68 71
69#ifdef CSRG_BASED 72#ifdef CSRG_BASED
70#include <sys/param.h> 73#include <sys/param.h>
71# if BSD < 199103 74# if BSD < 199103
72typedef long fd_mask; 75typedef long fd_mask;
73# endif 76# endif
74#endif 77#endif
75 78
76#ifndef NBBY 79#ifndef NBBY
77#define NBBY 8 /* number of bits in a byte */ 80#define NBBY 8 /* number of bits in a byte */
78#endif 81#endif
79 82
80#ifndef NFDBITS 83#ifndef NFDBITS
81#define NFDBITS (sizeof(fd_mask) * NBBY) /* bits per mask */ 84#define NFDBITS (sizeof(fd_mask) * NBBY) /* bits per mask */
82#endif 85#endif
83 86
84#ifndef howmany 87#ifndef howmany
85#define howmany(x,y) (((x)+((y)-1))/(y)) 88#define howmany(x,y) (((x)+((y)-1))/(y))
86#endif 89#endif
87 90
88#if defined(BSD) && BSD < 198911  91#if defined(BSD) && BSD < 198911
89typedef struct fd_set { 92typedef struct fd_set {
90 fd_mask fds_bits[howmany(FD_SETSIZE, NFDBITS)]; 93 fd_mask fds_bits[howmany(FD_SETSIZE, NFDBITS)];
91} fd_set; 94} fd_set;
92#endif 95#endif
93 96
94# define Select(n,r,w,e,t) select(n,(fd_set*)r,(fd_set*)w,(fd_set*)e,(struct timeval*)t) 97# define Select(n,r,w,e,t) select(n,(fd_set*)r,(fd_set*)w,(fd_set*)e,(struct timeval*)t)
95 98
96#define __X_FDS_BITS @USE_FDS_BITS@ 99#define __X_FDS_BITS @USE_FDS_BITS@
97 100
98#ifndef __FDS_BITS 101#ifndef __FDS_BITS
99# define __FDS_BITS(p) ((p)->__X_FDS_BITS) 102# define __FDS_BITS(p) ((p)->__X_FDS_BITS)
100#endif 103#endif
101 104
102#define __XFDS_BITS(p, n) (__FDS_BITS(p))[n] 105#define __XFDS_BITS(p, n) (__FDS_BITS(p))[n]
103 106
104#ifndef FD_SET 107#ifndef FD_SET
105#define FD_SET(n, p) (__XFDS_BITS(p, ((n)/NFDBITS)) |= ((fd_mask)1 << ((n) % NFDBITS))) 108#define FD_SET(n, p) (__XFDS_BITS(p, ((n)/NFDBITS)) |= ((fd_mask)1 << ((n) % NFDBITS)))
106#endif 109#endif
107#ifndef FD_CLR 110#ifndef FD_CLR
108#define FD_CLR(n, p) (__XFDS_BITS((p), ((n)/NFDBITS)) &= ~((fd_mask)1 << ((n) % NFDBITS))) 111#define FD_CLR(n, p) (__XFDS_BITS((p), ((n)/NFDBITS)) &= ~((fd_mask)1 << ((n) % NFDBITS)))
109#endif 112#endif
110#ifndef FD_ISSET 113#ifndef FD_ISSET
111#define FD_ISSET(n, p) ((__XFDS_BITS((p), ((n)/NFDBITS))) & ((fd_mask)1 << ((n) % NFDBITS))) 114#define FD_ISSET(n, p) ((__XFDS_BITS((p), ((n)/NFDBITS))) & ((fd_mask)1 << ((n) % NFDBITS)))
112#endif 115#endif
113#ifndef FD_ZERO 116#ifndef FD_ZERO
114#define FD_ZERO(p) bzero((char *)(p), sizeof(*(p))) 117#define FD_ZERO(p) bzero((char *)(p), sizeof(*(p)))
115#endif 118#endif
116 119
117/* 120/*
118 * The howmany(FD_SETSIZE, NFDBITS) computes the number of elements in the 121 * The howmany(FD_SETSIZE, NFDBITS) computes the number of elements in the
119 * array. before accessing an element in the array we check it exists. 122 * array. before accessing an element in the array we check it exists.
120 * If it does not exist then the compiler discards the code to access it.  123 * If it does not exist then the compiler discards the code to access it.
121 */ 124 */
122#define XFD_ANYSET(p) \ 125#define XFD_ANYSET(p) \
123 ((howmany(FD_SETSIZE, NFDBITS) > 0 && (__XFDS_BITS(p, 0))) || \ 126 ((howmany(FD_SETSIZE, NFDBITS) > 0 && (__XFDS_BITS(p, 0))) || \
124 (howmany(FD_SETSIZE, NFDBITS) > 1 && (__XFDS_BITS(p, 1))) || \ 127 (howmany(FD_SETSIZE, NFDBITS) > 1 && (__XFDS_BITS(p, 1))) || \
125 (howmany(FD_SETSIZE, NFDBITS) > 2 && (__XFDS_BITS(p, 2))) || \ 128 (howmany(FD_SETSIZE, NFDBITS) > 2 && (__XFDS_BITS(p, 2))) || \
126 (howmany(FD_SETSIZE, NFDBITS) > 3 && (__XFDS_BITS(p, 3))) || \ 129 (howmany(FD_SETSIZE, NFDBITS) > 3 && (__XFDS_BITS(p, 3))) || \
127 (howmany(FD_SETSIZE, NFDBITS) > 4 && (__XFDS_BITS(p, 4))) || \ 130 (howmany(FD_SETSIZE, NFDBITS) > 4 && (__XFDS_BITS(p, 4))) || \
128 (howmany(FD_SETSIZE, NFDBITS) > 5 && (__XFDS_BITS(p, 5))) || \ 131 (howmany(FD_SETSIZE, NFDBITS) > 5 && (__XFDS_BITS(p, 5))) || \
129 (howmany(FD_SETSIZE, NFDBITS) > 6 && (__XFDS_BITS(p, 6))) || \ 132 (howmany(FD_SETSIZE, NFDBITS) > 6 && (__XFDS_BITS(p, 6))) || \
130 (howmany(FD_SETSIZE, NFDBITS) > 7 && (__XFDS_BITS(p, 7))) || \ 133 (howmany(FD_SETSIZE, NFDBITS) > 7 && (__XFDS_BITS(p, 7))) || \
131 (howmany(FD_SETSIZE, NFDBITS) > 8 && (__XFDS_BITS(p, 8))) || \ 134 (howmany(FD_SETSIZE, NFDBITS) > 8 && (__XFDS_BITS(p, 8))) || \
132 (howmany(FD_SETSIZE, NFDBITS) > 9 && (__XFDS_BITS(p, 9))) || \ 135 (howmany(FD_SETSIZE, NFDBITS) > 9 && (__XFDS_BITS(p, 9))) || \
133 (howmany(FD_SETSIZE, NFDBITS) > 10 && (__XFDS_BITS(p, 10))) || \ 136 (howmany(FD_SETSIZE, NFDBITS) > 10 && (__XFDS_BITS(p, 10))) || \
134 (howmany(FD_SETSIZE, NFDBITS) > 11 && (__XFDS_BITS(p, 11))) || \ 137 (howmany(FD_SETSIZE, NFDBITS) > 11 && (__XFDS_BITS(p, 11))) || \
135 (howmany(FD_SETSIZE, NFDBITS) > 12 && (__XFDS_BITS(p, 12))) || \ 138 (howmany(FD_SETSIZE, NFDBITS) > 12 && (__XFDS_BITS(p, 12))) || \
136 (howmany(FD_SETSIZE, NFDBITS) > 13 && (__XFDS_BITS(p, 13))) || \ 139 (howmany(FD_SETSIZE, NFDBITS) > 13 && (__XFDS_BITS(p, 13))) || \
137 (howmany(FD_SETSIZE, NFDBITS) > 14 && (__XFDS_BITS(p, 14))) || \ 140 (howmany(FD_SETSIZE, NFDBITS) > 14 && (__XFDS_BITS(p, 14))) || \
138 (howmany(FD_SETSIZE, NFDBITS) > 15 && (__XFDS_BITS(p, 15)))) 141 (howmany(FD_SETSIZE, NFDBITS) > 15 && (__XFDS_BITS(p, 15))))
139 142
140 143
141#define XFD_COPYSET(src,dst) { \ 144#define XFD_COPYSET(src,dst) { \
142 int __i__; \ 145 int __i__; \
143 for (__i__ = 0; __i__ < howmany(FD_SETSIZE, NFDBITS); __i__++) \ 146 for (__i__ = 0; __i__ < howmany(FD_SETSIZE, NFDBITS); __i__++) \
144 __XFDS_BITS((dst), __i__) = __XFDS_BITS((src), __i__); \ 147 __XFDS_BITS((dst), __i__) = __XFDS_BITS((src), __i__); \
145 } 148 }
146#define XFD_ANDSET(dst,b1,b2) { \ 149#define XFD_ANDSET(dst,b1,b2) { \
147 int __i__; \ 150 int __i__; \
148 for (__i__ = 0; __i__ < howmany(FD_SETSIZE, NFDBITS); __i__++) \ 151 for (__i__ = 0; __i__ < howmany(FD_SETSIZE, NFDBITS); __i__++) \
149 __XFDS_BITS((dst), __i__) = ((__XFDS_BITS((b1), __i__)) & (__XFDS_BITS((b2), __i__))); \ 152 __XFDS_BITS((dst), __i__) = ((__XFDS_BITS((b1), __i__)) & (__XFDS_BITS((b2), __i__))); \
150 } 153 }
151#define XFD_ORSET(dst,b1,b2) { \ 154#define XFD_ORSET(dst,b1,b2) { \
152 int __i__; \ 155 int __i__; \
153 for (__i__ = 0; __i__ < howmany(FD_SETSIZE, NFDBITS); __i__++) \ 156 for (__i__ = 0; __i__ < howmany(FD_SETSIZE, NFDBITS); __i__++) \
154 __XFDS_BITS((dst), __i__) = ((__XFDS_BITS((b1), __i__)) | (__XFDS_BITS((b2), __i__))); \ 157 __XFDS_BITS((dst), __i__) = ((__XFDS_BITS((b1), __i__)) | (__XFDS_BITS((b2), __i__))); \
155 }  158 }
156#define XFD_UNSET(dst,b1) { \ 159#define XFD_UNSET(dst,b1) { \
157 int __i__; \ 160 int __i__; \
158 for (__i__ = 0; __i__ < howmany(FD_SETSIZE, NFDBITS); __i__++) \ 161 for (__i__ = 0; __i__ < howmany(FD_SETSIZE, NFDBITS); __i__++) \
159 __XFDS_BITS((dst), __i__) &= ~(__XFDS_BITS((b1), __i__)); \ 162 __XFDS_BITS((dst), __i__) &= ~(__XFDS_BITS((b1), __i__)); \
160 } 163 }
161 164
162#else /* USE_POLL */ 165#else /* USE_POLL */
163#include <sys/poll.h> 166#include <sys/poll.h>
164#endif /* USE_POLL */ 167#endif /* USE_POLL */
165 168
166#else /* WIN32 */ 169#else /* WIN32 */
167 170
168#define XFD_SETSIZE 256 171#define XFD_SETSIZE 512
169#ifndef FD_SETSIZE 172#ifndef FD_SETSIZE
170#define FD_SETSIZE XFD_SETSIZE 173#define FD_SETSIZE XFD_SETSIZE
171#endif 174#endif
172#include <X11/Xwinsock.h> 175#include <X11/Xwinsock.h>
173 176
174#define Select(n,r,w,e,t) select(0,(fd_set*)r,(fd_set*)w,(fd_set*)e,(struct timeval*)t) 177#define Select(n,r,w,e,t) select(0,(fd_set*)r,(fd_set*)w,(fd_set*)e,(struct timeval*)t)
175 178
176#define XFD_SETCOUNT(p) (((fd_set FAR *)(p))->fd_count) 179#define XFD_SETCOUNT(p) (((fd_set FAR *)(p))->fd_count)
177#define XFD_FD(p,i) (((fd_set FAR *)(p))->fd_array[i]) 180#define XFD_FD(p,i) (((fd_set FAR *)(p))->fd_array[i])
178#define XFD_ANYSET(p) XFD_SETCOUNT(p) 181#define XFD_ANYSET(p) XFD_SETCOUNT(p)
179 182
180#define XFD_COPYSET(src,dst) { \ 183#define XFD_COPYSET(src,dst) { \
181 u_int __i; \ 184 u_int __i; \
182 FD_ZERO(dst); \ 185 FD_ZERO(dst); \
183 for (__i = 0; __i < XFD_SETCOUNT(src) ; __i++) { \ 186 for (__i = 0; __i < XFD_SETCOUNT(src) ; __i++) { \
184 XFD_FD(dst,__i) = XFD_FD(src,__i); \ 187 XFD_FD(dst,__i) = XFD_FD(src,__i); \
185 } \ 188 } \
186 XFD_SETCOUNT(dst) = XFD_SETCOUNT(src); \ 189 XFD_SETCOUNT(dst) = XFD_SETCOUNT(src); \
187} 190}
188 191
189#define XFD_ANDSET(dst,b1,b2) { \ 192#define XFD_ANDSET(dst,b1,b2) { \
190 u_int __i; \ 193 u_int __i; \
191 FD_ZERO(dst); \ 194 FD_ZERO(dst); \
192 for (__i = 0; __i < XFD_SETCOUNT(b1) ; __i++) { \ 195 for (__i = 0; __i < XFD_SETCOUNT(b1) ; __i++) { \
193 if (FD_ISSET(XFD_FD(b1,__i), b2)) \ 196 if (FD_ISSET(XFD_FD(b1,__i), b2)) \
194 FD_SET(XFD_FD(b1,__i), dst); \ 197 FD_SET(XFD_FD(b1,__i), dst); \
195 } \ 198 } \
196} 199}
197 200
198#define XFD_ORSET(dst,b1,b2) { \ 201#define XFD_ORSET(dst,b1,b2) { \
199 u_int __i; \ 202 u_int __i; \
200 if (dst != b1) XFD_COPYSET(b1,dst); \ 203 if (dst != b1) XFD_COPYSET(b1,dst); \
201 for (__i = 0; __i < XFD_SETCOUNT(b2) ; __i++) { \ 204 for (__i = 0; __i < XFD_SETCOUNT(b2) ; __i++) { \
202 if (!FD_ISSET(XFD_FD(b2,__i), dst)) \ 205 if (!FD_ISSET(XFD_FD(b2,__i), dst)) \
203 FD_SET(XFD_FD(b2,__i), dst); \ 206 FD_SET(XFD_FD(b2,__i), dst); \
204 } \ 207 } \
205} 208}
206 209
207/* this one is really sub-optimal */ 210/* this one is really sub-optimal */
208#define XFD_UNSET(dst,b1) { \ 211#define XFD_UNSET(dst,b1) { \
209 u_int __i; \ 212 u_int __i; \
210 for (__i = 0; __i < XFD_SETCOUNT(b1) ; __i++) { \ 213 for (__i = 0; __i < XFD_SETCOUNT(b1) ; __i++) { \
211 FD_CLR(XFD_FD(b1,__i), dst); \ 214 FD_CLR(XFD_FD(b1,__i), dst); \
212 } \ 215 } \
213} 216}
214 217
215/* we have to pay the price of having an array here, unlike with bitmasks 218/* we have to pay the price of having an array here, unlike with bitmasks
216 calling twice FD_SET with the same fd is not transparent, so be careful */ 219 calling twice FD_SET with the same fd is not transparent, so be careful */
217#undef FD_SET 220#undef FD_SET
218#define FD_SET(fd,set) do { \ 221#define FD_SET(fd,set) do { \
219 if (XFD_SETCOUNT(set) < FD_SETSIZE && !FD_ISSET(fd,set)) \ 222 if (XFD_SETCOUNT(set) < FD_SETSIZE && !FD_ISSET(fd,set)) \
220 XFD_FD(set,XFD_SETCOUNT(set)++)=(fd); \ 223 XFD_FD(set,XFD_SETCOUNT(set)++)=(fd); \
221} while(0) 224} while(0)
222 225
223#define getdtablesize() FD_SETSIZE  226#define getdtablesize() FD_SETSIZE
224 227
225#endif /* WIN32 */ 228#endif /* WIN32 */
226 229
227#endif /* _XPOLL_H_ */ 230#endif /* _XPOLL_H_ */