]> git.ozlabs.org Git - ccan/commitdiff
jmap,likely,tdb2: use CCAN_<MODNAME>_DEBUG instead of DEBUG.
authorRusty Russell <rusty@rustcorp.com.au>
Thu, 24 Feb 2011 05:09:32 +0000 (15:39 +1030)
committerRusty Russell <rusty@rustcorp.com.au>
Thu, 24 Feb 2011 05:09:32 +0000 (15:39 +1030)
Samba (for example) uses a DEBUG() macro, which triggers these heuristics.
Better to make it per-module anyway.

ccan/jmap/jmap.h
ccan/jmap/test/run.c
ccan/likely/likely.c
ccan/likely/likely.h
ccan/likely/test/run-debug.c
ccan/tdb2/free.c

index cfa2e26c61512fa07951f5e3101cc3be843354b7..f1b2f03864aa084e0675dca9c90d13a3b0508a29 100644 (file)
@@ -6,7 +6,7 @@
 #include <string.h>
 #include <ccan/compiler/compiler.h>
 #include <assert.h>
-#ifdef DEBUG
+#ifdef CCAN_JMAP_DEBUG
 #include <stdio.h>
 #endif
 
@@ -39,7 +39,7 @@ struct jmap {
        const char *errstr;
        /* Used if !NDEBUG */
        int num_accesses;
-       /* Used if DEBUG */
+       /* Used if CCAN_JMAP_DEBUG */
        unsigned long *acc_value;
        unsigned long acc_index;
        const char *funcname;
@@ -52,7 +52,7 @@ static inline void jmap_debug_add_access(const struct jmap *map,
                                         unsigned long *val,
                                         const char *funcname)
 {
-#ifdef DEBUG
+#ifdef CCAN_JMAP_DEBUG
        if (!map->acc_value) {
                ((struct jmap *)map)->acc_value = val;
                ((struct jmap *)map)->acc_index = index;
@@ -66,7 +66,7 @@ static inline void jmap_debug_add_access(const struct jmap *map,
 static inline void jmap_debug_del_access(struct jmap *map, unsigned long **val)
 {
        assert(--map->num_accesses >= 0);
-#ifdef DEBUG
+#ifdef CCAN_JMAP_DEBUG
        if (map->acc_value == *val)
                map->acc_value = NULL;
 #endif
@@ -76,7 +76,7 @@ static inline void jmap_debug_del_access(struct jmap *map, unsigned long **val)
 
 static inline void jmap_debug_access(struct jmap *map)
 {
-#ifdef DEBUG
+#ifdef CCAN_JMAP_DEBUG
        if (map->num_accesses && map->acc_value)
                fprintf(stderr,
                        "jmap: still got index %lu, val %lu (%p) from %s\n",
index 5f5c932f0ba8191baa0de6b5f0adcfdd68e696ef..e2c72ae3561ac603a108f89bb2ec5194a28359c5 100644 (file)
@@ -1,5 +1,5 @@
 #include <ccan/tap/tap.h>
-#define DEBUG
+#define CCAN_JMAP_DEBUG
 #include <ccan/jmap/jmap.c>
 
 int main(int argc, char *argv[])
index 1bdc1b1a6c16efb571aaaf5811b07346ff0147cc..8893d0b6d244b5af79831a66900375fcce48b324 100644 (file)
@@ -1,4 +1,4 @@
-#ifdef DEBUG
+#ifdef CCAN_LIKELY_DEBUG
 #include <ccan/likely/likely.h>
 #include <ccan/hash/hash.h>
 #include <ccan/htable/htable.h>
@@ -138,4 +138,4 @@ const char *likely_stats(unsigned int min_hits, unsigned int percent)
 
        return ret;
 }
-#endif /*DEBUG*/
+#endif /*CCAN_LIKELY_DEBUG*/
index 137cb86131884d28710fa4f5e668d5bfe0f99f74..0fad89c42bb80088f78116a8bfb054123c8ef355 100644 (file)
@@ -4,7 +4,7 @@
 #include <ccan/str/str.h>
 #include <stdbool.h>
 
-#ifndef DEBUG
+#ifndef CCAN_LIKELY_DEBUG
 #if HAVE_BUILTIN_EXPECT
 /**
  * likely - indicate that a condition is likely to be true.
@@ -55,7 +55,7 @@
 #define likely(cond) (!!(cond))
 #define unlikely(cond) (!!(cond))
 #endif
-#else /* DEBUG versions */
+#else /* CCAN_LIKELY_DEBUG versions */
 #define likely(cond) \
        (_likely_trace(!!(cond), 1, stringify(cond), __FILE__, __LINE__))
 #define unlikely(cond) \
@@ -66,15 +66,15 @@ long _likely_trace(bool cond, bool expect,
                   const char *file, unsigned int line);
 #endif
 
-#ifdef DEBUG
+#ifdef CCAN_LIKELY_DEBUG
 /**
  * likely_stats - return description of abused likely()/unlikely()
  * @min_hits: minimum number of hits
  * @percent: maximum percentage correct
  *
- * When DEBUG is defined, likely() and unlikely() trace their results: this
- * causes a significant slowdown, but allows analysis of whether the stats
- * are correct.
+ * When CCAN_LIKELY_DEBUG is defined, likely() and unlikely() trace their
+ * results: this causes a significant slowdown, but allows analysis of 
+ * whether the branches are labelled correctly.
  *
  * This function returns a malloc'ed description of the least-correct
  * usage of likely() or unlikely().  It ignores places which have been
@@ -90,7 +90,7 @@ long _likely_trace(bool cond, bool expect,
  *     // Print every place hit more than twice which was wrong > 5%.
  *     static void report_stats(void)
  *     {
- *     #ifdef DEBUG
+ *     #ifdef CCAN_LIKELY_DEBUG
  *             const char *bad;
  *
  *             while ((bad = likely_stats(2, 95)) != NULL) {
@@ -101,5 +101,5 @@ long _likely_trace(bool cond, bool expect,
  *     }
  */
 const char *likely_stats(unsigned int min_hits, unsigned int percent);
-#endif /* DEBUG */
+#endif /* CCAN_LIKELY_DEBUG */
 #endif /* CCAN_LIKELY_H */
index 198ac5b79e6424099a37f3fc87604f5273f93507..df78619271fc705eb9f0ded4c2868b84e48419dd 100644 (file)
@@ -1,4 +1,4 @@
-#define DEBUG 1
+#define CCAN_LIKELY_DEBUG 1
 #include <ccan/likely/likely.c>
 #include <ccan/likely/likely.h>
 #include <ccan/tap/tap.h>
index 5d1bd3c6d1360d7c2a1b3498a58e3d7443ec0d18..ba14dfcd70747b8ad6789ba08487d30b91cbc6fc 100644 (file)
@@ -116,7 +116,7 @@ static int remove_from_list(struct tdb_context *tdb,
                off = frec_prev(r) + offsetof(struct tdb_free_record, next);
        }
 
-#ifdef DEBUG
+#ifdef CCAN_TDB2_DEBUG
        if (tdb_read_off(tdb, off) != r_off) {
                tdb_logerr(tdb, TDB_ERR_CORRUPT, TDB_DEBUG_FATAL,
                         "remove_from_list: %llu bad prev in list %llu",
@@ -134,7 +134,7 @@ static int remove_from_list(struct tdb_context *tdb,
                off = r->next + offsetof(struct tdb_free_record,magic_and_prev);
                /* r->next->prev = r->prev */
 
-#ifdef DEBUG
+#ifdef CCAN_TDB2_DEBUG
                if (tdb_read_off(tdb, off) & TDB_OFF_MASK != r_off) {
                        tdb_logerr(tdb, TDB_ERR_CORRUPT, TDB_DEBUG_FATAL,
                                   "remove_from_list: %llu bad list %llu",
@@ -171,7 +171,7 @@ static int enqueue_in_free(struct tdb_context *tdb,
                return -1;
 
        if (new.next) {
-#ifdef DEBUG
+#ifdef CCAN_TDB2_DEBUG
                if (tdb_read_off(tdb,
                                 new.next + offsetof(struct tdb_free_record,
                                                     magic_and_prev))