Browse Source

jmap,likely,tdb2: use CCAN_<MODNAME>_DEBUG instead of DEBUG.

Samba (for example) uses a DEBUG() macro, which triggers these heuristics.
Better to make it per-module anyway.
Rusty Russell 15 years ago
parent
commit
fc00f14087
6 changed files with 20 additions and 20 deletions
  1. 5 5
      ccan/jmap/jmap.h
  2. 1 1
      ccan/jmap/test/run.c
  3. 2 2
      ccan/likely/likely.c
  4. 8 8
      ccan/likely/likely.h
  5. 1 1
      ccan/likely/test/run-debug.c
  6. 3 3
      ccan/tdb2/free.c

+ 5 - 5
ccan/jmap/jmap.h

@@ -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",

+ 1 - 1
ccan/jmap/test/run.c

@@ -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[])

+ 2 - 2
ccan/likely/likely.c

@@ -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*/

+ 8 - 8
ccan/likely/likely.h

@@ -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 */

+ 1 - 1
ccan/likely/test/run-debug.c

@@ -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>

+ 3 - 3
ccan/tdb2/free.c

@@ -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))