From 73ab14c882ca0f2b7112ab4cd9dfb16d5f41916e Mon Sep 17 00:00:00 2001 From: Monty Taylor Date: Sun, 14 Jun 2009 14:24:48 -0700 Subject: [PATCH] Aligned configure.ac with libdizzle and gearman. --- clients/memslap.c | 14 +- clients/memstat.c | 21 +- clients/utilities.c | 1 + config/{bootstrap => autorun.sh} | 0 configure.ac | 308 ++++++++++++++++++++++------ libmemcached/crc.c | 3 +- libmemcached/jenkins_hash.c | 3 + libmemcached/memcached_analyze.c | 17 +- libmemcached/memcached_auto.c | 10 +- libmemcached/memcached_behavior.c | 7 + libmemcached/memcached_hash.c | 5 + libmemcached/memcached_hosts.c | 38 ++-- libmemcached/memcached_internal.h | 3 +- libmemcached/memcached_io.c | 24 +-- libmemcached/memcached_stats.c | 123 +++++------ libmemcached/memcached_storage.c | 6 + libmemcached/memcached_strerror.c | 2 + libmemcached/memcached_watchpoint.h | 4 +- libmemcached/murmur_hash.c | 1 + m4/64bit.m4 | 58 +++--- m4/acx_pthread.m4 | 276 +++++++++++++++++++++++++ m4/byteorder.m4 | 1 - m4/debug.m4 | 20 -- m4/enable_utillib.m4 | 16 ++ m4/extensions.m4 | 2 +- m4/util.m4 | 20 -- tests/function.c | 200 +++++++++--------- tests/test.c | 1 - 28 files changed, 832 insertions(+), 352 deletions(-) rename config/{bootstrap => autorun.sh} (100%) create mode 100644 m4/acx_pthread.m4 delete mode 100644 m4/debug.m4 create mode 100644 m4/enable_utillib.m4 delete mode 100644 m4/util.m4 diff --git a/clients/memslap.c b/clients/memslap.c index 0baff1df..5e747b23 100644 --- a/clients/memslap.c +++ b/clients/memslap.c @@ -147,7 +147,6 @@ void scheduler(memcached_server_st *servers, conclusions_st *conclusion) if (opt_udp_io) { memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_USE_UDP, opt_udp_io); - unsigned int x= 0; for(x= 0; x < servers[0].count; x++ ) servers[x].type= MEMCACHED_CONNECTION_UDP; } @@ -378,6 +377,9 @@ void *run_task(void *p) case GET_TEST: execute_get(memc, context->initial_pairs, context->initial_number); break; + default: + WATCHPOINT_ASSERT(context->test); + break; } memcached_free(memc); @@ -403,17 +405,17 @@ void flush_all(memcached_st *memc) pairs_st *load_create_data(memcached_st *memc, unsigned int number_of, unsigned int *actual_loaded) { - memcached_st *clone; + memcached_st *memc_clone; pairs_st *pairs; - clone= memcached_clone(NULL, memc); + memc_clone= memcached_clone(NULL, memc); /* We always used non-blocking IO for load since it is faster */ - memcached_behavior_set(clone, MEMCACHED_BEHAVIOR_NO_BLOCK, 0); + memcached_behavior_set(memc_clone, MEMCACHED_BEHAVIOR_NO_BLOCK, 0); pairs= pairs_generate(number_of, 400); - *actual_loaded= execute_set(clone, pairs, number_of); + *actual_loaded= execute_set(memc_clone, pairs, number_of); - memcached_free(clone); + memcached_free(memc_clone); return pairs; } diff --git a/clients/memstat.c b/clients/memstat.c index f3ac9fe1..817b9f6d 100644 --- a/clients/memstat.c +++ b/clients/memstat.c @@ -49,7 +49,7 @@ int main(int argc, char *argv[]) { memcached_return rc; memcached_st *memc; - memcached_stat_st *stat; + memcached_stat_st *memc_stat; memcached_server_st *servers; memcached_server_st *server_list; @@ -75,7 +75,7 @@ int main(int argc, char *argv[]) memcached_server_push(memc, servers); memcached_server_list_free(servers); - stat= memcached_stat(memc, NULL, &rc); + memc_stat= memcached_stat(memc, NULL, &rc); if (rc != MEMCACHED_SUCCESS && rc != MEMCACHED_SOME_ERRORS) { @@ -87,11 +87,11 @@ int main(int argc, char *argv[]) server_list= memcached_server_list(memc); if (opt_analyze) - run_analyzer(memc, stat, server_list); + run_analyzer(memc, memc_stat, server_list); else - print_server_listing(memc, stat, server_list); + print_server_listing(memc, memc_stat, server_list); - free(stat); + free(memc_stat); free(opt_servers); memcached_free(memc); @@ -99,7 +99,7 @@ int main(int argc, char *argv[]) return 0; } -static void run_analyzer(memcached_st *memc, memcached_stat_st *stat, +static void run_analyzer(memcached_st *memc, memcached_stat_st *memc_stat, memcached_server_st *server_list) { memcached_return rc; @@ -107,7 +107,7 @@ static void run_analyzer(memcached_st *memc, memcached_stat_st *stat, if (analyze_mode == NULL) { memcached_analysis_st *report; - report= memcached_analyze(memc, stat, &rc); + report= memcached_analyze(memc, memc_stat, &rc); if (rc != MEMCACHED_SUCCESS || report == NULL) { printf("Failure to analyze servers (%s)\n", @@ -215,7 +215,7 @@ static void run_analyzer(memcached_st *memc, memcached_stat_st *stat, } } -static void print_server_listing(memcached_st *memc, memcached_stat_st *stat, +static void print_server_listing(memcached_st *memc, memcached_stat_st *memc_stat, memcached_server_st *server_list) { unsigned int x; @@ -227,14 +227,13 @@ static void print_server_listing(memcached_st *memc, memcached_stat_st *stat, char **list; char **ptr; - list= memcached_stat_get_keys(memc, &stat[x], &rc); + list= memcached_stat_get_keys(memc, &memc_stat[x], &rc); printf("Server: %s (%u)\n", memcached_server_name(memc, server_list[x]), memcached_server_port(memc, server_list[x])); for (ptr= list; *ptr; ptr++) { - memcached_return rc; - char *value= memcached_stat_get_value(memc, &stat[x], *ptr, &rc); + char *value= memcached_stat_get_value(memc, &memc_stat[x], *ptr, &rc); printf("\t %s: %s\n", *ptr, value); free(value); diff --git a/clients/utilities.c b/clients/utilities.c index b9795246..466c0485 100644 --- a/clients/utilities.c +++ b/clients/utilities.c @@ -47,6 +47,7 @@ static char *lookup_help(memcached_options option) case OPT_BINARY: return("Switch to binary protocol."); case OPT_ANALYZE: return("Analyze the provided servers."); case OPT_UDP: return("Use UDP protocol when communicating with server."); + default: WATCHPOINT_ASSERT(0); }; WATCHPOINT_ASSERT(0); diff --git a/config/bootstrap b/config/autorun.sh similarity index 100% rename from config/bootstrap rename to config/autorun.sh diff --git a/configure.ac b/configure.ac index af6d399e..75599a08 100644 --- a/configure.ac +++ b/configure.ac @@ -1,19 +1,16 @@ +# Gearman server and library +# Copyright (C) 2008 Brian Aker +# All rights reserved. +# +# Use and distribution licensed under the BSD license. See +# the COPYING file in this directory for full text. + +AC_PREREQ(2.59) AC_INIT([libmemcached],[0.30],[http://tangent.org/552/libmemcached.html]) -AC_CONFIG_SRCDIR([clients/memcat.c]) +AC_CONFIG_SRCDIR([libmemcached/memcached.c]) AC_CONFIG_AUX_DIR(config) AM_CONFIG_HEADER(libmemcached/libmemcached_config.h) -# Setting CFLAGS here prevents AC_CANONICAL_TARGET from injecting them -SAVE_CFLAGS=${CFLAGS} -SAVE_CXXFLAGS=${CXXFLAGS} -CFLAGS= -CXXFLAGS= - -AC_CANONICAL_TARGET - -CFLAGS=${SAVE_CFLAGS} -CXXFLAGS=${SAVE_CXXFLAGS} - #shared library versioning MEMCACHED_LIBRARY_VERSION=2:0:0 # | | | @@ -30,17 +27,66 @@ AC_SUBST(MEMCACHED_LIBRARY_VERSION) MEMCACHEDUTIL_LIBRARY_VERSION=0:0:0 AC_SUBST(MEMCACHEDUTIL_LIBRARY_VERSION) -AM_INIT_AUTOMAKE(nostdinc no-define -Wall -Werror) -AC_USE_SYSTEM_EXTENSIONS +# Setting CFLAGS here prevents AC_CANONICAL_TARGET from injecting them +SAVE_CFLAGS=${CFLAGS} +SAVE_CXXFLAGS=${CXXFLAGS} +CFLAGS= +CXXFLAGS= + +AC_CANONICAL_TARGET + +CFLAGS=${SAVE_CFLAGS} +CXXFLAGS=${SAVE_CXXFLAGS} + +AM_INIT_AUTOMAKE([-Wall -Werror nostdinc subdir-objects]) + +if test "x${enable_dependency_tracking}" = "x" +then + enable_dependency_tracking=yes +fi + +if test -d "${srcdir}/.bzr" +then + building_from_bzr=yes +else + building_from_bzr=no +fi AC_PROG_CC AC_PROG_CC_C99 +AM_PROG_CC_STDC AC_PROG_CXX -AC_PROG_LIBTOOL -AM_SANITY_CHECK + +ACX_USE_SYSTEM_EXTENSIONS + +AC_PROG_CPP +AM_PROG_CC_C_O + +AC_C_BIGENDIAN +AC_C_CONST +AC_HEADER_TIME +AC_TYPE_SIZE_T +AC_TYPE_SSIZE_T +AC_FUNC_MALLOC +AC_FUNC_REALLOC AC_CHECK_DECL([__SUNPRO_C], [SUNCC="yes"], [SUNCC="no"]) +# We use libtool +AC_PROG_LIBTOOL + +AC_MSG_CHECKING("C Compiler version") +if test "$GCC" = "yes" +then + CC_VERSION=`$CC --version | sed 1q` +elif test "$SUNCC" = "yes" +then + CC_VERSION=`$CC -V 2>&1 | sed 1q` +else + CC_VERSION="" +fi +AC_MSG_RESULT("$CC_VERSION") +AC_SUBST(CC_VERSION) # libmemcached versioning when linked with GNU ld. if test "$lt_cv_prog_gnu_ld" = "yes" @@ -51,9 +97,33 @@ fi AC_SUBST(LD_VERSION_SCRIPT) AC_SUBST(LD_UTIL_VERSION_SCRIPT) -AC_C_CONST -AC_HEADER_TIME -AC_TYPE_SIZE_T +# Build optimized or debug version ? +# First check for gcc and g++ +if test "$GCC" = "yes" +then + CFLAGS="-ggdb3 -std=gnu99 ${CFLAGS}" + DEBUG_CFLAGS="-O0" + OPTIMIZE_CFLAGS="-O3" +fi +if test "x$SUNCC" = "xyes" +then + CFLAGS="-g -mt -xc99=all $CFLAGS" + CXXFLAGS="-g -mt -xlang=c99 $CXXFLAGS" + OPTIMIZE_CFLAGS="-xO4 -xlibmil -xdepend -Xa -xstrconst" +fi + +SOLARIS_64BIT + +#-------------------------------------------------------------------- +# Check for libpthread +#-------------------------------------------------------------------- + +ACX_PTHREAD(,AC_MSG_ERROR(could not find libpthread)) +LIBS="${PTHREAD_LIBS} ${LIBS}" +CFLAGS="${PTHREAD_CFLAGS} ${CFLAGS}" +CC="$PTHREAD_CC" + + AC_SEARCH_LIBS(getopt_long, gnugetopt) AC_SEARCH_LIBS(socket, socket) AC_SEARCH_LIBS(gethostbyname, nsl) @@ -71,77 +141,189 @@ AC_LINK_IFELSE( AC_SUBST(LIBM) LIBS="$save_LIBS" + AC_SEARCH_LIBS(floorf, m) +DETECT_BYTEORDER +ENABLE_UTILLIB sinclude(m4/pod2man.m4) -sinclude(m4/debug.m4) sinclude(m4/dtrace.m4) -sinclude(m4/byteorder.m4) -sinclude(m4/64bit.m4) sinclude(m4/protocol_binary.m4) sinclude(m4/memcached.m4) sinclude(m4/setsockopt.m4) sinclude(m4/hsieh.m4) -sinclude(m4/util.m4) -dnl This is likely subverted by vpath builds. How do we find the original -dnl source dir in the configure step of a vpath build? -if test -d ".hg" +dnl TODO: Remove this define once we are using 2.61 across the board. +# AX_HEADER_ASSERT +# ---------------- +# Check whether to enable assertions. +AC_DEFUN([AX_HEADER_ASSERT], +[ + AC_MSG_CHECKING([whether to enable assertions]) + AC_ARG_ENABLE([assert], + [AS_HELP_STRING([--disable-assert], + [Turn off assertions])], + [ac_cv_assert="no"], + [ac_cv_assert="yes"]) + AC_MSG_RESULT([$ac_cv_assert]) +]) +AX_HEADER_ASSERT + + +AC_ARG_WITH([debug], + [AS_HELP_STRING([--with-debug], + [Add debug code/turns off optimizations (yes|no) @<:@default=no@:>@])], + [with_debug=$withval], + [with_debug=no]) +if test "$with_debug" = "yes" then - building_from_hg=yes + # Debugging. No optimization. + CFLAGS="${DEBUG_CFLAGS} -DDEBUG ${CFLAGS}" else - building_from_hg=no + # Optimized version. No debug + CFLAGS="${OPTIMIZE_CFLAGS} ${CFLAGS}" fi +AC_ARG_ENABLE([profiling], + [AS_HELP_STRING([--enable-profiling], + [Toggle profiling @<:@default=off@:>@])], + [ac_profiling="$enableval"], + [ac_profiling="no"]) + +AC_ARG_ENABLE([coverage], + [AS_HELP_STRING([--enable-coverage], + [Toggle coverage @<:@default=off@:>@])], + [ac_coverage="$enableval"], + [ac_coverage="no"]) + +AC_ARG_ENABLE([unreachable], + [AS_HELP_STRING([--enable-unreachable], + [Enable warnings about unreachable code @<:@default=no@:>@])], + [ac_warn_unreachable="$enableval"], + [ac_warn_unreachable="no"]) + -# We only support GCC and Sun's forte at the moment if test "$GCC" = "yes" then - if test "$ENABLE_DEBUG" = "yes" - then - CFLAGS="-O0 -DHAVE_DEBUG $CFLAGS" - CXXFLAGS="-O0 -DHAVE_DEBUG $CXXFLAGS" - else - CFLAGS="-O3 $CFLAGS" - CXXFLAGS="-O3 $CXXFLAGS" - fi - if test "$building_from_hg" = "yes" - then - CFLAGS="-Werror $CFLAGS" - CXXFLAGS="-Werror $CXXFLAGS" - fi - - CFLAGS="-W -std=iso9899:1999 -Wall -Wextra -Wno-strict-aliasing -pedantic -Wundef -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls -ggdb3 $CFLAGS" - CXXFLAGS="-W -Wall -Wextra -Wno-strict-aliasing -pedantic -Wundef -Woverloaded-virtual -Wnon-virtual-dtor -Wctor-dtor-privacy -Wold-style-cast -Weffc++ -Wconversion -Wmissing-declarations -Wredundant-decls -ggdb3 $CXXFLAGS" + W_STRICT_ALIASING="-Wno-strict-aliasing" -fi + AS_IF([test "$ac_profiling" = "yes"], + [CC_PROFILING="-pg"]) + + AS_IF([test "$ac_coverage" = "yes"], + [CC_COVERAGE="-fprofile-arcs -ftest-coverage"]) + + AS_IF([test "$building_from_bzr" = "yes"], + [W_FAIL="-Werror"]) + + AS_IF([test "$ac_warn_unreachable" = "yes"], + [W_UNREACHABLE="-Wunreachable-code"]) + BASE_WARNINGS="-pedantic -W -Wall -Wextra ${W_FAIL} -Wundef -Wshadow -Wmissing-declarations ${W_STRICT_ALIASING}" + CC_WARNINGS="${BASE_WARNINGS} -Wstrict-prototypes -Wmissing-prototypes -Wredundant-decls -Wswitch-default -Wswitch-enum -Wcast-align" + CXX_WARNINGS="${BASE_WARNINGS} -Woverloaded-virtual -Wnon-virtual-dtor -Wctor-dtor-privacy -Wold-style-cast -Weffc++ -Wno-long-long" + + AC_CACHE_CHECK([whether it is safe to use -Wconversion], + [ac_cv_safe_to_use_Wconversion_], + [save_CFLAGS="$CFLAGS" + CFLAGS="-Werror -Wconversion" + AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM( + [[ +#include +void foo(in_port_t port) +{ + return; +} + ]],[[ +in_port_t x= 0; +foo(x); + ]])], + [ac_cv_safe_to_use_Wconversion_=yes], + [ac_cv_safe_to_use_Wconversion_=no]) + CFLAGS="$save_CFLAGS"]) + dnl disable -Wconversion for now. Will fix later + AS_IF([test "$ac_cv_safe_to_use_Wconversion_" = "disabled"], + [ + CC_WARNINGS="${CC_WARNINGS} -Wconversion" + CXX_WARNINGS="${CXX_WARNINGS} -Wconversion" + ]) + + AC_CACHE_CHECK([whether it is safe to use -Wlogical-op], + [ac_cv_safe_to_use_Wlogical_op_], + [save_CFLAGS="$CFLAGS" + CFLAGS="-Wlogical-op" + AC_COMPILE_IFELSE([ + AC_LANG_PROGRAM( + [[ +#include + ]], [[]]) + ], + [ac_cv_safe_to_use_Wlogical_op_=yes], + [ac_cv_safe_to_use_Wlogical_op_=no]) + CFLAGS="$save_CFLAGS"]) + AS_IF([test "$ac_cv_safe_to_use_Wlogical_op_" = "yes"], + [CC_WARNINGS="${CC_WARNINGS} -Wlogical-op"]) + + AC_CACHE_CHECK([whether it is safe to use -Wredundant-decls from C++], + [ac_cv_safe_to_use_Wredundant_decls_], + [AC_LANG_PUSH(C++) + save_CXXFLAGS="${CXXFLAGS}" + CXXFLAGS="${CXXFLAGS} ${W_FAIL} -Wredundant-decls" + AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM([ +template struct C { void foo(); }; +template void C::foo() { } +template <> void C::foo(); + AC_INCLUDES_DEFAULT])], + [ac_cv_safe_to_use_Wredundant_decls_=yes], + [ac_cv_safe_to_use_Wredundant_decls_=no]) + CXXFLAGS="${save_CXXFLAGS}" + AC_LANG_POP()]) + AS_IF([test "$ac_cv_safe_to_use_Wredundant_decls_" = "yes"], + [CXX_WARNINGS="${CXX_WARNINGS} -Wredundant-decls"], + [CXX_WARNINGS="${CXX_WARNINGS} -Wno-redundant-decls"]) + + NO_REDUNDANT_DECLS="-Wno-redundant-decls" +fi if test "$SUNCC" = "yes" then - if test "$ENABLE_DEBUG" = "yes" - then - CFLAGS="-xO0 -DHAVE_DEBUG $CFLAGS" - CXXFLAGS="-xO0 -DHAVE_DEBUG $CXXFLAGS" - else - CFLAGS="-xO4 -xlibmil -xdepend $CFLAGS" - CXXFLAGS="-xO4 -xlibmil -xdepend $CXXFLAGS" - fi - if test "$building_from_hg" = "yes" - then - CFLAGS="-errwarn $CFLAGS" - CXXFLAGS="-errwarn $CXXFLAGS" - fi - CFLAGS="-Xa -xstrconst -mt -errfmt=error -errshort=tags ${CFLAGS}" - CXXFLAGS="+w +w2 -xwe -mt ${CXXFLAGS}" + AS_IF([test "$ac_profiling" = "yes"], + [CC_PROFILING="-xinstrument=datarace"]) + + AS_IF([test "$ac_warn_fail" = "yes"], + [W_FAIL="-errwarn=%all"]) + + AC_CACHE_CHECK([whether E_PASTE_RESULT_NOT_TOKEN is usable], + [ac_cv_paste_result], + [ + save_CFLAGS="${CFLAGS}" + CFLAGS="-errwarn=%all -erroff=E_PASTE_RESULT_NOT_TOKEN ${CFLAGS}" + AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM([ + AC_INCLUDES_DEFAULT + ],[ + int x= 0;])], + [ac_cv_paste_result=yes], + [ac_cv_paste_result=no]) + CFLAGS="${save_CFLAGS}" + ]) + AS_IF([test $ac_cv_paste_result = yes], + [W_PASTE_RESULT=",E_PASTE_RESULT_NOT_TOKEN"]) + + + CC_WARNINGS="-v -errtags=yes ${W_FAIL} -erroff=E_INTEGER_OVERFLOW_DETECTED${W_PASTE_RESULT}" + CXX_WARNINGS="+w +w2 -xwe -xport64 -errtags=yes ${W_FAIL}" fi +AC_SUBST(NO_REDUNDANT_DECLS) AM_CPPFLAGS="-I\$(top_srcdir) -I\$(top_builddir) ${CPPFLAGS}" -AM_CFLAGS="${CFLAGS}" -AM_CXXFLAGS="${CXXFLAGS}" +AM_CFLAGS="${CC_WARNINGS} ${CC_PROFILING} ${CC_COVERAGE} ${CFLAGS}" +AM_CXXFLAGS="${CXX_WARNING} ${CC_PROFILING} ${CC_COVERAGE} ${CXXFLAGS}" AC_SUBST([AM_CPPFLAGS]) AC_SUBST([AM_CFLAGS]) diff --git a/libmemcached/crc.c b/libmemcached/crc.c index ed22adc4..5c586bf0 100644 --- a/libmemcached/crc.c +++ b/libmemcached/crc.c @@ -77,8 +77,7 @@ static const uint32_t crc32tab[256] = { uint32_t hash_crc32(const char *key, size_t key_length) { uint32_t x; - uint32_t crc; - crc= ~0; + uint32_t crc= UINT32_MAX; for (x= 0; x < key_length; x++) crc= (crc >> 8) ^ crc32tab[(crc ^ (key[x])) & 0xff]; diff --git a/libmemcached/jenkins_hash.c b/libmemcached/jenkins_hash.c index 262ff937..e84cf3ed 100644 --- a/libmemcached/jenkins_hash.c +++ b/libmemcached/jenkins_hash.c @@ -104,6 +104,7 @@ uint32_t jenkins_hash(const void *key, size_t length, uint32_t initval) case 2 : a+=k[0]&0xffff; break; case 1 : a+=k[0]&0xff; break; case 0 : return c; /* zero length strings require no mixing */ + default: return c; } } @@ -153,6 +154,7 @@ uint32_t jenkins_hash(const void *key, size_t length, uint32_t initval) case 1 : a+=k8[0]; break; case 0 : return c; /* zero length requires no mixing */ + default: return c; } } @@ -198,6 +200,7 @@ uint32_t jenkins_hash(const void *key, size_t length, uint32_t initval) case 1 : a+=k[0]; break; case 0 : return c; + default : return c; } #ifdef BYTEORDER_LITTLE_ENDIAN } diff --git a/libmemcached/memcached_analyze.c b/libmemcached/memcached_analyze.c index e2c17fda..41fee384 100644 --- a/libmemcached/memcached_analyze.c +++ b/libmemcached/memcached_analyze.c @@ -60,7 +60,7 @@ static void calc_hit_ratio(memcached_analysis_st *result, } memcached_analysis_st *memcached_analyze(memcached_st *memc, - memcached_stat_st *stat, + memcached_stat_st *memc_stat, memcached_return *error) { uint64_t total_items= 0, total_bytes= 0; @@ -81,14 +81,15 @@ memcached_analysis_st *memcached_analyze(memcached_st *memc, for (x= 0; x < server_count; x++) { - calc_largest_consumption(result, x, stat[x].bytes); - calc_oldest_node(result, x, stat[x].uptime); - calc_least_free_node(result, x, stat[x].limit_maxbytes, stat[x].bytes); + calc_largest_consumption(result, x, memc_stat[x].bytes); + calc_oldest_node(result, x, memc_stat[x].uptime); + calc_least_free_node(result, x, + memc_stat[x].limit_maxbytes, memc_stat[x].bytes); - total_get_hits+= stat[x].get_hits; - total_get_cmds+= stat[x].cmd_get; - total_items+= stat[x].curr_items; - total_bytes+= stat[x].bytes; + total_get_hits+= memc_stat[x].get_hits; + total_get_cmds+= memc_stat[x].cmd_get; + total_items+= memc_stat[x].curr_items; + total_bytes+= memc_stat[x].bytes; } calc_average_item_size(result, total_items, total_bytes); diff --git a/libmemcached/memcached_auto.c b/libmemcached/memcached_auto.c index afb1df3a..700c4183 100644 --- a/libmemcached/memcached_auto.c +++ b/libmemcached/memcached_auto.c @@ -20,11 +20,11 @@ static memcached_return memcached_auto(memcached_st *ptr, server_key= memcached_generate_hash(ptr, key, key_length); - send_length= snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, - "%s %s%.*s %u%s\r\n", verb, - ptr->prefix_key, - (int)key_length, key, - offset, no_reply ? " noreply" : ""); + send_length= (size_t)snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, + "%s %s%.*s %u%s\r\n", verb, + ptr->prefix_key, + (int)key_length, key, + offset, no_reply ? " noreply" : ""); unlikely (send_length >= MEMCACHED_DEFAULT_COMMAND_SIZE) return MEMCACHED_WRITE_FAILURE; diff --git a/libmemcached/memcached_behavior.c b/libmemcached/memcached_behavior.c index fb201d4e..ed295d95 100644 --- a/libmemcached/memcached_behavior.c +++ b/libmemcached/memcached_behavior.c @@ -157,6 +157,10 @@ memcached_return memcached_behavior_set(memcached_st *ptr, case MEMCACHED_BEHAVIOR_AUTO_EJECT_HOSTS: set_behavior_flag(ptr, MEM_AUTO_EJECT_HOSTS, data); break; + default: + /* Shouldn't get here */ + WATCHPOINT_ASSERT(flag); + break; } return MEMCACHED_SUCCESS; @@ -274,6 +278,9 @@ uint64_t memcached_behavior_get(memcached_st *ptr, case MEMCACHED_BEHAVIOR_AUTO_EJECT_HOSTS: temp_flag= MEM_AUTO_EJECT_HOSTS; break; + default: + WATCHPOINT_ASSERT(flag); + break; } WATCHPOINT_ASSERT(temp_flag); /* Programming mistake if it gets this far */ diff --git a/libmemcached/memcached_hash.c b/libmemcached/memcached_hash.c index e6747db5..5d73611c 100644 --- a/libmemcached/memcached_hash.c +++ b/libmemcached/memcached_hash.c @@ -92,6 +92,11 @@ uint32_t memcached_generate_hash_value(const char *key, size_t key_length, memca hash=jenkins_hash(key, key_length, 13); break; } + default: + { + WATCHPOINT_ASSERT(hash_algorithm); + break; + } } return hash; } diff --git a/libmemcached/memcached_hosts.c b/libmemcached/memcached_hosts.c index 3e8b122b..2f1c4cc0 100644 --- a/libmemcached/memcached_hosts.c +++ b/libmemcached/memcached_hosts.c @@ -102,11 +102,11 @@ static int continuum_item_cmp(const void *t1, const void *t2) memcached_return update_continuum(memcached_st *ptr) { - uint32_t index; uint32_t host_index; uint32_t continuum_index= 0; uint32_t value; memcached_server_st *list; + uint32_t pointer_index; uint32_t pointer_counter= 0; uint32_t pointer_per_server= MEMCACHED_POINTS_PER_SERVER; uint32_t pointer_per_hash= 1; @@ -188,7 +188,7 @@ memcached_return update_continuum(memcached_st *ptr) float pct = (float)list[host_index].weight / (float)total_weight; pointer_per_server= floorf(pct * MEMCACHED_POINTS_PER_SERVER_KETAMA / 4 * (float)live_servers + 0.0000000001) * 4; pointer_per_hash= 4; -#ifdef HAVE_DEBUG +#ifdef DEBUG printf("ketama_weighted:%s|%d|%llu|%u\n", list[host_index].hostname, list[host_index].port, @@ -196,21 +196,27 @@ memcached_return update_continuum(memcached_st *ptr) pointer_per_server); #endif } - for (index= 1; index <= pointer_per_server / pointer_per_hash; ++index) + for (pointer_index= 1; + pointer_index <= pointer_per_server / pointer_per_hash; + ++pointer_index) { char sort_host[MEMCACHED_MAX_HOST_SORT_LENGTH]= ""; size_t sort_host_length; if (list[host_index].port == MEMCACHED_DEFAULT_PORT) { - sort_host_length= snprintf(sort_host, MEMCACHED_MAX_HOST_SORT_LENGTH, "%s-%d", - list[host_index].hostname, index - 1); + sort_host_length= snprintf(sort_host, MEMCACHED_MAX_HOST_SORT_LENGTH, + "%s-%d", + list[host_index].hostname, + pointer_index - 1); } else { - sort_host_length= snprintf(sort_host, MEMCACHED_MAX_HOST_SORT_LENGTH, "%s:%d-%d", - list[host_index].hostname, list[host_index].port, index - 1); + sort_host_length= snprintf(sort_host, MEMCACHED_MAX_HOST_SORT_LENGTH, + "%s:%d-%d", + list[host_index].hostname, + list[host_index].port, pointer_index - 1); } WATCHPOINT_ASSERT(sort_host_length); @@ -240,10 +246,10 @@ memcached_return update_continuum(memcached_st *ptr) ptr->continuum_points_counter= pointer_counter; qsort(ptr->continuum, ptr->continuum_points_counter, sizeof(memcached_continuum_item_st), continuum_item_cmp); -#ifdef HAVE_DEBUG - for (index= 0; ptr->number_of_hosts && index < ((live_servers * MEMCACHED_POINTS_PER_SERVER) - 1); index++) +#ifdef DEBUG + for (pointer_index= 0; ptr->number_of_hosts && pointer_index < ((live_servers * MEMCACHED_POINTS_PER_SERVER) - 1); pointer_index++) { - WATCHPOINT_ASSERT(ptr->continuum[index].value <= ptr->continuum[index + 1].value); + WATCHPOINT_ASSERT(ptr->continuum[pointer_index].value <= ptr->continuum[pointer_index + 1].value); } #endif @@ -375,20 +381,20 @@ static memcached_return server_add(memcached_st *ptr, const char *hostname, memcached_return memcached_server_remove(memcached_server_st *st_ptr) { - uint32_t x, index; + uint32_t x, host_index; memcached_st *ptr= st_ptr->root; memcached_server_st *list= ptr->hosts; - for (x= 0, index= 0; x < ptr->number_of_hosts; x++) + for (x= 0, host_index= 0; x < ptr->number_of_hosts; x++) { if (strncmp(list[x].hostname, st_ptr->hostname, MEMCACHED_MAX_HOST_LENGTH) != 0 || list[x].port != st_ptr->port) { - if (index != x) - memcpy(list+index, list+x, sizeof(memcached_server_st)); - index++; + if (host_index != x) + memcpy(list+host_index, list+x, sizeof(memcached_server_st)); + host_index++; } } - ptr->number_of_hosts= index; + ptr->number_of_hosts= host_index; if (st_ptr->address_info) { diff --git a/libmemcached/memcached_internal.h b/libmemcached/memcached_internal.h index cda67a20..086915aa 100644 --- a/libmemcached/memcached_internal.h +++ b/libmemcached/memcached_internal.h @@ -17,7 +17,8 @@ void *libmemcached_malloc(memcached_st *ptr __attribute__((unused)), const size_t size); void *libmemcached_realloc(memcached_st *ptr __attribute__((unused)), void *mem, const size_t size); - +void *libmemcached_calloc(memcached_st *ptr __attribute__((unused)), + size_t nelem, size_t size); #ifdef __cplusplus } #endif diff --git a/libmemcached/memcached_io.c b/libmemcached/memcached_io.c index 7bdb7238..69771d71 100644 --- a/libmemcached/memcached_io.c +++ b/libmemcached/memcached_io.c @@ -257,7 +257,7 @@ memcached_return memcached_io_close(memcached_server_st *ptr) { r= shutdown(ptr->fd, SHUT_RDWR); -#ifdef HAVE_DEBUG +#ifdef DEBUG if (r && errno != ENOTCONN) { WATCHPOINT_NUMBER(ptr->fd); @@ -268,7 +268,7 @@ memcached_return memcached_io_close(memcached_server_st *ptr) } r= close(ptr->fd); -#ifdef HAVE_DEBUG +#ifdef DEBUG if (r != 0) WATCHPOINT_ERRNO(errno); #endif @@ -280,10 +280,10 @@ memcached_server_st *memcached_io_get_readable_server(memcached_st *memc) { #define MAX_SERVERS_TO_POLL 100 struct pollfd fds[MAX_SERVERS_TO_POLL]; - unsigned int index= 0; + unsigned int host_index= 0; for (unsigned int x= 0; - x< memc->number_of_hosts && index < MAX_SERVERS_TO_POLL; + x< memc->number_of_hosts && host_index < MAX_SERVERS_TO_POLL; ++x) { if (memc->hosts[x].read_buffer_length > 0) /* I have data in the buffer */ @@ -291,14 +291,14 @@ memcached_server_st *memcached_io_get_readable_server(memcached_st *memc) if (memcached_server_response_count(&memc->hosts[x]) > 0) { - fds[index].events = POLLIN; - fds[index].revents = 0; - fds[index].fd = memc->hosts[x].fd; - ++index; + fds[host_index].events = POLLIN; + fds[host_index].revents = 0; + fds[host_index].fd = memc->hosts[x].fd; + ++host_index; } } - if (index < 2) + if (host_index < 2) { /* We have 0 or 1 server with pending events.. */ for (unsigned int x= 0; x< memc->number_of_hosts; ++x) @@ -308,7 +308,7 @@ memcached_server_st *memcached_io_get_readable_server(memcached_st *memc) return NULL; } - int err= poll(fds, index, memc->poll_timeout); + int err= poll(fds, host_index, memc->poll_timeout); switch (err) { case -1: memc->cached_errno = errno; @@ -316,7 +316,7 @@ memcached_server_st *memcached_io_get_readable_server(memcached_st *memc) case 0: break; default: - for (unsigned int x= 0; x < index; ++x) + for (unsigned int x= 0; x < host_index; ++x) if (fds[x].revents & POLLIN) for (unsigned int y= 0; y < memc->number_of_hosts; ++y) if (memc->hosts[y].fd == fds[x].fd) @@ -360,7 +360,7 @@ static ssize_t io_flush(memcached_server_st *ptr, return 0; /* Looking for memory overflows */ -#if defined(HAVE_DEBUG) +#if defined(DEBUG) if (write_length == MEMCACHED_MAX_BUFFER) WATCHPOINT_ASSERT(ptr->write_buffer == local_write_ptr); WATCHPOINT_ASSERT((ptr->write_buffer + MEMCACHED_MAX_BUFFER) >= (local_write_ptr + write_length)); diff --git a/libmemcached/memcached_stats.c b/libmemcached/memcached_stats.c index d52f781a..c7e1197b 100644 --- a/libmemcached/memcached_stats.c +++ b/libmemcached/memcached_stats.c @@ -30,7 +30,7 @@ static char *memcached_stat_keys[] = { }; -static memcached_return set_data(memcached_stat_st *stat, char *key, char *value) +static memcached_return set_data(memcached_stat_st *memc_stat, char *key, char *value) { if(strlen(key) < 1) @@ -40,24 +40,24 @@ static memcached_return set_data(memcached_stat_st *stat, char *key, char *value } else if (!strcmp("pid", key)) { - stat->pid= strtol(value, (char **)NULL, 10); + memc_stat->pid= strtol(value, (char **)NULL, 10); } else if (!strcmp("uptime", key)) { - stat->uptime= strtol(value, (char **)NULL, 10); + memc_stat->uptime= strtol(value, (char **)NULL, 10); } else if (!strcmp("time", key)) { - stat->time= strtol(value, (char **)NULL, 10); + memc_stat->time= strtol(value, (char **)NULL, 10); } else if (!strcmp("version", key)) { - memcpy(stat->version, value, strlen(value)); - stat->version[strlen(value)]= 0; + memcpy(memc_stat->version, value, strlen(value)); + memc_stat->version[strlen(value)]= 0; } else if (!strcmp("pointer_size", key)) { - stat->pointer_size= strtol(value, (char **)NULL, 10); + memc_stat->pointer_size= strtol(value, (char **)NULL, 10); } else if (!strcmp("rusage_user", key)) { @@ -65,8 +65,8 @@ static memcached_return set_data(memcached_stat_st *stat, char *key, char *value for (walk_ptr= value; (!ispunct(*walk_ptr)); walk_ptr++); *walk_ptr= 0; walk_ptr++; - stat->rusage_user_seconds= strtol(value, (char **)NULL, 10); - stat->rusage_user_microseconds= strtol(walk_ptr, (char **)NULL, 10); + memc_stat->rusage_user_seconds= strtol(value, (char **)NULL, 10); + memc_stat->rusage_user_microseconds= strtol(walk_ptr, (char **)NULL, 10); } else if (!strcmp("rusage_system", key)) { @@ -74,68 +74,68 @@ static memcached_return set_data(memcached_stat_st *stat, char *key, char *value for (walk_ptr= value; (!ispunct(*walk_ptr)); walk_ptr++); *walk_ptr= 0; walk_ptr++; - stat->rusage_system_seconds= strtol(value, (char **)NULL, 10); - stat->rusage_system_microseconds= strtol(walk_ptr, (char **)NULL, 10); + memc_stat->rusage_system_seconds= strtol(value, (char **)NULL, 10); + memc_stat->rusage_system_microseconds= strtol(walk_ptr, (char **)NULL, 10); } else if (!strcmp("curr_items", key)) { - stat->curr_items= strtol(value, (char **)NULL, 10); + memc_stat->curr_items= strtol(value, (char **)NULL, 10); } else if (!strcmp("total_items", key)) { - stat->total_items= strtol(value, (char **)NULL, 10); + memc_stat->total_items= strtol(value, (char **)NULL, 10); } else if (!strcmp("bytes_read", key)) { - stat->bytes_read= strtoll(value, (char **)NULL, 10); + memc_stat->bytes_read= strtoll(value, (char **)NULL, 10); } else if (!strcmp("bytes_written", key)) { - stat->bytes_written= strtoll(value, (char **)NULL, 10); + memc_stat->bytes_written= strtoll(value, (char **)NULL, 10); } else if (!strcmp("bytes", key)) { - stat->bytes= strtoll(value, (char **)NULL, 10); + memc_stat->bytes= strtoll(value, (char **)NULL, 10); } else if (!strcmp("curr_connections", key)) { - stat->curr_connections= strtoll(value, (char **)NULL, 10); + memc_stat->curr_connections= strtoll(value, (char **)NULL, 10); } else if (!strcmp("total_connections", key)) { - stat->total_connections= strtoll(value, (char **)NULL, 10); + memc_stat->total_connections= strtoll(value, (char **)NULL, 10); } else if (!strcmp("connection_structures", key)) { - stat->connection_structures= strtol(value, (char **)NULL, 10); + memc_stat->connection_structures= strtol(value, (char **)NULL, 10); } else if (!strcmp("cmd_get", key)) { - stat->cmd_get= strtoll(value, (char **)NULL, 10); + memc_stat->cmd_get= strtoll(value, (char **)NULL, 10); } else if (!strcmp("cmd_set", key)) { - stat->cmd_set= strtoll(value, (char **)NULL, 10); + memc_stat->cmd_set= strtoll(value, (char **)NULL, 10); } else if (!strcmp("get_hits", key)) { - stat->get_hits= strtoll(value, (char **)NULL, 10); + memc_stat->get_hits= strtoll(value, (char **)NULL, 10); } else if (!strcmp("get_misses", key)) { - stat->get_misses= (uint64_t)strtoll(value, (char **)NULL, 10); + memc_stat->get_misses= (uint64_t)strtoll(value, (char **)NULL, 10); } else if (!strcmp("evictions", key)) { - stat->evictions= (uint64_t)strtoll(value, (char **)NULL, 10); + memc_stat->evictions= (uint64_t)strtoll(value, (char **)NULL, 10); } else if (!strcmp("limit_maxbytes", key)) { - stat->limit_maxbytes= strtoll(value, (char **)NULL, 10); + memc_stat->limit_maxbytes= strtoll(value, (char **)NULL, 10); } else if (!strcmp("threads", key)) { - stat->threads= strtol(value, (char **)NULL, 10); + memc_stat->threads= strtol(value, (char **)NULL, 10); } else if (!(strcmp("delete_misses", key) == 0 ||/* New stats in the 1.3 beta */ strcmp("delete_hits", key) == 0 ||/* Just swallow them for now.. */ @@ -157,7 +157,7 @@ static memcached_return set_data(memcached_stat_st *stat, char *key, char *value return MEMCACHED_SUCCESS; } -char *memcached_stat_get_value(memcached_st *ptr, memcached_stat_st *stat, +char *memcached_stat_get_value(memcached_st *ptr, memcached_stat_st *memc_stat, const char *key, memcached_return *error) { char buffer[SMALL_STRING_LEN]; @@ -167,49 +167,49 @@ char *memcached_stat_get_value(memcached_st *ptr, memcached_stat_st *stat, *error= MEMCACHED_SUCCESS; if (!memcmp("pid", key, strlen("pid"))) - length= snprintf(buffer, SMALL_STRING_LEN,"%u", stat->pid); + length= snprintf(buffer, SMALL_STRING_LEN,"%u", memc_stat->pid); else if (!memcmp("uptime", key, strlen("uptime"))) - length= snprintf(buffer, SMALL_STRING_LEN,"%u", stat->uptime); + length= snprintf(buffer, SMALL_STRING_LEN,"%u", memc_stat->uptime); else if (!memcmp("time", key, strlen("time"))) - length= snprintf(buffer, SMALL_STRING_LEN,"%llu", (unsigned long long)stat->time); + length= snprintf(buffer, SMALL_STRING_LEN,"%llu", (unsigned long long)memc_stat->time); else if (!memcmp("version", key, strlen("version"))) - length= snprintf(buffer, SMALL_STRING_LEN,"%s", stat->version); + length= snprintf(buffer, SMALL_STRING_LEN,"%s", memc_stat->version); else if (!memcmp("pointer_size", key, strlen("pointer_size"))) - length= snprintf(buffer, SMALL_STRING_LEN,"%u", stat->pointer_size); + length= snprintf(buffer, SMALL_STRING_LEN,"%u", memc_stat->pointer_size); else if (!memcmp("rusage_user", key, strlen("rusage_user"))) - length= snprintf(buffer, SMALL_STRING_LEN,"%u.%u", stat->rusage_user_seconds, stat->rusage_user_microseconds); + length= snprintf(buffer, SMALL_STRING_LEN,"%u.%u", memc_stat->rusage_user_seconds, memc_stat->rusage_user_microseconds); else if (!memcmp("rusage_system", key, strlen("rusage_system"))) - length= snprintf(buffer, SMALL_STRING_LEN,"%u.%u", stat->rusage_system_seconds, stat->rusage_system_microseconds); + length= snprintf(buffer, SMALL_STRING_LEN,"%u.%u", memc_stat->rusage_system_seconds, memc_stat->rusage_system_microseconds); else if (!memcmp("curr_items", key, strlen("curr_items"))) - length= snprintf(buffer, SMALL_STRING_LEN,"%u", stat->curr_items); + length= snprintf(buffer, SMALL_STRING_LEN,"%u", memc_stat->curr_items); else if (!memcmp("total_items", key, strlen("total_items"))) - length= snprintf(buffer, SMALL_STRING_LEN,"%u", stat->total_items); + length= snprintf(buffer, SMALL_STRING_LEN,"%u", memc_stat->total_items); else if (!memcmp("bytes", key, strlen("bytes"))) - length= snprintf(buffer, SMALL_STRING_LEN,"%llu", (unsigned long long)stat->bytes); + length= snprintf(buffer, SMALL_STRING_LEN,"%llu", (unsigned long long)memc_stat->bytes); else if (!memcmp("curr_connections", key, strlen("curr_connections"))) - length= snprintf(buffer, SMALL_STRING_LEN,"%u", stat->curr_connections); + length= snprintf(buffer, SMALL_STRING_LEN,"%u", memc_stat->curr_connections); else if (!memcmp("total_connections", key, strlen("total_connections"))) - length= snprintf(buffer, SMALL_STRING_LEN,"%u", stat->total_connections); + length= snprintf(buffer, SMALL_STRING_LEN,"%u", memc_stat->total_connections); else if (!memcmp("connection_structures", key, strlen("connection_structures"))) - length= snprintf(buffer, SMALL_STRING_LEN,"%u", stat->connection_structures); + length= snprintf(buffer, SMALL_STRING_LEN,"%u", memc_stat->connection_structures); else if (!memcmp("cmd_get", key, strlen("cmd_get"))) - length= snprintf(buffer, SMALL_STRING_LEN,"%llu", (unsigned long long)stat->cmd_get); + length= snprintf(buffer, SMALL_STRING_LEN,"%llu", (unsigned long long)memc_stat->cmd_get); else if (!memcmp("cmd_set", key, strlen("cmd_set"))) - length= snprintf(buffer, SMALL_STRING_LEN,"%llu", (unsigned long long)stat->cmd_set); + length= snprintf(buffer, SMALL_STRING_LEN,"%llu", (unsigned long long)memc_stat->cmd_set); else if (!memcmp("get_hits", key, strlen("get_hits"))) - length= snprintf(buffer, SMALL_STRING_LEN,"%llu", (unsigned long long)stat->get_hits); + length= snprintf(buffer, SMALL_STRING_LEN,"%llu", (unsigned long long)memc_stat->get_hits); else if (!memcmp("get_misses", key, strlen("get_misses"))) - length= snprintf(buffer, SMALL_STRING_LEN,"%llu", (unsigned long long)stat->get_misses); + length= snprintf(buffer, SMALL_STRING_LEN,"%llu", (unsigned long long)memc_stat->get_misses); else if (!memcmp("evictions", key, strlen("evictions"))) - length= snprintf(buffer, SMALL_STRING_LEN,"%llu", (unsigned long long)stat->evictions); + length= snprintf(buffer, SMALL_STRING_LEN,"%llu", (unsigned long long)memc_stat->evictions); else if (!memcmp("bytes_read", key, strlen("bytes_read"))) - length= snprintf(buffer, SMALL_STRING_LEN,"%llu", (unsigned long long)stat->bytes_read); + length= snprintf(buffer, SMALL_STRING_LEN,"%llu", (unsigned long long)memc_stat->bytes_read); else if (!memcmp("bytes_written", key, strlen("bytes_written"))) - length= snprintf(buffer, SMALL_STRING_LEN,"%llu", (unsigned long long)stat->bytes_written); + length= snprintf(buffer, SMALL_STRING_LEN,"%llu", (unsigned long long)memc_stat->bytes_written); else if (!memcmp("limit_maxbytes", key, strlen("limit_maxbytes"))) - length= snprintf(buffer, SMALL_STRING_LEN,"%llu", (unsigned long long)stat->limit_maxbytes); + length= snprintf(buffer, SMALL_STRING_LEN,"%llu", (unsigned long long)memc_stat->limit_maxbytes); else if (!memcmp("threads", key, strlen("threads"))) - length= snprintf(buffer, SMALL_STRING_LEN,"%u", stat->threads); + length= snprintf(buffer, SMALL_STRING_LEN,"%u", memc_stat->threads); else { *error= MEMCACHED_NOTFOUND; @@ -224,7 +224,7 @@ char *memcached_stat_get_value(memcached_st *ptr, memcached_stat_st *stat, } static memcached_return binary_stats_fetch(memcached_st *ptr, - memcached_stat_st *stat, + memcached_stat_st *memc_stat, char *args, unsigned int server_key) { @@ -279,7 +279,7 @@ static memcached_return binary_stats_fetch(memcached_st *ptr, return rc; } - unlikely((set_data(stat, buffer, buffer + strlen(buffer) + 1)) == MEMCACHED_UNKNOWN_STAT_KEY) + unlikely((set_data(memc_stat, buffer, buffer + strlen(buffer) + 1)) == MEMCACHED_UNKNOWN_STAT_KEY) { WATCHPOINT_ERROR(MEMCACHED_UNKNOWN_STAT_KEY); WATCHPOINT_ASSERT(0); @@ -295,7 +295,7 @@ static memcached_return binary_stats_fetch(memcached_st *ptr, } static memcached_return ascii_stats_fetch(memcached_st *ptr, - memcached_stat_st *stat, + memcached_stat_st *memc_stat, char *args, unsigned int server_key) { @@ -337,7 +337,7 @@ static memcached_return ascii_stats_fetch(memcached_st *ptr, value= string_ptr; value[(size_t)(end_ptr-string_ptr)]= 0; string_ptr= end_ptr + 2; - unlikely((set_data(stat, key, value)) == MEMCACHED_UNKNOWN_STAT_KEY) + unlikely((set_data(memc_stat, key, value)) == MEMCACHED_UNKNOWN_STAT_KEY) { WATCHPOINT_ERROR(MEMCACHED_UNKNOWN_STAT_KEY); WATCHPOINT_ASSERT(0); @@ -392,7 +392,7 @@ memcached_stat_st *memcached_stat(memcached_st *ptr, char *args, memcached_retur return stats; } -memcached_return memcached_stat_servername(memcached_stat_st *stat, char *args, +memcached_return memcached_stat_servername(memcached_stat_st *memc_stat, char *args, char *hostname, unsigned int port) { memcached_return rc; @@ -403,9 +403,9 @@ memcached_return memcached_stat_servername(memcached_stat_st *stat, char *args, memcached_server_add(&memc, hostname, port); if (memc.flags & MEM_BINARY_PROTOCOL) - rc= binary_stats_fetch(&memc, stat, args, 0); + rc= binary_stats_fetch(&memc, memc_stat, args, 0); else - rc= ascii_stats_fetch(&memc, stat, args, 0); + rc= ascii_stats_fetch(&memc, memc_stat, args, 0); memcached_free(&memc); @@ -416,9 +416,10 @@ memcached_return memcached_stat_servername(memcached_stat_st *stat, char *args, We make a copy of the keys since at some point in the not so distant future we will add support for "found" keys. */ -char ** memcached_stat_get_keys(memcached_st *ptr, memcached_stat_st *stat __attribute__((unused)), +char ** memcached_stat_get_keys(memcached_st *ptr, memcached_stat_st *memc_stat, memcached_return *error) { + (void) memc_stat; char **list; size_t length= sizeof(memcached_stat_keys); @@ -437,16 +438,16 @@ char ** memcached_stat_get_keys(memcached_st *ptr, memcached_stat_st *stat __att return list; } -void memcached_stat_free(memcached_st *ptr, memcached_stat_st *stat) +void memcached_stat_free(memcached_st *ptr, memcached_stat_st *memc_stat) { - if (stat == NULL) + if (memc_stat == NULL) { WATCHPOINT_ASSERT(0); /* Be polite, but when debugging catch this as an error */ return; } if (ptr) - ptr->call_free(ptr, stat); + ptr->call_free(ptr, memc_stat); else - free(stat); + free(memc_stat); } diff --git a/libmemcached/memcached_storage.c b/libmemcached/memcached_storage.c index 97d345bd..f18b6d89 100644 --- a/libmemcached/memcached_storage.c +++ b/libmemcached/memcached_storage.c @@ -381,6 +381,9 @@ static inline uint8_t get_com_code(memcached_storage_action verb, bool noreply) case PREPEND_OP: ret=PROTOCOL_BINARY_CMD_PREPENDQ; break; + default: + WATCHPOINT_ASSERT(verb); + break; } else switch (verb) @@ -401,6 +404,9 @@ static inline uint8_t get_com_code(memcached_storage_action verb, bool noreply) case PREPEND_OP: ret=PROTOCOL_BINARY_CMD_PREPEND; break; + default: + WATCHPOINT_ASSERT(verb); + break; } return ret; diff --git a/libmemcached/memcached_strerror.c b/libmemcached/memcached_strerror.c index 44f8f88a..e643db2b 100644 --- a/libmemcached/memcached_strerror.c +++ b/libmemcached/memcached_strerror.c @@ -54,6 +54,8 @@ char *memcached_strerror(memcached_st *ptr __attribute__((unused)), memcached_re return "SERVER VALUE"; case MEMCACHED_STAT: return "STAT VALUE"; + case MEMCACHED_ITEM: + return "ITEM"; case MEMCACHED_ERRNO: return "SYSTEM ERROR"; case MEMCACHED_FAIL_UNIX_SOCKET: diff --git a/libmemcached/memcached_watchpoint.h b/libmemcached/memcached_watchpoint.h index 10cbdbd8..ab479f17 100644 --- a/libmemcached/memcached_watchpoint.h +++ b/libmemcached/memcached_watchpoint.h @@ -14,7 +14,7 @@ extern "C" { #endif /* Some personal debugging functions */ -#if defined(MEMCACHED_INTERNAL) && defined(HAVE_DEBUG) +#if defined(MEMCACHED_INTERNAL) && defined(DEBUG) #include #define WATCHPOINT fprintf(stderr, "\nWATCHPOINT %s:%d (%s)\n", __FILE__, __LINE__,__func__);fflush(stdout); @@ -36,7 +36,7 @@ extern "C" { #define WATCHPOINT_ASSERT_PRINT(A,B,C) #define WATCHPOINT_ASSERT(A) -#endif /* MEMCACHED_INTERNAL && HAVE_DEBUG */ +#endif /* MEMCACHED_INTERNAL && DEBUG */ #ifdef __cplusplus } diff --git a/libmemcached/murmur_hash.c b/libmemcached/murmur_hash.c index c9e60f5b..edb9e777 100644 --- a/libmemcached/murmur_hash.c +++ b/libmemcached/murmur_hash.c @@ -60,6 +60,7 @@ uint32_t murmur_hash(const char *key, size_t length) case 2: h ^= data[1] << 8; case 1: h ^= data[0]; h *= m; + default: break; }; /* diff --git a/m4/64bit.m4 b/m4/64bit.m4 index a704c655..377636e6 100644 --- a/m4/64bit.m4 +++ b/m4/64bit.m4 @@ -1,31 +1,39 @@ dnl --------------------------------------------------------------------------- -dnl Macro: 64BIT +dnl Macro: SOLARIS_64BIT dnl --------------------------------------------------------------------------- -AC_ARG_ENABLE(64bit, - [ --enable-64bit Build 64bit library.], - [ - org_cflags=$CFLAGS - CFLAGS=-m64 - AC_LANG(C) - AC_RUN_IFELSE([ - AC_LANG_PROGRAM([], [ if (sizeof(void*) != 8) return 1;]) - ],[ - CFLAGS="$CFLAGS $org_cflags" - ],[ - AC_MSG_ERROR([Don't know how to build a 64-bit object.]) - ]) - org_cxxflags=$CXXFLAGS - CXXFLAGS=-m64 - AC_LANG(C++) - AC_RUN_IFELSE([ - AC_LANG_PROGRAM([], [ if (sizeof(void*) != 8) return 1;]) - ],[ - CXXFLAGS="$CXXFLAGS $org_cxxflags" - ],[ - AC_MSG_ERROR([Don't know how to build a 64-bit object.]) - ]) +AC_DEFUN([SOLARIS_64BIT],[ +AC_CHECK_PROGS(ISAINFO, [isainfo], [no]) +if test "x$ISAINFO" != "xno" +then + isainfo_b=`${ISAINFO} -b` + spro_common_flags="-mt" + if test "x$isainfo_b" = "x64" + then + AC_ARG_ENABLE([64bit], + [AS_HELP_STRING([--disable-64bit], + [Build 64 bit binary @<:@default=on@:>@])], + [ac_enable_64bit="$enableval"], + [ac_enable_64bit="yes"]) - ]) + if test "x$ac_enable_64bit" = "xyes" + then + if test "x$libdir" = "x\${exec_prefix}/lib" ; then + # The user hasn't overridden the default libdir, so we'll + # the dir suffix to match solaris 32/64-bit policy + isainfo_k=`${ISAINFO} -k` + libdir="${libdir}/${isainfo_k}" + fi + CFLAGS="-m64 $CFLAGS" + CXXFLAGS="-m64 $CXXFLAGS" + if test "$target_cpu" = "sparc" -a "x$SUNCC" = "xyes" + then + CFLAGS="-xmemalign=8s $CFLAGS" + CXXFLAGS="-xmemalign=8s $CXXFLAGS" + fi + fi + fi +fi +]) dnl --------------------------------------------------------------------------- dnl End Macro: 64BIT dnl --------------------------------------------------------------------------- diff --git a/m4/acx_pthread.m4 b/m4/acx_pthread.m4 new file mode 100644 index 00000000..65f5a172 --- /dev/null +++ b/m4/acx_pthread.m4 @@ -0,0 +1,276 @@ +##### http://autoconf-archive.cryp.to/acx_pthread.html +# +# SYNOPSIS +# +# ACX_PTHREAD([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]]) +# +# DESCRIPTION +# +# This macro figures out how to build C programs using POSIX threads. +# It sets the PTHREAD_LIBS output variable to the threads library and +# linker flags, and the PTHREAD_CFLAGS output variable to any special +# C compiler flags that are needed. (The user can also force certain +# compiler flags/libs to be tested by setting these environment +# variables.) +# +# Also sets PTHREAD_CC to any special C compiler that is needed for +# multi-threaded programs (defaults to the value of CC otherwise). +# (This is necessary on AIX to use the special cc_r compiler alias.) +# +# NOTE: You are assumed to not only compile your program with these +# flags, but also link it with them as well. e.g. you should link +# with $PTHREAD_CC $CFLAGS $PTHREAD_CFLAGS $LDFLAGS ... $PTHREAD_LIBS +# $LIBS +# +# If you are only building threads programs, you may wish to use +# these variables in your default LIBS, CFLAGS, and CC: +# +# LIBS="$PTHREAD_LIBS $LIBS" +# CFLAGS="$CFLAGS $PTHREAD_CFLAGS" +# CC="$PTHREAD_CC" +# +# In addition, if the PTHREAD_CREATE_JOINABLE thread-attribute +# constant has a nonstandard name, defines PTHREAD_CREATE_JOINABLE to +# that name (e.g. PTHREAD_CREATE_UNDETACHED on AIX). +# +# ACTION-IF-FOUND is a list of shell commands to run if a threads +# library is found, and ACTION-IF-NOT-FOUND is a list of commands to +# run it if it is not found. If ACTION-IF-FOUND is not specified, the +# default action will define HAVE_PTHREAD. +# +# Please let the authors know if this macro fails on any platform, or +# if you have any other suggestions or comments. This macro was based +# on work by SGJ on autoconf scripts for FFTW (http://www.fftw.org/) +# (with help from M. Frigo), as well as ac_pthread and hb_pthread +# macros posted by Alejandro Forero Cuervo to the autoconf macro +# repository. We are also grateful for the helpful feedback of +# numerous users. +# +# LAST MODIFICATION +# +# 2006-05-29 +# +# COPYLEFT +# +# Copyright (c) 2006 Steven G. Johnson +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 2 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA +# 02111-1307, USA. +# +# As a special exception, the respective Autoconf Macro's copyright +# owner gives unlimited permission to copy, distribute and modify the +# configure scripts that are the output of Autoconf when processing +# the Macro. You need not follow the terms of the GNU General Public +# License when using or distributing such scripts, even though +# portions of the text of the Macro appear in them. The GNU General +# Public License (GPL) does govern all other use of the material that +# constitutes the Autoconf Macro. +# +# This special exception to the GPL applies to versions of the +# Autoconf Macro released by the Autoconf Macro Archive. When you +# make and distribute a modified version of the Autoconf Macro, you +# may extend this special exception to the GPL to apply to your +# modified version as well. + +AC_DEFUN([ACX_PTHREAD], [ +AC_REQUIRE([AC_CANONICAL_HOST]) +AC_LANG_PUSH([C]) +acx_pthread_ok=no + +# We used to check for pthread.h first, but this fails if pthread.h +# requires special compiler flags (e.g. on True64 or Sequent). +# It gets checked for in the link test anyway. + +# First of all, check if the user has set any of the PTHREAD_LIBS, +# etcetera environment variables, and if threads linking works using +# them: +if test x"$PTHREAD_LIBS$PTHREAD_CFLAGS" != x; then + save_CFLAGS="$CFLAGS" + CFLAGS="$CFLAGS $PTHREAD_CFLAGS" + save_LIBS="$LIBS" + LIBS="$PTHREAD_LIBS $LIBS" + AC_MSG_CHECKING([for pthread_join in LIBS=$PTHREAD_LIBS with CFLAGS=$PTHREAD_CFLAGS]) + AC_TRY_LINK_FUNC(pthread_join, acx_pthread_ok=yes) + AC_MSG_RESULT($acx_pthread_ok) + if test x"$acx_pthread_ok" = xno; then + PTHREAD_LIBS="" + PTHREAD_CFLAGS="" + fi + LIBS="$save_LIBS" + CFLAGS="$save_CFLAGS" +fi + +# We must check for the threads library under a number of different +# names; the ordering is very important because some systems +# (e.g. DEC) have both -lpthread and -lpthreads, where one of the +# libraries is broken (non-POSIX). + +# Create a list of thread flags to try. Items starting with a "-" are +# C compiler flags, and other items are library names, except for "none" +# which indicates that we try without any flags at all, and "pthread-config" +# which is a program returning the flags for the Pth emulation library. + +acx_pthread_flags="pthreads none -Kthread -kthread lthread -pthread -pthreads -mthreads pthread --thread-safe -mt pthread-config" + +# The ordering *is* (sometimes) important. Some notes on the +# individual items follow: + +# pthreads: AIX (must check this before -lpthread) +# none: in case threads are in libc; should be tried before -Kthread and +# other compiler flags to prevent continual compiler warnings +# -Kthread: Sequent (threads in libc, but -Kthread needed for pthread.h) +# -kthread: FreeBSD kernel threads (preferred to -pthread since SMP-able) +# lthread: LinuxThreads port on FreeBSD (also preferred to -pthread) +# -pthread: Linux/gcc (kernel threads), BSD/gcc (userland threads) +# -pthreads: Solaris/gcc +# -mthreads: Mingw32/gcc, Lynx/gcc +# -mt: Sun Workshop C (may only link SunOS threads [-lthread], but it +# doesn't hurt to check since this sometimes defines pthreads too; +# also defines -D_REENTRANT) +# ... -mt is also the pthreads flag for HP/aCC +# pthread: Linux, etcetera +# --thread-safe: KAI C++ +# pthread-config: use pthread-config program (for GNU Pth library) + +case "${host_cpu}-${host_os}" in + *solaris*) + + # On Solaris (at least, for some versions), libc contains stubbed + # (non-functional) versions of the pthreads routines, so link-based + # tests will erroneously succeed. (We need to link with -pthreads/-mt/ + # -lpthread.) (The stubs are missing pthread_cleanup_push, or rather + # a function called by this macro, so we could check for that, but + # who knows whether they'll stub that too in a future libc.) So, + # we'll just look for -pthreads and -lpthread first: + + acx_pthread_flags="-pthreads pthread -mt -pthread $acx_pthread_flags" + ;; +esac + +if test x"$acx_pthread_ok" = xno; then +for flag in $acx_pthread_flags; do + + case $flag in + none) + AC_MSG_CHECKING([whether pthreads work without any flags]) + ;; + + -*) + AC_MSG_CHECKING([whether pthreads work with $flag]) + PTHREAD_CFLAGS="$flag" + ;; + + pthread-config) + AC_CHECK_PROG(acx_pthread_config, pthread-config, yes, no) + if test x"$acx_pthread_config" = xno; then continue; fi + PTHREAD_CFLAGS="`pthread-config --cflags`" + PTHREAD_LIBS="`pthread-config --ldflags` `pthread-config --libs`" + ;; + + *) + AC_MSG_CHECKING([for the pthreads library -l$flag]) + PTHREAD_LIBS="-l$flag" + ;; + esac + + save_LIBS="$LIBS" + save_CFLAGS="$CFLAGS" + LIBS="$PTHREAD_LIBS $LIBS" + CFLAGS="$CFLAGS $PTHREAD_CFLAGS" + + # Check for various functions. We must include pthread.h, + # since some functions may be macros. (On the Sequent, we + # need a special flag -Kthread to make this header compile.) + # We check for pthread_join because it is in -lpthread on IRIX + # while pthread_create is in libc. We check for pthread_attr_init + # due to DEC craziness with -lpthreads. We check for + # pthread_cleanup_push because it is one of the few pthread + # functions on Solaris that doesn't have a non-functional libc stub. + # We try pthread_create on general principles. + AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include ]], [[pthread_t th; pthread_join(th, 0); + pthread_attr_init(0); pthread_cleanup_push(0, 0); + pthread_create(0,0,0,0); pthread_cleanup_pop(0); ]])],[acx_pthread_ok=yes],[]) + + LIBS="$save_LIBS" + CFLAGS="$save_CFLAGS" + + AC_MSG_RESULT($acx_pthread_ok) + if test "x$acx_pthread_ok" = xyes; then + break; + fi + + PTHREAD_LIBS="" + PTHREAD_CFLAGS="" +done +fi + +# Various other checks: +if test "x$acx_pthread_ok" = xyes; then + save_LIBS="$LIBS" + LIBS="$PTHREAD_LIBS $LIBS" + save_CFLAGS="$CFLAGS" + CFLAGS="$CFLAGS $PTHREAD_CFLAGS" + + # Detect AIX lossage: JOINABLE attribute is called UNDETACHED. + AC_MSG_CHECKING([for joinable pthread attribute]) + attr_name=unknown + for attr in PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_UNDETACHED; do + AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include ]], [[int attr=$attr; return attr;]])],[attr_name=$attr; break],[]) + done + AC_MSG_RESULT($attr_name) + if test "$attr_name" != PTHREAD_CREATE_JOINABLE; then + AC_DEFINE_UNQUOTED(PTHREAD_CREATE_JOINABLE, $attr_name, + [Define to necessary symbol if this constant + uses a non-standard name on your system.]) + fi + + AC_MSG_CHECKING([if more special flags are required for pthreads]) + flag=no + case "${host_cpu}-${host_os}" in + *-aix* | *-freebsd* | *-darwin*) flag="-D_THREAD_SAFE";; + *solaris* | *-osf* | *-hpux*) flag="-D_REENTRANT";; + esac + AC_MSG_RESULT(${flag}) + if test "x$flag" != xno; then + PTHREAD_CFLAGS="$flag $PTHREAD_CFLAGS" + fi + + LIBS="$save_LIBS" + CFLAGS="$save_CFLAGS" + + # More AIX lossage: must compile with xlc_r or cc_r + if test x"$GCC" != xyes; then + AC_CHECK_PROGS(PTHREAD_CC, xlc_r cc_r, ${CC}) + else + PTHREAD_CC=$CC + fi +else + PTHREAD_CC="$CC" +fi + +AC_SUBST(PTHREAD_LIBS) +AC_SUBST(PTHREAD_CFLAGS) +AC_SUBST(PTHREAD_CC) + +# Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND: +if test x"$acx_pthread_ok" = xyes; then + ifelse([$1],,AC_DEFINE(HAVE_PTHREAD,1,[Define if you have POSIX threads libraries and header files.]),[$1]) + : +else + acx_pthread_ok=no + $2 +fi +AC_LANG_POP([]) +])dnl ACX_PTHREAD diff --git a/m4/byteorder.m4 b/m4/byteorder.m4 index 7dd1a41d..7d2c99ba 100644 --- a/m4/byteorder.m4 +++ b/m4/byteorder.m4 @@ -38,4 +38,3 @@ if (htonl(5) != 5) { ]) ]) -DETECT_BYTEORDER diff --git a/m4/debug.m4 b/m4/debug.m4 deleted file mode 100644 index 9b177810..00000000 --- a/m4/debug.m4 +++ /dev/null @@ -1,20 +0,0 @@ -dnl --------------------------------------------------------------------------- -dnl Macro: DEBUG_TEST -dnl --------------------------------------------------------------------------- -AC_ARG_ENABLE(debug, - [ --enable-debug Build with support for the DEBUG.], - [ - AC_DEFINE([HAVE_DEBUG], [1], [Enables DEBUG Support]) - AC_CHECK_PROGS(DEBUG, debug) - ENABLE_DEBUG="yes" - AC_SUBST(DEBUGFLAGS) - AC_SUBST(HAVE_DEBUG) - ], - [ - ENABLE_DEBUG="no" - ] - ) -AM_CONDITIONAL([HAVE_DEBUG], [ test "$ENABLE_DEBUG" = "yes" ]) -dnl --------------------------------------------------------------------------- -dnl End Macro: DEBUG_TEST -dnl --------------------------------------------------------------------------- diff --git a/m4/enable_utillib.m4 b/m4/enable_utillib.m4 new file mode 100644 index 00000000..d77922d3 --- /dev/null +++ b/m4/enable_utillib.m4 @@ -0,0 +1,16 @@ +AC_DEFUN([ENABLE_UTILLIB],[ + AC_ARG_ENABLE([utils], + [AS_HELP_STRING([--disable-utils], + [Disable libmemcachedutils @<:@default=on@:>@])], + [BUILD_UTILLIB="$enableval"], + [BUILD_UTILLIB="yes"]) + + if test "x$BUILD_UTILLIB" = "xyes"; then + if test x"$acx_pthread_ok" != "xyes"; then + AC_MSG_ERROR([Sorry you need POSIX thread library to build libmemcachedutil.]) + fi + AC_DEFINE([HAVE_LIBMEMCACHEDUTIL], [1], [Enables libmemcachedutil Support]) + fi + + AM_CONDITIONAL([BUILD_LIBMEMCACHEDUTIL],[test "x$BUILD_UTILLIB" = "xyes"]) +]) diff --git a/m4/extensions.m4 b/m4/extensions.m4 index 611fcfdb..2824fa09 100644 --- a/m4/extensions.m4 +++ b/m4/extensions.m4 @@ -20,7 +20,7 @@ # AC_DEFINE. The goal here is to define all known feature-enabling # macros, then, if reports of conflicts are made, disable macros that # cause problems on some platforms (such as __EXTENSIONS__). -AC_DEFUN([AC_USE_SYSTEM_EXTENSIONS], +AC_DEFUN([ACX_USE_SYSTEM_EXTENSIONS], [AC_BEFORE([$0], [AC_COMPILE_IFELSE])dnl AC_BEFORE([$0], [AC_RUN_IFELSE])dnl diff --git a/m4/util.m4 b/m4/util.m4 deleted file mode 100644 index e1fc17b4..00000000 --- a/m4/util.m4 +++ /dev/null @@ -1,20 +0,0 @@ -BUILD_UTILLIB=yes - -AC_ARG_ENABLE(utils, - [ --enable-utils Build libmemcachedutils [[default=yes]]], - [ - if test "x$enableval" = "xno"; then - BUILD_UTILLIB="no" - fi - ] - ) - -if test "x$BUILD_UTILLIB" = "xyes"; then - AC_SEARCH_LIBS(pthread_create, pthread) - if test "x$ac_cv_search_pthread_create" = "xno"; then - AC_MSG_ERROR([Sorry you need POSIX thread library to build libmemcachedutil.]) - fi - AC_DEFINE([HAVE_LIBMEMCACHEDUTIL], [1], [Enables libmemcachedutil Support]) -fi - -AM_CONDITIONAL([BUILD_LIBMEMCACHEDUTIL],[test "x$BUILD_UTILLIB" = "xyes"]) diff --git a/tests/function.c b/tests/function.c index 99ad776a..2262f1b2 100644 --- a/tests/function.c +++ b/tests/function.c @@ -200,64 +200,64 @@ static test_return clone_test(memcached_st *memc) { /* All null? */ { - memcached_st *clone; - clone= memcached_clone(NULL, NULL); - assert(clone); - memcached_free(clone); + memcached_st *memc_clone; + memc_clone= memcached_clone(NULL, NULL); + assert(memc_clone); + memcached_free(memc_clone); } /* Can we init from null? */ { - memcached_st *clone; - clone= memcached_clone(NULL, memc); - assert(clone); - - assert(clone->call_free == memc->call_free); - assert(clone->call_malloc == memc->call_malloc); - assert(clone->call_realloc == memc->call_realloc); - assert(clone->call_calloc == memc->call_calloc); - assert(clone->connect_timeout == memc->connect_timeout); - assert(clone->delete_trigger == memc->delete_trigger); - assert(clone->distribution == memc->distribution); - assert(clone->flags == memc->flags); - assert(clone->get_key_failure == memc->get_key_failure); - assert(clone->hash == memc->hash); - assert(clone->hash_continuum == memc->hash_continuum); - assert(clone->io_bytes_watermark == memc->io_bytes_watermark); - assert(clone->io_msg_watermark == memc->io_msg_watermark); - assert(clone->io_key_prefetch == memc->io_key_prefetch); - assert(clone->on_cleanup == memc->on_cleanup); - assert(clone->on_clone == memc->on_clone); - assert(clone->poll_timeout == memc->poll_timeout); - assert(clone->rcv_timeout == memc->rcv_timeout); - assert(clone->recv_size == memc->recv_size); - assert(clone->retry_timeout == memc->retry_timeout); - assert(clone->send_size == memc->send_size); - assert(clone->server_failure_limit == memc->server_failure_limit); - assert(clone->snd_timeout == memc->snd_timeout); - assert(clone->user_data == memc->user_data); - - memcached_free(clone); + memcached_st *memc_clone; + memc_clone= memcached_clone(NULL, memc); + assert(memc_clone); + + assert(memc_clone->call_free == memc->call_free); + assert(memc_clone->call_malloc == memc->call_malloc); + assert(memc_clone->call_realloc == memc->call_realloc); + assert(memc_clone->call_calloc == memc->call_calloc); + assert(memc_clone->connect_timeout == memc->connect_timeout); + assert(memc_clone->delete_trigger == memc->delete_trigger); + assert(memc_clone->distribution == memc->distribution); + assert(memc_clone->flags == memc->flags); + assert(memc_clone->get_key_failure == memc->get_key_failure); + assert(memc_clone->hash == memc->hash); + assert(memc_clone->hash_continuum == memc->hash_continuum); + assert(memc_clone->io_bytes_watermark == memc->io_bytes_watermark); + assert(memc_clone->io_msg_watermark == memc->io_msg_watermark); + assert(memc_clone->io_key_prefetch == memc->io_key_prefetch); + assert(memc_clone->on_cleanup == memc->on_cleanup); + assert(memc_clone->on_clone == memc->on_clone); + assert(memc_clone->poll_timeout == memc->poll_timeout); + assert(memc_clone->rcv_timeout == memc->rcv_timeout); + assert(memc_clone->recv_size == memc->recv_size); + assert(memc_clone->retry_timeout == memc->retry_timeout); + assert(memc_clone->send_size == memc->send_size); + assert(memc_clone->server_failure_limit == memc->server_failure_limit); + assert(memc_clone->snd_timeout == memc->snd_timeout); + assert(memc_clone->user_data == memc->user_data); + + memcached_free(memc_clone); } /* Can we init from struct? */ { memcached_st declared_clone; - memcached_st *clone; + memcached_st *memc_clone; memset(&declared_clone, 0 , sizeof(memcached_st)); - clone= memcached_clone(&declared_clone, NULL); - assert(clone); - memcached_free(clone); + memc_clone= memcached_clone(&declared_clone, NULL); + assert(memc_clone); + memcached_free(memc_clone); } /* Can we init from struct? */ { memcached_st declared_clone; - memcached_st *clone; + memcached_st *memc_clone; memset(&declared_clone, 0 , sizeof(memcached_st)); - clone= memcached_clone(&declared_clone, memc); - assert(clone); - memcached_free(clone); + memc_clone= memcached_clone(&declared_clone, memc); + assert(memc_clone); + memcached_free(memc_clone); } return 0; @@ -265,7 +265,7 @@ static test_return clone_test(memcached_st *memc) static test_return userdata_test(memcached_st *memc) { - void* foo; + void* foo= NULL; assert(memcached_set_user_data(memc, foo) == NULL); assert(memcached_get_user_data(memc) == foo); assert(memcached_set_user_data(memc, NULL) == foo); @@ -657,29 +657,29 @@ static test_return bad_key_test(memcached_st *memc) char *string; size_t string_length; uint32_t flags; - memcached_st *clone; + memcached_st *memc_clone; unsigned int set= 1; size_t max_keylen= 0xffff; - clone= memcached_clone(NULL, memc); - assert(clone); + memc_clone= memcached_clone(NULL, memc); + assert(memc_clone); - rc= memcached_behavior_set(clone, MEMCACHED_BEHAVIOR_VERIFY_KEY, set); + rc= memcached_behavior_set(memc_clone, MEMCACHED_BEHAVIOR_VERIFY_KEY, set); assert(rc == MEMCACHED_SUCCESS); /* All keys are valid in the binary protocol (except for length) */ - if (memcached_behavior_get(clone, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL) == 0) + if (memcached_behavior_get(memc_clone, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL) == 0) { - string= memcached_get(clone, key, strlen(key), + string= memcached_get(memc_clone, key, strlen(key), &string_length, &flags, &rc); assert(rc == MEMCACHED_BAD_KEY_PROVIDED); assert(string_length == 0); assert(!string); set= 0; - rc= memcached_behavior_set(clone, MEMCACHED_BEHAVIOR_VERIFY_KEY, set); + rc= memcached_behavior_set(memc_clone, MEMCACHED_BEHAVIOR_VERIFY_KEY, set); assert(rc == MEMCACHED_SUCCESS); - string= memcached_get(clone, key, strlen(key), + string= memcached_get(memc_clone, key, strlen(key), &string_length, &flags, &rc); assert(rc == MEMCACHED_NOTFOUND); assert(string_length == 0); @@ -689,13 +689,13 @@ static test_return bad_key_test(memcached_st *memc) char *keys[] = { "GoodKey", "Bad Key", "NotMine" }; size_t key_lengths[] = { 7, 7, 7 }; set= 1; - rc= memcached_behavior_set(clone, MEMCACHED_BEHAVIOR_VERIFY_KEY, set); + rc= memcached_behavior_set(memc_clone, MEMCACHED_BEHAVIOR_VERIFY_KEY, set); assert(rc == MEMCACHED_SUCCESS); - rc= memcached_mget(clone, keys, key_lengths, 3); + rc= memcached_mget(memc_clone, keys, key_lengths, 3); assert(rc == MEMCACHED_BAD_KEY_PROVIDED); - rc= memcached_mget_by_key(clone, "foo daddy", 9, keys, key_lengths, 1); + rc= memcached_mget_by_key(memc_clone, "foo daddy", 9, keys, key_lengths, 1); assert(rc == MEMCACHED_BAD_KEY_PROVIDED); max_keylen= 250; @@ -704,20 +704,20 @@ static test_return bad_key_test(memcached_st *memc) memcached server is updated to allow max size length of the keys in the binary protocol */ - rc= memcached_callback_set(clone, MEMCACHED_CALLBACK_PREFIX_KEY, NULL); + rc= memcached_callback_set(memc_clone, MEMCACHED_CALLBACK_PREFIX_KEY, NULL); assert(rc == MEMCACHED_SUCCESS); char *longkey= malloc(max_keylen + 1); if (longkey != NULL) { memset(longkey, 'a', max_keylen + 1); - string= memcached_get(clone, longkey, max_keylen, + string= memcached_get(memc_clone, longkey, max_keylen, &string_length, &flags, &rc); assert(rc == MEMCACHED_NOTFOUND); assert(string_length == 0); assert(!string); - string= memcached_get(clone, longkey, max_keylen + 1, + string= memcached_get(memc_clone, longkey, max_keylen + 1, &string_length, &flags, &rc); assert(rc == MEMCACHED_BAD_KEY_PROVIDED); assert(string_length == 0); @@ -729,15 +729,15 @@ static test_return bad_key_test(memcached_st *memc) /* Make sure zero length keys are marked as bad */ set= 1; - rc= memcached_behavior_set(clone, MEMCACHED_BEHAVIOR_VERIFY_KEY, set); + rc= memcached_behavior_set(memc_clone, MEMCACHED_BEHAVIOR_VERIFY_KEY, set); assert(rc == MEMCACHED_SUCCESS); - string= memcached_get(clone, key, 0, + string= memcached_get(memc_clone, key, 0, &string_length, &flags, &rc); assert(rc == MEMCACHED_BAD_KEY_PROVIDED); assert(string_length == 0); assert(!string); - memcached_free(clone); + memcached_free(memc_clone); return 0; } @@ -1035,8 +1035,8 @@ static test_return get_test5(memcached_st *memc) static test_return stats_servername_test(memcached_st *memc) { memcached_return rc; - memcached_stat_st stat; - rc= memcached_stat_servername(&stat, NULL, + memcached_stat_st memc_stat; + rc= memcached_stat_servername(&memc_stat, NULL, memc->hosts[0].hostname, memc->hosts[0].port); @@ -1366,10 +1366,10 @@ static test_return get_stats_keys(memcached_st *memc) { char **list; char **ptr; - memcached_stat_st stat; + memcached_stat_st memc_stat; memcached_return rc; - list= memcached_stat_get_keys(memc, &stat, &rc); + list= memcached_stat_get_keys(memc, &memc_stat, &rc); assert(rc == MEMCACHED_SUCCESS); for (ptr= list; *ptr; ptr++) assert(*ptr); @@ -1397,24 +1397,24 @@ static test_return get_stats(memcached_st *memc) char **list; char **ptr; memcached_return rc; - memcached_stat_st *stat; + memcached_stat_st *memc_stat; - stat= memcached_stat(memc, NULL, &rc); + memc_stat= memcached_stat(memc, NULL, &rc); assert(rc == MEMCACHED_SUCCESS); assert(rc == MEMCACHED_SUCCESS); - assert(stat); + assert(memc_stat); for (x= 0; x < memcached_server_count(memc); x++) { - list= memcached_stat_get_keys(memc, stat+x, &rc); + list= memcached_stat_get_keys(memc, memc_stat+x, &rc); assert(rc == MEMCACHED_SUCCESS); for (ptr= list; *ptr; ptr++); free(list); } - memcached_stat_free(NULL, stat); + memcached_stat_free(NULL, memc_stat); return 0; } @@ -1451,7 +1451,7 @@ static test_return add_host_test(memcached_st *memc) return 0; } -static memcached_return clone_test_callback(memcached_st *parent __attribute__((unused)), memcached_st *clone __attribute__((unused))) +static memcached_return clone_test_callback(memcached_st *parent __attribute__((unused)), memcached_st *memc_clone __attribute__((unused))) { return MEMCACHED_SUCCESS; } @@ -1910,7 +1910,7 @@ static test_return user_supplied_bug8(memcached_st *memc __attribute__((unused) { memcached_return rc; memcached_st *mine; - memcached_st *clone; + memcached_st *memc_clone; memcached_server_st *servers; char *server_list= "memcache1.memcache.bk.sapo.pt:11211, memcache1.memcache.bk.sapo.pt:11212, memcache1.memcache.bk.sapo.pt:11213, memcache1.memcache.bk.sapo.pt:11214, memcache2.memcache.bk.sapo.pt:11211, memcache2.memcache.bk.sapo.pt:11212, memcache2.memcache.bk.sapo.pt:11213, memcache2.memcache.bk.sapo.pt:11214"; @@ -1924,14 +1924,14 @@ static test_return user_supplied_bug8(memcached_st *memc __attribute__((unused) memcached_server_list_free(servers); assert(mine); - clone= memcached_clone(NULL, mine); + memc_clone= memcached_clone(NULL, mine); memcached_quit(mine); - memcached_quit(clone); + memcached_quit(memc_clone); memcached_free(mine); - memcached_free(clone); + memcached_free(memc_clone); return 0; } @@ -2709,12 +2709,12 @@ static test_return get_read_count(memcached_st *memc) { unsigned int x; memcached_return rc; - memcached_st *clone; + memcached_st *memc_clone; - clone= memcached_clone(NULL, memc); - assert(clone); + memc_clone= memcached_clone(NULL, memc); + assert(memc_clone); - memcached_server_add_with_weight(clone, "localhost", 6666, 0); + memcached_server_add_with_weight(memc_clone, "localhost", 6666, 0); { char *return_value; @@ -2724,7 +2724,7 @@ static test_return get_read_count(memcached_st *memc) for (x= count= 0; x < global_count; x++) { - return_value= memcached_get(clone, global_keys[x], global_keys_length[x], + return_value= memcached_get(memc_clone, global_keys[x], global_keys_length[x], &return_value_length, &flags, &rc); if (rc == MEMCACHED_SUCCESS) { @@ -2736,7 +2736,7 @@ static test_return get_read_count(memcached_st *memc) fprintf(stderr, "\t%u -> %u", global_count, count); } - memcached_free(clone); + memcached_free(memc_clone); return 0; } @@ -2904,15 +2904,15 @@ static memcached_return pre_nonblock(memcached_st *memc) static memcached_return pre_nonblock_binary(memcached_st *memc) { memcached_return rc= MEMCACHED_FAILURE; - memcached_st *clone; + memcached_st *memc_clone; - clone= memcached_clone(NULL, memc); - assert(clone); + memc_clone= memcached_clone(NULL, memc); + assert(memc_clone); // The memcached_version needs to be done on a clone, because the server // will not toggle protocol on an connection. - memcached_version(clone); + memcached_version(memc_clone); - if (clone->hosts[0].major_version >= 1 && clone->hosts[0].minor_version > 2) + if (memc_clone->hosts[0].major_version >= 1 && memc_clone->hosts[0].minor_version > 2) { memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NO_BLOCK, 0); rc = memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL, 1); @@ -2920,7 +2920,7 @@ static memcached_return pre_nonblock_binary(memcached_st *memc) assert(memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL) == 1); } - memcached_free(clone); + memcached_free(memc_clone); return rc; } @@ -3028,22 +3028,22 @@ static memcached_return pre_behavior_ketama_weighted(memcached_st *memc) static memcached_return pre_binary(memcached_st *memc) { memcached_return rc= MEMCACHED_FAILURE; - memcached_st *clone; + memcached_st *memc_clone; - clone= memcached_clone(NULL, memc); - assert(clone); + memc_clone= memcached_clone(NULL, memc); + assert(memc_clone); // The memcached_version needs to be done on a clone, because the server // will not toggle protocol on an connection. - memcached_version(clone); + memcached_version(memc_clone); - if (clone->hosts[0].major_version >= 1 && clone->hosts[0].minor_version > 2) + if (memc_clone->hosts[0].major_version >= 1 && memc_clone->hosts[0].minor_version > 2) { rc = memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL, 1); assert(rc == MEMCACHED_SUCCESS); assert(memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL) == 1); } - memcached_free(clone); + memcached_free(memc_clone); return rc; } @@ -3338,6 +3338,9 @@ static test_return noreply_test(memcached_st *memc) case 4: ret=memcached_prepend(memc, key, len, key, len, 0, 0); break; + default: + assert(count); + break; } assert(ret == MEMCACHED_SUCCESS || ret == MEMCACHED_BUFFERED); } @@ -3380,6 +3383,9 @@ static test_return noreply_test(memcached_st *memc) case 4: assert(length == len * 3); break; + default: + assert(count); + break; } free(value); } @@ -3425,19 +3431,19 @@ static test_return noreply_test(memcached_st *memc) static test_return analyzer_test(memcached_st *memc) { memcached_return rc; - memcached_stat_st *stat; + memcached_stat_st *memc_stat; memcached_analysis_st *report; - stat= memcached_stat(memc, NULL, &rc); + memc_stat= memcached_stat(memc, NULL, &rc); assert(rc == MEMCACHED_SUCCESS); - assert(stat); + assert(memc_stat); - report= memcached_analyze(memc, stat, &rc); + report= memcached_analyze(memc, memc_stat, &rc); assert(rc == MEMCACHED_SUCCESS); assert(report); free(report); - memcached_stat_free(NULL, stat); + memcached_stat_free(NULL, memc_stat); return TEST_SUCCESS; } diff --git a/tests/test.c b/tests/test.c index 49ae022a..a5371fee 100644 --- a/tests/test.c +++ b/tests/test.c @@ -99,7 +99,6 @@ int main(int argc, char *argv[]) if (next->pre) { - memcached_return rc; rc= next->pre(memc); if (rc != MEMCACHED_SUCCESS) -- 2.30.2