]> git.kaiwu.me - haproxy.git/commitdiff
[CLEANUP] remove dependency on obsolete INTBITS macro
authorWilly Tarreau <w@1wt.eu>
Mon, 14 Jul 2008 22:36:31 +0000 (00:36 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 2 Sep 2008 09:13:07 +0000 (11:13 +0200)
The INTBITS macro was found to be already defined on some platforms,
and to equal 32 (while INTBITS was 5 here). Due to pure luck, there
was no declaration conflict, but it's nonetheless a problem to fix.

Looking at the code showed that this macro was only used for left
shifts and nothing else anymore. So the replacement is obvious. The
new macro, BITS_PER_INT is more obviously correct.
(cherry picked from commit 177e2b012723ef65c6c7f850df3e6e0cd2cca2b4)
(cherry picked from commit 0e3e59b11f7926a570cfc98d8967b61098c91602)

include/common/compat.h
src/ev_poll.c
src/ev_select.c
src/haproxy.c

index a41be70ca8c5130d623411fb4006f975d838b7a3..ef3342485132b43a01001ce48ce18a92ba926579 100644 (file)
 #include <common/config.h>
 #include <common/standard.h>
 
-/* INTBITS
- * how many bits are needed to code the size of an int on the target platform.
- * (eg: 32bits -> 5)
- */
-#define        INTBITS         5
+#ifndef BITS_PER_INT
+#define BITS_PER_INT    (8*sizeof(int))
+#endif
 
 /* this is for libc5 for example */
 #ifndef TCP_NODELAY
index b50b2232d341849c76fe78845c0ca1bf7002fa8d..7773d0fc97d857e437279d3618bd48b151d4f0f4 100644 (file)
@@ -92,13 +92,13 @@ REGPRM2 static void _do_poll(struct poller *p, struct timeval *exp)
        unsigned rn, wn; /* read new, write new */
 
        nbfd = 0;
-       for (fds = 0; (fds << INTBITS) < maxfd; fds++) {
+       for (fds = 0; (fds * BITS_PER_INT) < maxfd; fds++) {
 
                rn = ((int*)fd_evts[DIR_RD])[fds];
                wn = ((int*)fd_evts[DIR_WR])[fds];
          
                if ((rn|wn)) {
-                       for (count = 0, fd = fds << INTBITS; count < (1<<INTBITS) && fd < maxfd; count++, fd++) {
+                       for (count = 0, fd = fds * BITS_PER_INT; count < BITS_PER_INT && fd < maxfd; count++, fd++) {
 #define FDSETS_ARE_INT_ALIGNED
 #ifdef FDSETS_ARE_INT_ALIGNED
 
@@ -107,8 +107,8 @@ REGPRM2 static void _do_poll(struct poller *p, struct timeval *exp)
                                sr = (rn >> count) & 1;
                                sw = (wn >> count) & 1;
 #else
-                               sr = FD_ISSET(fd&((1<<INTBITS)-1), (typeof(fd_set*))&rn);
-                               sw = FD_ISSET(fd&((1<<INTBITS)-1), (typeof(fd_set*))&wn);
+                               sr = FD_ISSET(fd&(BITS_PER_INT-1), (typeof(fd_set*))&rn);
+                               sw = FD_ISSET(fd&(BITS_PER_INT-1), (typeof(fd_set*))&wn);
 #endif
 #else
                                sr = FD_ISSET(fd, fd_evts[DIR_RD]);
index bbbbfe0ccc5f419ca4d1b2ea1cb368d837a559bf..fbef07079b66080675456f6f41b29ff2297de91f 100644 (file)
@@ -129,11 +129,11 @@ REGPRM2 static void _do_poll(struct poller *p, struct timeval *exp)
        if (status <= 0)
                return;
 
-       for (fds = 0; (fds << INTBITS) < maxfd; fds++) {
+       for (fds = 0; (fds * BITS_PER_INT) < maxfd; fds++) {
                if ((((int *)(tmp_evts[DIR_RD]))[fds] | ((int *)(tmp_evts[DIR_WR]))[fds]) == 0)
                        continue;
 
-               for (count = 1<<INTBITS, fd = fds << INTBITS; count && fd < maxfd; count--, fd++) {
+               for (count = BITS_PER_INT, fd = fds * BITS_PER_INT; count && fd < maxfd; count--, fd++) {
                        /* if we specify read first, the accepts and zero reads will be
                         * seen first. Moreover, system buffers will be flushed faster.
                         */
index 38d49e7bb76c69b359b62f60f4c55a99345889c9..d80620487869797cb96bb09bf1e17cc906f41d54 100644 (file)
@@ -397,13 +397,6 @@ void init(int argc, char **argv)
        char *tmp;
        char *cfg_pidfile = NULL;
 
-       if (1<<INTBITS != sizeof(int)*8) {
-               fprintf(stderr,
-                       "Error: wrong architecture. Recompile so that sizeof(int)=%d\n",
-                       (int)(sizeof(int)*8));
-               exit(1);
-       }
-
        /*
         * Initialize the previously static variables.
         */