Commit fc00f140 authored by Rusty Russell's avatar Rusty Russell

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