From c5c5f2799a24eac8df5e11f447b48e031299579a Mon Sep 17 00:00:00 2001 From: Brian Aker Date: Thu, 21 Jul 2011 19:58:25 -0700 Subject: [PATCH] Remove old watchpoint system. --- libmemcached/behavior.cc | 4 +-- libmemcached/callback.cc | 6 ++-- libmemcached/connect.cc | 17 ++++------- libmemcached/get.cc | 4 +-- libmemcached/hosts.cc | 12 ++++---- libmemcached/server.cc | 2 ++ libmemcached/watchpoint.h | 59 --------------------------------------- 7 files changed, 22 insertions(+), 82 deletions(-) diff --git a/libmemcached/behavior.cc b/libmemcached/behavior.cc index 0c182ec2..a6988a22 100644 --- a/libmemcached/behavior.cc +++ b/libmemcached/behavior.cc @@ -239,7 +239,7 @@ memcached_return_t memcached_behavior_set(memcached_st *ptr, case MEMCACHED_BEHAVIOR_MAX: default: /* Shouldn't get here */ - WATCHPOINT_ASSERT(0); + assert_msg(0, "Invalid behavior passed to memcached_behavior_set()"); return memcached_set_error(*ptr, MEMCACHED_INVALID_ARGUMENTS, MEMCACHED_AT, memcached_literal_param("Invalid behavior passed to memcached_behavior_set()")); } @@ -441,7 +441,7 @@ uint64_t memcached_behavior_get(memcached_st *ptr, case MEMCACHED_BEHAVIOR_MAX: default: - WATCHPOINT_ASSERT(0); /* Programming mistake if it gets this far */ + assert_msg(0, "Invalid behavior passed to memcached_behavior_set()"); return 0; } diff --git a/libmemcached/callback.cc b/libmemcached/callback.cc index 47397863..bb13a87b 100644 --- a/libmemcached/callback.cc +++ b/libmemcached/callback.cc @@ -90,8 +90,10 @@ void *memcached_callback_get(memcached_st *ptr, { memcached_return_t local_error; - if (!error) + if (error == NULL) + { error = &local_error; + } switch (flag) { @@ -152,7 +154,7 @@ void *memcached_callback_get(memcached_st *ptr, } case MEMCACHED_CALLBACK_MAX: default: - WATCHPOINT_ASSERT(0); + assert_msg(0, "Invalid behavior passed to memcached_behavior_set()"); *error= MEMCACHED_FAILURE; return NULL; } diff --git a/libmemcached/connect.cc b/libmemcached/connect.cc index 8efbb119..ecff6386 100644 --- a/libmemcached/connect.cc +++ b/libmemcached/connect.cc @@ -78,7 +78,6 @@ static memcached_return_t connect_poll(memcached_server_st *ptr) } default: // A real error occurred and we need to completely bail - WATCHPOINT_ERRNO(get_socket_errno()); switch (get_socket_errno()) { #ifdef TARGET_OS_LINUX @@ -107,7 +106,7 @@ static memcached_return_t connect_poll(memcached_server_st *ptr) memcached_set_errno(*ptr, get_socket_errno(), MEMCACHED_AT); } - WATCHPOINT_ASSERT(ptr->fd != INVALID_SOCKET); + assert_msg(ptr->fd != INVALID_SOCKET, "poll() was passed an invalid file descriptor"); (void)closesocket(ptr->fd); ptr->fd= INVALID_SOCKET; ptr->state= MEMCACHED_SERVER_STATE_NEW; @@ -123,7 +122,6 @@ static memcached_return_t connect_poll(memcached_server_st *ptr) static memcached_return_t set_hostinfo(memcached_server_st *server) { - WATCHPOINT_ASSERT(not server->address_info); // We cover the case where a programming mistake has been made. if (server->address_info) { freeaddrinfo(server->address_info); @@ -175,8 +173,6 @@ static memcached_return_t set_hostinfo(memcached_server_st *server) default: { - WATCHPOINT_STRING(server->hostname); - WATCHPOINT_STRING(gai_strerror(errcode)); return memcached_set_error(*server, MEMCACHED_HOST_LOOKUP_FAILURE, MEMCACHED_AT, memcached_string_make_from_cstr(gai_strerror(errcode))); } } @@ -225,10 +221,12 @@ static inline void set_socket_nonblocking(memcached_server_st *ptr) static void set_socket_options(memcached_server_st *ptr) { - WATCHPOINT_ASSERT(ptr->fd != -1); + assert_msg(ptr->fd != -1, "invalid socket was passed to set_socket_options()"); if (ptr->type == MEMCACHED_CONNECTION_UDP) + { return; + } #ifdef HAVE_SNDTIMEO if (ptr->root->snd_timeout) @@ -407,7 +405,9 @@ static memcached_return_t network_connect(memcached_server_st *ptr) while (--counter) { if ((rc= set_hostinfo(ptr)) != MEMCACHED_TIMEOUT) + { break; + } #ifndef WIN32 struct timespec dream, rem; @@ -529,11 +529,6 @@ void set_last_disconnected_host(memcached_server_write_instance_st self) // const_cast memcached_st *root= (memcached_st *)self->root; -#if 0 - WATCHPOINT_STRING(self->hostname); - WATCHPOINT_NUMBER(self->port); - WATCHPOINT_ERRNO(self->cached_errno); -#endif memcached_server_free(root->last_disconnected_server); root->last_disconnected_server= memcached_server_clone(NULL, self); } diff --git a/libmemcached/get.cc b/libmemcached/get.cc index 794d3d15..8c98d4ca 100644 --- a/libmemcached/get.cc +++ b/libmemcached/get.cc @@ -168,8 +168,8 @@ char *memcached_get_by_key(memcached_st *ptr, char *dummy_value= memcached_fetch(ptr, NULL, NULL, &dummy_length, &dummy_flags, &dummy_error); - WATCHPOINT_ASSERT(dummy_length == 0); - WATCHPOINT_ASSERT(dummy_value == 0); + assert_msg(dummy_value == 0, "memcached_fetch() returned additional values beyond the single get it expected"); + assert_msg(dummy_length == 0, "memcached_fetch() returned additional values beyond the single get it expected"); assert_msg(ptr->query_id == query_id +1, "Programmer error, the query_id was not incremented."); return value; diff --git a/libmemcached/hosts.cc b/libmemcached/hosts.cc index 89896e85..1bcaaa7a 100644 --- a/libmemcached/hosts.cc +++ b/libmemcached/hosts.cc @@ -80,7 +80,9 @@ static void sort_hosts(memcached_st *ptr) memcached_return_t run_distribution(memcached_st *ptr) { if (ptr->flags.use_sort_hosts) + { sort_hosts(ptr); + } switch (ptr->distribution) { @@ -89,15 +91,18 @@ memcached_return_t run_distribution(memcached_st *ptr) case MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA_SPY: case MEMCACHED_DISTRIBUTION_CONSISTENT_WEIGHTED: return update_continuum(ptr); + case MEMCACHED_DISTRIBUTION_VIRTUAL_BUCKET: case MEMCACHED_DISTRIBUTION_MODULA: break; + case MEMCACHED_DISTRIBUTION_RANDOM: srandom((uint32_t) time(NULL)); break; + case MEMCACHED_DISTRIBUTION_CONSISTENT_MAX: default: - WATCHPOINT_ASSERT(0); /* We have added a distribution without extending the logic */ + assert_msg(0, "Invalid distribution type passed to run_distribution()"); } return MEMCACHED_SUCCESS; @@ -252,9 +257,6 @@ static memcached_return_t update_continuum(memcached_st *ptr) #ifdef DEBUG printf("update_continuum: key is %s\n", sort_host); #endif - - WATCHPOINT_ASSERT(sort_host_length); - if (is_ketama_weighted) { for (uint32_t x= 0; x < pointer_per_hash; x++) @@ -303,8 +305,6 @@ static memcached_return_t update_continuum(memcached_st *ptr) memcached_literal_param("snprintf(MEMCACHED_DEFAULT_COMMAND_SIZE)")); } - WATCHPOINT_ASSERT(sort_host_length); - if (is_ketama_weighted) { for (uint32_t x = 0; x < pointer_per_hash; x++) diff --git a/libmemcached/server.cc b/libmemcached/server.cc index eda7f847..98b16eef 100644 --- a/libmemcached/server.cc +++ b/libmemcached/server.cc @@ -281,7 +281,9 @@ void memcached_server_error_reset(memcached_server_st *self) { WATCHPOINT_ASSERT(self); if (not self) + { return; + } memcached_error_free(*self); } diff --git a/libmemcached/watchpoint.h b/libmemcached/watchpoint.h index 58875e09..822101e9 100644 --- a/libmemcached/watchpoint.h +++ b/libmemcached/watchpoint.h @@ -37,63 +37,6 @@ #pragma once -/* Some personal debugging functions */ -#if defined(DEBUG) - -#ifdef TARGET_OS_LINUX -static inline void libmemcached_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); -} - -#elif defined(__sun) -#include - -static inline void libmemcached_stack_dump(void) -{ - fflush(stderr); - printstack(fileno(stderr)); -} - -#else - -static inline void libmemcached_stack_dump(void) -{ } - -#endif // libmemcached_stack_dump() - -#include - -#define WATCHPOINT do { fprintf(stderr, "\nWATCHPOINT %s:%d (%s)\n", __FILE__, __LINE__,__func__);fflush(stdout); } while (0) -#define WATCHPOINT_ERROR(A) do {fprintf(stderr, "\nWATCHPOINT %s:%d %s\n", __FILE__, __LINE__, memcached_strerror(NULL, A));fflush(stdout); } while (0) -#define WATCHPOINT_IFERROR(A) do { if(A != MEMCACHED_SUCCESS)fprintf(stderr, "\nWATCHPOINT %s:%d %s\n", __FILE__, __LINE__, memcached_strerror(NULL, A));fflush(stdout); } while (0) -#define WATCHPOINT_STRING(A) do { fprintf(stderr, "\nWATCHPOINT %s:%d (%s) %s\n", __FILE__, __LINE__,__func__,A);fflush(stdout); } while (0) -#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) %lu\n", __FILE__, __LINE__,__func__,(unsigned long)(A));fflush(stdout); } while (0) -#define WATCHPOINT_LABELED_NUMBER(A,B) do { fprintf(stderr, "\nWATCHPOINT %s:%d (%s) %s:%lu\n", __FILE__, __LINE__,__func__,(A),(unsigned long)(B));fflush(stdout); } while (0) -#define WATCHPOINT_IF_LABELED_NUMBER(A,B,C) do { if(A) {fprintf(stderr, "\nWATCHPOINT %s:%d (%s) %s:%lu\n", __FILE__, __LINE__,__func__,(B),(unsigned long)(C));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); libmemcached_stack_dump(); } assert((A)); } while (0) -#define WATCHPOINT_ASSERT(A) do { if (! (A)) {libmemcached_stack_dump();} assert((A)); } while (0) -#define WATCHPOINT_ASSERT_INITIALIZED(A) do { if (! (A)) { libmemcached_stack_dump(); } assert(memcached_is_initialized((A))); } while (0); -#define WATCHPOINT_SET(A) do { A; } while(0); - -#else - #define WATCHPOINT #define WATCHPOINT_ERROR(A) #define WATCHPOINT_IFERROR(__memcached_return_t) (void)(__memcached_return_t) @@ -106,5 +49,3 @@ static inline void libmemcached_stack_dump(void) #define WATCHPOINT_ASSERT(A) (void)(A) #define WATCHPOINT_ASSERT_INITIALIZED(A) #define WATCHPOINT_SET(A) - -#endif /* DEBUG */ -- 2.30.2