From: Trond Norbye Date: Fri, 23 Jan 2009 10:43:14 +0000 (+0100) Subject: Source cleanup (remove compiler warnings ++) X-Git-Tag: 0.26~3 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=6dbe9f6cd35e445cf3122d80bd7814370ded2aa0;p=awesomized%2Flibmemcached Source cleanup (remove compiler warnings ++) Set warning == errors on Sun Studio compilers. Added const to the "C++" API to remove compiler warnings. Removed statements that couldn't be reached. --- diff --git a/configure.ac b/configure.ac index 928f45b1..57ce53ff 100644 --- a/configure.ac +++ b/configure.ac @@ -48,7 +48,13 @@ AC_PROG_LIBTOOL AM_SANITY_CHECK LIBTOOL="$LIBTOOL --preserve-dup-deps" AC_SUBST(LIBTOOL)dnl -AC_LANG_CPLUSPLUS + +AC_C_CONST +AC_HEADER_TIME +AC_TYPE_SIZE_T +AC_SEARCH_LIBS(getopt_long, gnugetopt) +AC_SEARCH_LIBS(socket, socket) +AC_SEARCH_LIBS(gethostbyname, nsl) sinclude(config/pod2man.m4) sinclude(config/debug.m4) @@ -57,6 +63,7 @@ sinclude(config/byteorder.m4) sinclude(config/64bit.m4) sinclude(config/protocol_binary.m4) sinclude(config/memcached.m4) +sinclude(config/setsockopt.m4) # We only support GCC and Sun's forte at the moment CFLAGS="-DMEMCACHED_INTERNAL $CFLAGS" @@ -70,22 +77,15 @@ then CFLAGS="$CFLAGS -ggdb -DHAVE_DEBUG" fi else - CFLAGS="-Xa -xstrconst -mt -D_FORTEC_ $CFLAGS" + CFLAGS="-Xa -xstrconst -mt -D_FORTEC_ -errfmt=error -errwarn -errshort=tags $CFLAGS" + CXXFLAGS="+w +w2 -xwe -mt -D_FORTEC_ $CXXFLAGS" if test "$ENABLE_DEBUG" = "yes" then CFLAGS="$CFLAGS -DHAVE_DEBUG" + CXXFLAGS="$CXXFLAGS -DHAVE_DEBUG" fi - DTRACEFLAGS="$DTRACEFLAGS" fi LDFLAGS="-lm" -AC_C_CONST -AC_HEADER_TIME -AC_TYPE_SIZE_T -AC_SEARCH_LIBS(getopt_long, gnugetopt) -AC_SEARCH_LIBS(socket, socket) -AC_SEARCH_LIBS(gethostbyname, nsl) - -sinclude(config/setsockopt.m4) AC_OUTPUT(Makefile clients/Makefile tests/Makefile docs/Makefile libmemcached/Makefile support/Makefile support/libmemcached.pc support/libmemcached.spec) diff --git a/libmemcached/memcached.hh b/libmemcached/memcached.hh index 3bbcaf0b..479693a7 100644 --- a/libmemcached/memcached.hh +++ b/libmemcached/memcached.hh @@ -30,7 +30,7 @@ public: return memcached_fetch(&memc, key, key_length, value_length, &flags, &rc); } - char *get(char *key, size_t *value_length) + char *get(const char *key, size_t *value_length) { uint32_t flags; memcached_return rc; @@ -39,29 +39,33 @@ public: value_length, &flags, &rc); } - char *get_by_key(char *master_key, char *key, size_t *value_length) + char *get_by_key(const char *master_key, const char *key, + size_t *value_length) { uint32_t flags; memcached_return rc; - return memcached_get_by_key(&memc, master_key, strlen(master_key), key, strlen(key), + return memcached_get_by_key(&memc, master_key, strlen(master_key), + key, strlen(key), value_length, &flags, &rc); } - memcached_return mget(char **keys, size_t *key_length, unsigned int number_of_keys) + memcached_return mget(char **keys, size_t *key_length, + unsigned int number_of_keys) { return memcached_mget(&memc, keys, key_length, number_of_keys); } - memcached_return set(char *key, char *value, size_t value_length) + memcached_return set(const char *key, const char *value, size_t value_length) { return memcached_set(&memc, key, strlen(key), value, value_length, (time_t)0, (uint32_t)0); } - memcached_return set_by_key(char *master_key, char *key, char *value, size_t value_length) + memcached_return set_by_key(const char *master_key, const char *key, + const char *value, size_t value_length) { return memcached_set_by_key(&memc, master_key, strlen(master_key), key, strlen(key), @@ -70,26 +74,27 @@ public: (uint32_t)0 ); } memcached_return - increment(char *key, unsigned int offset, uint64_t *value) + increment(const char *key, unsigned int offset, uint64_t *value) { return memcached_increment(&memc, key, strlen(key), offset, value); } memcached_return - decrement(char *key, unsigned int offset, uint64_t *value) + decrement(const char *key, unsigned int offset, uint64_t *value) { return memcached_decrement(&memc, key, strlen(key), offset, value); } - memcached_return add(char *key, char *value, size_t value_length) + memcached_return add(const char *key, const char *value, size_t value_length) { return memcached_add(&memc, key, strlen(key), value, value_length, (time_t)0, (uint32_t)0); } - memcached_return add_by_key(char *master_key, char *key, char *value, size_t value_length) + memcached_return add_by_key(const char *master_key, const char *key, + const char *value, size_t value_length) { return memcached_add_by_key(&memc, master_key, strlen(master_key), key, strlen(key), @@ -97,14 +102,15 @@ public: (time_t)0, (uint32_t)0); } - memcached_return replace(char *key, char *value, size_t value_length) + memcached_return replace(const char *key, const char *value, + size_t value_length) { return memcached_replace(&memc, key, strlen(key), value, value_length, (time_t)0, (uint32_t)0); } - memcached_return replace_by_key(char *master_key, - char *key, char *value, size_t value_length) + memcached_return replace_by_key(const char *master_key, const char *key, + const char *value, size_t value_length) { return memcached_replace_by_key(&memc, master_key, strlen(master_key), key, strlen(key), @@ -112,15 +118,16 @@ public: (time_t)0, (uint32_t)0); } - memcached_return prepend(char *key, char *value, size_t value_length) + memcached_return prepend(const char *key, const char *value, + size_t value_length) { return memcached_prepend(&memc, key, strlen(key), value, value_length, (time_t)0, (uint32_t)0); } - memcached_return prepend_by_key(char *master_key, - char *key, char *value, size_t value_length) + memcached_return prepend_by_key(const char *master_key, const char *key, + const char *value, size_t value_length) { return memcached_prepend_by_key(&memc, master_key, strlen(master_key), key, strlen(key), @@ -129,15 +136,16 @@ public: (uint32_t)0); } - memcached_return append(char *key, char *value, size_t value_length) + memcached_return append(const char *key, const char *value, + size_t value_length) { return memcached_append(&memc, key, strlen(key), value, value_length, (time_t)0, (uint32_t)0); } - memcached_return append_by_key(char *master_key, - char *key, char *value, size_t value_length) + memcached_return append_by_key(const char *master_key, const char *key, + const char *value, size_t value_length) { return memcached_append_by_key(&memc, master_key, strlen(master_key), @@ -146,7 +154,8 @@ public: (time_t)0, (uint32_t)0); } - memcached_return cas(char *key, char *value, size_t value_length, uint64_t cas) + memcached_return cas(const char *key, const char *value, + size_t value_length, uint64_t cas) { return memcached_cas(&memc, key, strlen(key), value, value_length, @@ -154,8 +163,9 @@ public: (uint32_t)0, cas); } - memcached_return cas_by_key(char *master_key, char *key, char *value, - size_t value_length, uint64_t cas) + memcached_return cas_by_key(const char *master_key, const char *key, + const char *value, size_t value_length, + uint64_t cas) { return memcached_cas_by_key(&memc, master_key, strlen(master_key), @@ -166,18 +176,18 @@ public: cas); } // using 'remove' vs. 'delete' since 'delete' is a keyword - memcached_return remove(char *key) + memcached_return remove(const char *key) { return memcached_delete (&memc, key, strlen(key), (time_t)0); } - memcached_return delete_by_key(char *master_key, char *key) + memcached_return delete_by_key(const char *master_key, const char *key) { return memcached_delete_by_key(&memc, master_key, strlen(master_key), key, strlen(key), (time_t)0); } - ~Memcached() - { - memcached_free(&memc); - } + ~Memcached() + { + memcached_free(&memc); + } }; diff --git a/libmemcached/memcached_behavior.c b/libmemcached/memcached_behavior.c index 3eca4eac..5a992b42 100644 --- a/libmemcached/memcached_behavior.c +++ b/libmemcached/memcached_behavior.c @@ -257,6 +257,4 @@ uint64_t memcached_behavior_get(memcached_st *ptr, return 1; else return 0; - - return MEMCACHED_SUCCESS; } diff --git a/libmemcached/memcached_hash.c b/libmemcached/memcached_hash.c index de0ce1dc..1f51ac25 100644 --- a/libmemcached/memcached_hash.c +++ b/libmemcached/memcached_hash.c @@ -145,8 +145,7 @@ static uint32_t dispatch_host(memcached_st *ptr, uint32_t hash) return hash % ptr->number_of_hosts; } - WATCHPOINT_ASSERT(0); /* We should never reach here */ - return 0; + /* NOTREACHED */ } /* diff --git a/libmemcached/memcached_parse.c b/libmemcached/memcached_parse.c index 8bb56f53..b81ccda1 100644 --- a/libmemcached/memcached_parse.c +++ b/libmemcached/memcached_parse.c @@ -13,8 +13,8 @@ memcached_server_st *memcached_servers_parse(const char *server_strings) char *string; unsigned int port; uint32_t weight; - char *begin_ptr; - char *end_ptr; + const char *begin_ptr; + const char *end_ptr; memcached_server_st *servers= NULL; memcached_return rc; diff --git a/libmemcached/memcached_response.c b/libmemcached/memcached_response.c index 08e664f6..e9ff94ac 100644 --- a/libmemcached/memcached_response.c +++ b/libmemcached/memcached_response.c @@ -156,7 +156,7 @@ static memcached_return textual_read_one_response(memcached_server_st *ptr, } } - return MEMCACHED_SUCCESS; + /* NOTREACHED */ } char *memcached_result_value(memcached_result_st *ptr) diff --git a/libmemcached/memcached_storage.c b/libmemcached/memcached_storage.c index f3c63300..111d0ea7 100644 --- a/libmemcached/memcached_storage.c +++ b/libmemcached/memcached_storage.c @@ -39,7 +39,7 @@ static char *storage_op_string(memcached_storage_action verb) return "tosserror"; /* This is impossible, fixes issue for compiler warning in VisualStudio */ }; - return SET_OP; + /* NOTREACHED */ } static memcached_return memcached_send_binary(memcached_server_st* server, diff --git a/tests/function.c b/tests/function.c index 42547870..35d1c5a6 100644 --- a/tests/function.c +++ b/tests/function.c @@ -3089,7 +3089,7 @@ static test_return noreply_test(memcached_st *memc) return TEST_SUCCESS; } -static memcached_return analyzer_test(memcached_st *memc) +static test_return analyzer_test(memcached_st *memc) { memcached_return rc; memcached_stat_st *stat; @@ -3106,7 +3106,7 @@ static memcached_return analyzer_test(memcached_st *memc) free(report); memcached_stat_free(NULL, stat); - return MEMCACHED_SUCCESS; + return TEST_SUCCESS; } /* Clean the server before beginning testing */ diff --git a/tests/plus.cpp b/tests/plus.cpp index ab9cdbe6..ec29b159 100644 --- a/tests/plus.cpp +++ b/tests/plus.cpp @@ -15,10 +15,10 @@ #include "test.h" -test_return basic_test(memcached_st *memc) +extern "C" test_return basic_test(memcached_st *memc) { - Memcached foo; - char *value_set= "This is some data"; + Memcached foo(memc); + const char *value_set= "This is some data"; char *value; size_t value_length; @@ -30,12 +30,12 @@ test_return basic_test(memcached_st *memc) return TEST_SUCCESS; } -uint8_t increment_test(memcached_st *memc) +extern "C" uint8_t increment_test(memcached_st *memc) { - Memcached mcach; + Memcached mcach(memc); memcached_return rc; - char *key= "inctest"; - char *inc_value= "1"; + const char *key= "inctest"; + const char *inc_value= "1"; char *ret_value; uint64_t int_inc_value; uint64_t int_ret_value; @@ -63,13 +63,13 @@ uint8_t increment_test(memcached_st *memc) return 0; } -test_return basic_master_key_test(memcached_st *memc) +extern "C" test_return basic_master_key_test(memcached_st *memc) { - Memcached foo; - char *value_set= "Data for server A"; - char *master_key_a= "server-a"; - char *master_key_b= "server-b"; - char *key= "xyz"; + Memcached foo(memc); + const char *value_set= "Data for server A"; + const char *master_key_a= "server-a"; + const char *master_key_b= "server-b"; + const char *key= "xyz"; char *value; size_t value_length; @@ -98,10 +98,8 @@ collection_st collection[] ={ #define SERVERS_TO_CREATE 1 -void *world_create(void) +extern "C" void *world_create(void) { - unsigned int x; - memcached_server_st *servers; server_startup_st *construct; construct= (server_startup_st *)malloc(sizeof(server_startup_st)); @@ -113,7 +111,7 @@ void *world_create(void) return construct; } -void world_destroy(void *p) +extern "C" void world_destroy(void *p) { server_startup_st *construct= (server_startup_st *)p; memcached_server_st *servers= (memcached_server_st *)construct->servers; diff --git a/tests/test.h b/tests/test.h index 77adaf53..63b75ef0 100644 --- a/tests/test.h +++ b/tests/test.h @@ -3,8 +3,8 @@ */ #ifdef __cplusplus extern "C" { - #endif + #include #include "../libmemcached/common.h" @@ -20,13 +20,13 @@ typedef enum { } test_return; struct test_st { - char *name; + const char *name; unsigned int requires_flush; test_return (*function)(memcached_st *memc); }; struct collection_st { - char *name; + const char *name; memcached_return (*pre)(memcached_st *memc); memcached_return (*post)(memcached_st *memc); test_st *tests;