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()"));
}
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;
}
{
memcached_return_t local_error;
- if (!error)
+ if (error == NULL)
+ {
error = &local_error;
+ }
switch (flag)
{
}
case MEMCACHED_CALLBACK_MAX:
default:
- WATCHPOINT_ASSERT(0);
+ assert_msg(0, "Invalid behavior passed to memcached_behavior_set()");
*error= MEMCACHED_FAILURE;
return NULL;
}
}
default: // A real error occurred and we need to completely bail
- WATCHPOINT_ERRNO(get_socket_errno());
switch (get_socket_errno())
{
#ifdef TARGET_OS_LINUX
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;
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);
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)));
}
}
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)
while (--counter)
{
if ((rc= set_hostinfo(ptr)) != MEMCACHED_TIMEOUT)
+ {
break;
+ }
#ifndef WIN32
struct timespec dream, rem;
// 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);
}
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;
memcached_return_t run_distribution(memcached_st *ptr)
{
if (ptr->flags.use_sort_hosts)
+ {
sort_hosts(ptr);
+ }
switch (ptr->distribution)
{
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;
#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++)
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++)
{
WATCHPOINT_ASSERT(self);
if (not self)
+ {
return;
+ }
memcached_error_free(*self);
}
#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 <ucontext.h>
-
-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 <assert.h>
-
-#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)
#define WATCHPOINT_ASSERT(A) (void)(A)
#define WATCHPOINT_ASSERT_INITIALIZED(A)
#define WATCHPOINT_SET(A)
-
-#endif /* DEBUG */