public inbox for newlib-cvs@sourceware.org
help / color / mirror / Atom feed
* [newlib-cygwin] select.h: update FD macros to latest FreeBSD, fix type conversion warning
@ 2020-08-03 10:42 Corinna Vinschen
0 siblings, 0 replies; only message in thread
From: Corinna Vinschen @ 2020-08-03 10:42 UTC (permalink / raw)
To: newlib-cvs
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="us-ascii", Size: 3765 bytes --]
https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=5717262b8ecfed0f7fab63e2c09c78991e36f9dd
commit 5717262b8ecfed0f7fab63e2c09c78991e36f9dd
Author: Corinna Vinschen <corinna@vinschen.de>
Date: Mon Aug 3 12:40:43 2020 +0200
select.h: update FD macros to latest FreeBSD, fix type conversion warning
Compiling
#include <sys/select.h>
void f(int X)
{
fd_set set;
FD_ZERO(&set);
FD_SET(X,&set);
FD_CLR(X+1,&set);
(void)FD_ISSET(X+2,&set);
}
results in plenty of gcc warnings when compiled with
-Wconversion -Wsign-conversion:
fds.c:7:2: warning: conversion to ‘long unsigned int’ from ‘int’ may
FD_SET(X,&set);
^~~~~~
[...]
The unsigned NFDBITS macro combined with the signed 1L constant
are causing lots of implicit signed/unsigned type conversions.
Fix this by updating the FD_* macro code to the latest from FreeBSD
and adding an (int) cast to _NFDBITS.
As a side-effect, this fixes the visibility of NFDBITS and
fds_bits (only if __BSD_VISIBLE).
This also eliminates the old, outdated fd_set workaround.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Diff:
---
newlib/libc/include/sys/select.h | 68 ++++++++++++++++++++++++----------------
1 file changed, 41 insertions(+), 27 deletions(-)
diff --git a/newlib/libc/include/sys/select.h b/newlib/libc/include/sys/select.h
index 1e5d895bb..a5cd6c3fe 100644
--- a/newlib/libc/include/sys/select.h
+++ b/newlib/libc/include/sys/select.h
@@ -27,33 +27,47 @@ typedef __sigset_t sigset_t;
* FD_SETSIZE may be defined by the user, but the default here
* should be >= NOFILE (param.h).
*/
-# ifndef FD_SETSIZE
-# define FD_SETSIZE 64
-# endif
-
-typedef unsigned long fd_mask;
-# define NFDBITS (sizeof (fd_mask) * 8) /* bits per mask */
-# ifndef _howmany
-# define _howmany(x,y) (((x)+((y)-1))/(y))
-# endif
-
-/* We use a macro for fd_set so that including Sockets.h afterwards
- can work. */
-typedef struct _types_fd_set {
- fd_mask fds_bits[_howmany(FD_SETSIZE, NFDBITS)];
-} _types_fd_set;
-
-#define fd_set _types_fd_set
-
-# define FD_SET(n, p) ((p)->fds_bits[(n)/NFDBITS] |= (1L << ((n) % NFDBITS)))
-# define FD_CLR(n, p) ((p)->fds_bits[(n)/NFDBITS] &= ~(1L << ((n) % NFDBITS)))
-# define FD_ISSET(n, p) ((p)->fds_bits[(n)/NFDBITS] & (1L << ((n) % NFDBITS)))
-# define FD_ZERO(p) (__extension__ (void)({ \
- size_t __i; \
- char *__tmp = (char *)p; \
- for (__i = 0; __i < sizeof (*(p)); ++__i) \
- *__tmp++ = 0; \
-}))
+#ifndef FD_SETSIZE
+#define FD_SETSIZE 64
+#endif
+
+typedef unsigned long __fd_mask;
+#if __BSD_VISIBLE
+typedef __fd_mask fd_mask;
+#endif
+
+#define _NFDBITS ((int)sizeof(__fd_mask) * 8) /* bits per mask */
+#if __BSD_VISIBLE
+#define NFDBITS _NFDBITS
+#endif
+
+#ifndef _howmany
+#define _howmany(x,y) (((x) + ((y) - 1)) / (y))
+#endif
+
+typedef struct fd_set {
+ __fd_mask __fds_bits[_howmany(FD_SETSIZE, _NFDBITS)];
+} fd_set;
+#if __BSD_VISIBLE
+#define fds_bits __fds_bits
+#endif
+
+#define __fdset_mask(n) ((__fd_mask)1 << ((n) % _NFDBITS))
+#define FD_CLR(n, p) ((p)->__fds_bits[(n)/_NFDBITS] &= ~__fdset_mask(n))
+#if __BSD_VISIBLE
+#define FD_COPY(f, t) (void)(*(t) = *(f))
+#endif
+#define FD_ISSET(n, p) (((p)->__fds_bits[(n)/_NFDBITS] & __fdset_mask(n)) != 0)
+#define FD_SET(n, p) ((p)->__fds_bits[(n)/_NFDBITS] |= __fdset_mask(n))
+#define FD_ZERO(p) do { \
+ fd_set *_p; \
+ __size_t _n; \
+ \
+ _p = (p); \
+ _n = _howmany(FD_SETSIZE, _NFDBITS); \
+ while (_n > 0) \
+ _p->__fds_bits[--_n] = 0; \
+} while (0)
#if !defined (__INSIDE_CYGWIN_NET__)
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2020-08-03 10:42 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-03 10:42 [newlib-cygwin] select.h: update FD macros to latest FreeBSD, fix type conversion warning Corinna Vinschen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).