Changeset: 4a9234b37447 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=4a9234b37447
Modified Files:
        buildtools/Mx/Def.c
        gdk/gdk.h
        gdk/gdk_bbp.mx
        gdk/gdk_relop.mx
        gdk/gdk_search.mx
        gdk/gdk_system.h
        gdk/gdk_utils.mx
        monetdb5/extras/crackers/crackers_joins.mx
        monetdb5/mal/mal_instruction.mx
        monetdb5/mal/mal_recycle.c
        monetdb5/mal/mal_sabaoth.c
        monetdb5/modules/atoms/mtime.mx
        monetdb5/modules/mal/pqueue.mx
        monetdb5/optimizer/opt_emptySet.mx
        sql/include/sql_mem.h
        sql/server/sql_parser.y
        sql/storage/store.c
        testing/difflib.h
Branch: default
Log Message:

Use do/while(0) trick on all macro definitions where appropriate.
Remember, in `do ... while (0)', the body is executed exactly once,
and it needs a semicolon at the end, just like a normal function call
(which is what the macro invocation looks like).


diffs (truncated from 640 to 300 lines):

diff --git a/buildtools/Mx/Def.c b/buildtools/Mx/Def.c
--- a/buildtools/Mx/Def.c
+++ b/buildtools/Mx/Def.c
@@ -43,11 +43,11 @@ int ndef = 0;
 
 #define topCond() (condStack[condSP-1].defined)
 #define topMacro() (condStack[condSP-1].macro)
-#define pushCond(X,N) { condStack[condSP].defined = (X);\
-                       condStack[condSP++].macro = StrDup(N); }
-#define toggle() {if(topCond())condStack[condSP-1].defined=0;\
-                  else condStack[condSP-1].defined=1;}
-#define popCond() {if(condSP) condSP--;else Fatal("DefDir","IFDEF error");}
+#define pushCond(X,N) do { condStack[condSP].defined = (X);\
+               condStack[condSP++].macro = StrDup(N); } while (0)
+#define toggle() do {if(topCond())condStack[condSP-1].defined=0;\
+               else condStack[condSP-1].defined=1;} while (0)
+#define popCond() do {if(condSP) condSP--;else Fatal("DefDir","IFDEF error");} 
while (0)
 
 int
 allTrue(void)
diff --git a/gdk/gdk.h b/gdk/gdk.h
--- a/gdk/gdk.h
+++ b/gdk/gdk.h
@@ -2806,12 +2806,12 @@ gdk_export void VIEWbounds(BAT *b, BAT *
 /* low level functions */
 gdk_export int ALIGNsetH(BAT *b1, BAT *b2);
 
-#define ALIGNset(x,y)  {ALIGNsetH(x,y);ALIGNsetT(x,y);}
+#define ALIGNset(x,y)  do {ALIGNsetH(x,y);ALIGNsetT(x,y);} while (0)
 #define ALIGNsetT(x,y) ALIGNsetH(BATmirror(x),BATmirror(y))
-#define ALIGNins(x,y,f)        {if (!(f)) 
VIEWchk(x,y,BAT_READ);(x)->halign=(x)->talign=0; }
-#define ALIGNdel(x,y,f)        {if (!(f)) 
VIEWchk(x,y,BAT_READ|BAT_APPEND);(x)->halign=(x)->talign=0; }
-#define ALIGNinp(x,y,f) {if (!(f)) 
VIEWchk(x,y,BAT_READ|BAT_APPEND);(x)->talign=0; }
-#define ALIGNapp(x,y,f) {if (!(f)) VIEWchk(x,y,BAT_READ);(x)->talign=0; }
+#define ALIGNins(x,y,f)        do {if (!(f)) 
VIEWchk(x,y,BAT_READ);(x)->halign=(x)->talign=0; } while (0)
+#define ALIGNdel(x,y,f)        do {if (!(f)) 
VIEWchk(x,y,BAT_READ|BAT_APPEND);(x)->halign=(x)->talign=0; } while (0)
+#define ALIGNinp(x,y,f) do {if (!(f)) 
VIEWchk(x,y,BAT_READ|BAT_APPEND);(x)->talign=0; } while (0)
+#define ALIGNapp(x,y,f) do {if (!(f)) VIEWchk(x,y,BAT_READ);(x)->talign=0; } 
while (0)
 
 #define BAThrestricted(b) (VIEWhparent(b) ? 
BBP_cache(VIEWhparent(b))->batRestricted : (b)->batRestricted)
 #define BATtrestricted(b) (VIEWtparent(b) ? 
BBP_cache(VIEWtparent(b))->batRestricted : (b)->batRestricted)
diff --git a/gdk/gdk_bbp.mx b/gdk/gdk_bbp.mx
--- a/gdk/gdk_bbp.mx
+++ b/gdk/gdk_bbp.mx
@@ -296,9 +296,10 @@ int BBPout = 0;                    /* bats saved statisti
  * may be modified).
  */
 @h
-#define BBP_status_set(bid, mode, nme) {       \
+#define BBP_status_set(bid, mode, nme)         \
+       do {                                    \
                BBP_status(bid) = mode;         \
-}
+       } while (0)
 
 #define BBP_status_on(bid, flags, nme)                                 \
                BBP_status_set(bid, BBP_status(bid) | flags, nme);
@@ -306,18 +307,20 @@ int BBPout = 0;                   /* bats saved statisti
 #define BBP_status_off(bid, flags, nme)                                        
\
                BBP_status_set(bid, BBP_status(bid) & ~(flags), nme);
 
-#define BBP_unload_inc(bid, nme) {                     \
+#define BBP_unload_inc(bid, nme)                       \
+       do {                                            \
                gdk_set_lock(GDKunloadLock, nme);       \
                BBPunloadCnt++;                         \
                gdk_unset_lock(GDKunloadLock, nme);     \
-       }
-
-#define BBP_unload_dec(bid, nme) {                                     \
+       } while (0)
+
+#define BBP_unload_dec(bid, nme)                                       \
+       do {                                                            \
                gdk_set_lock(GDKunloadLock, nme);                       \
                if (--BBPunloadCnt == 0) gdk_signal_cond(GDKunloadCond, nme); \
                assert(BBPunloadCnt >= 0);                              \
                gdk_unset_lock(GDKunloadLock, nme);                     \
-       }
+       } while (0)
 @c
 static MT_Id locked_by = 0;
 
diff --git a/gdk/gdk_relop.mx b/gdk/gdk_relop.mx
--- a/gdk/gdk_relop.mx
+++ b/gdk/gdk_relop.mx
@@ -185,7 +185,8 @@ All Rights Reserved.
                ((((dbl) (lend-lfirst))*((dbl) (rend-rfirst))) / \
                 MAX(1,((lcur-lfirst)*((dbl) (rend-rfirst))+(dbl) 
(rcur-rfirst))))
 
-#define bunfastins_limit(b, h, t, limit, percdone) {                   \
+#define bunfastins_limit(b, h, t, limit, percdone)                     \
+       do {                                                            \
                 register BUN _p = BUNlast(b);                          \
                if (_p == BUN_MAX) /* reached maximum, can't do more */ \
                        goto bunins_done;                               \
@@ -200,7 +201,7 @@ All Rights Reserved.
                 hfastins_nocheck(b, _p, h, Hsize(b));                  \
                 tfastins_nocheck(b, _p, t, Tsize(b));                  \
                 (b)->batCount++;                                       \
-        }
+        } while (0)
 @= mergejoin
        if (((!BATtvoid(l)) || l->tseqbase != oid_nil) &&
            ((!BAThvoid(r)) || r->hseqbase != oid_nil || nil_on_miss)) {
diff --git a/gdk/gdk_search.mx b/gdk/gdk_search.mx
--- a/gdk/gdk_search.mx
+++ b/gdk/gdk_search.mx
@@ -110,44 +110,56 @@ gdk_export BUN HASHlist(Hash *h, BUN i);
 
 
 @= hashfnd
-#define HASHfnd_@1(x,y,z)      {                                       \
-       BUN _i;                                                         \
-       (x) = BUN_NONE;                                                 \
-       if ((y).b->H->hash || BAThash((y).b, 0) || GDKfatal("HASHfnd_@1: hash 
build failed on %s.\n", BATgetId((y).b))) \
-               HASHloop_@1((y), (y).b->H->hash, _i, (z)) {             \
-                       (x) = _i;                                       \
-                       break;                                          \
-               }                                                       \
-}
+#define HASHfnd_@1(x,y,z)                                              \
+       do {                                                            \
+               BUN _i;                                                 \
+               (x) = BUN_NONE;                                         \
+               if ((y).b->H->hash || BAThash((y).b, 0) ||              \
+                   GDKfatal("HASHfnd_@1: hash build failed on %s.\n",  \
+                            BATgetId((y).b)))                          \
+                       HASHloop_@1((y), (y).b->H->hash, _i, (z)) {     \
+                               (x) = _i;                               \
+                               break;                                  \
+                       }                                               \
+       } while (0)
 @
 @h
-#define HASHfnd_str(x,y,z)     {                                       \
-       BUN _i;                                                         \
-       (x) = BUN_NONE;                                                 \
-       if ((y).b->H->hash || BAThash((y).b, 0) || GDKfatal("HASHfnd_str: hash 
build failed on %s.\n", BATgetId((y).b))) \
-               HASHloop_str((y), (y).b->H->hash, _i, (z)) {            \
-                       (x) = _i;                                       \
-                       break;                                          \
-               }                                                       \
-}
-#define HASHfnd_str_hv(x,y,z)  {                                       \
-       BUN _i;                                                         \
-       (x) = BUN_NONE;                                                 \
-       if ((y).b->H->hash || BAThash((y).b, 0) || GDKfatal("HASHfnd_str_hv: 
hash build failed on %s.\n", BATgetId((y).b))) \
-               HASHloop_str_hv((y), (y).b->H->hash, _i, (z)) {         \
-                       (x) = _i;                                       \
-                       break;                                          \
-               }                                                       \
-}
-#define HASHfnd(x,y,z) {                                               \
-       BUN _i;                                                 \
-       (x) = BUN_NONE;                                                 \
-       if ((y).b->H->hash || BAThash((y).b, 0) || GDKfatal("HASHfnd: hash 
build failed on %s.\n", BATgetId((y).b))) \
-               HASHloop((y), (y).b->H->hash, _i, (z)) {                        
\
-                       (x) = _i;                                       \
-                       break;                                          \
-               }                                                       \
-}
+#define HASHfnd_str(x,y,z)                                             \
+       do {                                                            \
+               BUN _i;                                                 \
+               (x) = BUN_NONE;                                         \
+               if ((y).b->H->hash || BAThash((y).b, 0) ||              \
+                   GDKfatal("HASHfnd_str: hash build failed on %s.\n", \
+                            BATgetId((y).b)))                          \
+                       HASHloop_str((y), (y).b->H->hash, _i, (z)) {    \
+                               (x) = _i;                               \
+                               break;                                  \
+                       }                                               \
+       } while (0)
+#define HASHfnd_str_hv(x,y,z)                                          \
+       do {                                                            \
+               BUN _i;                                                 \
+               (x) = BUN_NONE;                                         \
+               if ((y).b->H->hash || BAThash((y).b, 0) ||              \
+                   GDKfatal("HASHfnd_str_hv: hash build failed on %s.\n", \
+                            BATgetId((y).b)))                          \
+                       HASHloop_str_hv((y), (y).b->H->hash, _i, (z)) { \
+                               (x) = _i;                               \
+                               break;                                  \
+                       }                                               \
+       } while (0)
+#define HASHfnd(x,y,z)                                                 \
+       do {                                                            \
+               BUN _i;                                                 \
+               (x) = BUN_NONE;                                         \
+               if ((y).b->H->hash || BAThash((y).b, 0) ||              \
+                   GDKfatal("HASHfnd: hash build failed on %s.\n",     \
+                            BATgetId((y).b)))                          \
+                       HASHloop((y), (y).b->H->hash, _i, (z)) {        \
+                               (x) = _i;                               \
+                               break;                                  \
+                       }                                               \
+       } while (0)
 @:hashfnd(bte)@
 @:hashfnd(sht)@
 @:hashfnd(int)@
@@ -226,43 +238,45 @@ gdk_export BUN HASHlist(Hash *h, BUN i);
 @:hashins(int)@
 @:hashins(lng)@
 
-#define HASHdel(h, i, v, next) {                                       \
-       if (next && h->link[i+1] == i) {                                \
-               h->link[i+1] = h->link[i];                              \
-       } else {                                                        \
-               BUN _c = HASHprobe(h, v);                               \
-               if (h->hash[_c] == i) {                                 \
-                       h->hash[_c] = h->link[i];                       \
+#define HASHdel(h, i, v, next)                                         \
+       do {                                                            \
+               if (next && h->link[i+1] == i) {                        \
+                       h->link[i+1] = h->link[i];                      \
                } else {                                                \
-                       for(_c = h->hash[_c]; _c != BUN_NONE;           \
-                                       _c = h->link[_c]){              \
-                               if (h->link[_c] == i) {                 \
-                                       h->link[_c] = h->link[i];       \
-                                       break;                          \
+                       BUN _c = HASHprobe(h, v);                       \
+                       if (h->hash[_c] == i) {                         \
+                               h->hash[_c] = h->link[i];               \
+                       } else {                                        \
+                               for(_c = h->hash[_c]; _c != BUN_NONE;   \
+                                               _c = h->link[_c]){      \
+                                       if (h->link[_c] == i) {         \
+                                               h->link[_c] = h->link[i]; \
+                                               break;                  \
+                                       }                               \
                                }                                       \
                        }                                               \
-               }                                                       \
-       } h->link[i] = BUN_NONE;                                        \
-}
+               } h->link[i] = BUN_NONE;                                \
+       } while (0)
 
-#define HASHmove(h, i, j, v, next) {                                   \
-       if (next && h->link[i+1] == i) {                                \
-               h->link[i+1] = j;                                       \
-       } else {                                                        \
-               BUN _c = HASHprobe(h, v);                               \
-               if (h->hash[_c] == i) {                                 \
-                       h->hash[_c] = j;                                \
+#define HASHmove(h, i, j, v, next)                                     \
+       do {                                                            \
+               if (next && h->link[i+1] == i) {                        \
+                       h->link[i+1] = j;                               \
                } else {                                                \
-                       for(_c = h->hash[_c]; _c != BUN_NONE;           \
-                                       _c = h->link[_c]){              \
-                               if (h->link[_c] == i) {                 \
-                                       h->link[_c] = j;                \
-                                       break;                          \
+                       BUN _c = HASHprobe(h, v);                       \
+                       if (h->hash[_c] == i) {                         \
+                               h->hash[_c] = j;                        \
+                       } else {                                        \
+                               for(_c = h->hash[_c]; _c != BUN_NONE;   \
+                                               _c = h->link[_c]){      \
+                                       if (h->link[_c] == i) {         \
+                                               h->link[_c] = j;        \
+                                               break;                  \
+                                       }                               \
                                }                                       \
                        }                                               \
-               }                                                       \
-       } h->link[j] = h->link[i];                                      \
-}
+               } h->link[j] = h->link[i];                              \
+       } while (0)
 @c
 /*
  * @- Hash Table Creation
diff --git a/gdk/gdk_system.h b/gdk/gdk_system.h
--- a/gdk/gdk_system.h
+++ b/gdk/gdk_system.h
@@ -86,11 +86,25 @@ gdk_export char *MT_locktrace_nme[65536]
 gdk_export unsigned long long MT_clock(void);
 
 #define MT_locktrace_hash(_id)  ((int) (((lng) ((size_t) _id))^(((lng) 
((size_t) _id))>>16))&65535)
-#define MT_log_trace(_impl, _object, _action, _caller, _fp, _pat) do { 
unsigned long long _c=0; if (MT_locktrace) _c=(MT_getpid() == 
MT_locktrace)?MT_clock():0; MT_log(_impl, _object, _action, _caller, _fp); if 
(_c) { MT_locktrace_cnt[MT_locktrace_hash(_pat)] += MT_clock() - _c; } } 
while(0)
-#define MT_locktrace_set(s,n) {int _i = MT_locktrace_hash(s); \
-                               if (MT_locktrace_nme[_i] && 
MT_locktrace_nme[_i] != (n)) { \
-                                  printf("MT_locktrace: name collision %s 
hides %s\n", MT_locktrace_nme[_i], (n)); \
-                               } else MT_locktrace_nme[_i] = (n); }
+#define MT_log_trace(_impl, _object, _action, _caller, _fp, _pat)      \
+       do {                                                            \
+               unsigned long long _c=0;                                \
+               if (MT_locktrace)                                       \
+                       _c=(MT_getpid() == MT_locktrace)?MT_clock():0;  \
+               MT_log(_impl, _object, _action, _caller, _fp);          \
+               if (_c) {                                               \
+                       MT_locktrace_cnt[MT_locktrace_hash(_pat)] += MT_clock() 
- _c; \
+               }                                                       \
+       } while(0)
+#define MT_locktrace_set(s,n)\
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to