]> git.ipfire.org Git - thirdparty/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>
Wed, 16 Jul 2008 08:30:44 +0000 (10:30 +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.

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

index 4e86325e69e80a225a3fbe80b41963b21cd75611..8d406e5c469832555b5bcc1909e55b0a178c8631 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 5f0a2c49b94f696db8fbbdf52382de57e9f3df5b..4a1eb8bf93b51a4fde6c92c9403a89b5ac3c7eaf 100644 (file)
@@ -92,13 +92,13 @@ REGPRM2 static void _do_poll(struct poller *p, int 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, int 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 95663ffef8c533a569984414568bbe933b908e3b..90754050da8517eae88bf2fd768fbd9f8d3bd153 100644 (file)
@@ -135,11 +135,11 @@ REGPRM2 static void _do_poll(struct poller *p, int 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 1d3089a58710374a515ef4822775a25d8657e667..9ef07f29fc831fbe20d150334914970668f66ffd 100644 (file)
@@ -395,13 +395,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.
         */