From: Brian Aker Date: Tue, 9 Feb 2010 20:44:21 +0000 (-0800) Subject: Fixing bogus assert in debug build. X-Git-Tag: 0.40~53 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=93eeb24c446d0d0255de2bebb8da6fc0546039fc;p=awesomized%2Flibmemcached Fixing bogus assert in debug build. --- diff --git a/libmemcached/hash.c b/libmemcached/hash.c index dbdcc7de..1c11c50d 100644 --- a/libmemcached/hash.c +++ b/libmemcached/hash.c @@ -28,7 +28,6 @@ uint32_t generate_hash(memcached_st *ptr, const char *key, size_t key_length) return 0; hash= hashkit_digest(&ptr->hashkit, key, key_length); - WATCHPOINT_ASSERT(hash); return hash; } @@ -103,8 +102,6 @@ uint32_t memcached_generate_hash(memcached_st *ptr, const char *key, size_t key_ hash= generate_hash(ptr, key, key_length); } - WATCHPOINT_ASSERT(hash); - if (memcached_behavior_get(ptr, MEMCACHED_BEHAVIOR_AUTO_EJECT_HOSTS) && ptr->next_distribution_rebuild) { struct timeval now; diff --git a/libmemcached/result.c b/libmemcached/result.c index f673413b..037293e7 100644 --- a/libmemcached/result.c +++ b/libmemcached/result.c @@ -53,6 +53,7 @@ memcached_result_st *memcached_result_create(const memcached_st *memc, _result_init(ptr, memc); ptr->root= memc; + WATCHPOINT_SET(ptr->value.options.is_initialized= false); memcached_string_create(memc, &ptr->value, 0); WATCHPOINT_ASSERT_INITIALIZED(&ptr->value); WATCHPOINT_ASSERT(ptr->value.string == NULL); diff --git a/libmemcached/watchpoint.h b/libmemcached/watchpoint.h index 38410194..6935a529 100644 --- a/libmemcached/watchpoint.h +++ b/libmemcached/watchpoint.h @@ -15,6 +15,33 @@ /* Some personal debugging functions */ #if defined(DEBUG) +#if TARGET_OS_LINUX +static inline void __stack_dump(void) +{ + void *array[10]; + int size; + char **strings; + + size= backtrace(array, 10); + strings= backtrace_symbols(array, size); + + fprintf(stderr, "Found %d stack frames.\n", size); + + for (int x= 0; x < size; x++) + fprintf(stderr, "%s\n", strings[x]); + + free (strings); + + fflush(stderr); +} + +#else + +static inline void __stack_dump(void) +{ } + +#endif // __stack_dump() + #include #define WATCHPOINT do { fprintf(stderr, "\nWATCHPOINT %s:%d (%s)\n", __FILE__, __LINE__,__func__);fflush(stdout); } while (0) @@ -24,9 +51,10 @@ #define WATCHPOINT_STRING_LENGTH(A,B) do { fprintf(stderr, "\nWATCHPOINT %s:%d (%s) %.*s\n", __FILE__, __LINE__,__func__,(int)B,A);fflush(stdout); } while (0) #define WATCHPOINT_NUMBER(A) do { fprintf(stderr, "\nWATCHPOINT %s:%d (%s) %zu\n", __FILE__, __LINE__,__func__,(size_t)(A));fflush(stdout); } while (0) #define WATCHPOINT_ERRNO(A) do { fprintf(stderr, "\nWATCHPOINT %s:%d (%s) %s\n", __FILE__, __LINE__,__func__, strerror(A));fflush(stdout); } while (0) -#define WATCHPOINT_ASSERT_PRINT(A,B,C) do { if(!(A)){fprintf(stderr, "\nWATCHPOINT ASSERT %s:%d (%s) ", __FILE__, __LINE__,__func__);fprintf(stderr, (B),(C));fprintf(stderr,"\n");fflush(stdout);}assert((A)); } while (0) -#define WATCHPOINT_ASSERT(A) assert((A)) -#define WATCHPOINT_ASSERT_INITIALIZED(A) assert(memcached_is_initialized((A))) +#define WATCHPOINT_ASSERT_PRINT(A,B,C) do { if(!(A)){fprintf(stderr, "\nWATCHPOINT ASSERT %s:%d (%s) ", __FILE__, __LINE__,__func__);fprintf(stderr, (B),(C));fprintf(stderr,"\n");fflush(stdout); __stack_dump(); } assert((A)); } while (0) +#define WATCHPOINT_ASSERT(A) do { if (! (A)) {__stack_dump();} assert((A)); } while (0) +#define WATCHPOINT_ASSERT_INITIALIZED(A) do { if (! (A)) { __stack_dump(); } assert(memcached_is_initialized((A))); } while (0); +#define WATCHPOINT_SET(A) do { A; } while(0); #else @@ -39,6 +67,7 @@ #define WATCHPOINT_ASSERT_PRINT(A,B,C) #define WATCHPOINT_ASSERT(A) #define WATCHPOINT_ASSERT_INITIALIZED(A) +#define WATCHPOINT_SET(A) #endif /* DEBUG */