From: Monty Taylor Date: Wed, 13 May 2009 09:53:59 +0000 (+0200) Subject: Turned on more warnings, and fixed the errors. Moved common.h, which includes X-Git-Tag: 0.29~1 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=a07bb255b72aa59d0f4c4c63bb71695b2e9df537;p=m6w6%2Flibmemcached Turned on more warnings, and fixed the errors. Moved common.h, which includes the config.h file to being included first in impl files, so that includes of things like stdlib.h can take advantage of autoconf produce defines. --- diff --git a/Makefile.am b/Makefile.am index c5693638..95382924 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,3 +1,4 @@ +ACLOCAL_AMFLAGS = -I config INCLUDES = SUBDIRS = docs libmemcached libmemcachedutil tests support clients EXTRA_dist = README.FIRST diff --git a/clients/execute.c b/clients/execute.c index e623825c..490662d3 100644 --- a/clients/execute.c +++ b/clients/execute.c @@ -3,7 +3,8 @@ Return the number of rows set. */ -#include +#include "libmemcached/common.h" + #include "execute.h" unsigned int execute_set(memcached_st *memc, pairs_st *pairs, unsigned int number_of) diff --git a/clients/generator.c b/clients/generator.c index c9750231..8000910e 100644 --- a/clients/generator.c +++ b/clients/generator.c @@ -1,3 +1,5 @@ +#include "libmemcached/common.h" + #include #include #include diff --git a/clients/memcat.c b/clients/memcat.c index 36e63622..5f5f2cda 100644 --- a/clients/memcat.c +++ b/clients/memcat.c @@ -1,3 +1,4 @@ +#include "libmemcached/common.h" #include #include #include diff --git a/clients/memcp.c b/clients/memcp.c index 0a7809f8..1762b601 100644 --- a/clients/memcp.c +++ b/clients/memcp.c @@ -1,3 +1,4 @@ +#include "libmemcached/common.h" #include #include #include diff --git a/clients/memerror.c b/clients/memerror.c index 5654c212..b70f8830 100644 --- a/clients/memerror.c +++ b/clients/memerror.c @@ -1,3 +1,4 @@ +#include "libmemcached/common.h" #include #include #include diff --git a/clients/memflush.c b/clients/memflush.c index 5208e5cd..abd19ce4 100644 --- a/clients/memflush.c +++ b/clients/memflush.c @@ -1,3 +1,4 @@ +#include "libmemcached/common.h" #include #include #include diff --git a/clients/memrm.c b/clients/memrm.c index 1570945e..c4ef1bda 100644 --- a/clients/memrm.c +++ b/clients/memrm.c @@ -1,3 +1,4 @@ +#include "libmemcached/common.h" #include #include #include diff --git a/clients/memslap.c b/clients/memslap.c index d42c06ae..d85642f8 100644 --- a/clients/memslap.c +++ b/clients/memslap.c @@ -1,3 +1,4 @@ +#include "libmemcached/common.h" #include #include #include diff --git a/clients/memstat.c b/clients/memstat.c index b3cc5851..f3ac9fe1 100644 --- a/clients/memstat.c +++ b/clients/memstat.c @@ -1,3 +1,4 @@ +#include "libmemcached/common.h" #include #include #include diff --git a/clients/utilities.c b/clients/utilities.c index 529955ce..b9795246 100644 --- a/clients/utilities.c +++ b/clients/utilities.c @@ -1,3 +1,4 @@ +#include "libmemcached/common.h" #include #include #include diff --git a/config/extensions.m4 b/config/extensions.m4 new file mode 100644 index 00000000..611fcfdb --- /dev/null +++ b/config/extensions.m4 @@ -0,0 +1,94 @@ +# serial 6 -*- Autoconf -*- +# Enable extensions on systems that normally disable them. + +# Copyright (C) 2003, 2006-2008 Free Software Foundation, Inc. +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This definition of AC_USE_SYSTEM_EXTENSIONS is stolen from CVS +# Autoconf. Perhaps we can remove this once we can assume Autoconf +# 2.62 or later everywhere, but since CVS Autoconf mutates rapidly +# enough in this area it's likely we'll need to redefine +# AC_USE_SYSTEM_EXTENSIONS for quite some time. + +# AC_USE_SYSTEM_EXTENSIONS +# ------------------------ +# Enable extensions on systems that normally disable them, +# typically due to standards-conformance issues. +# Remember that #undef in AH_VERBATIM gets replaced with #define by +# 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_BEFORE([$0], [AC_COMPILE_IFELSE])dnl +AC_BEFORE([$0], [AC_RUN_IFELSE])dnl + + AC_REQUIRE([AC_CANONICAL_HOST]) + + AC_CHECK_HEADER([minix/config.h], [MINIX=yes], [MINIX=]) + if test "$MINIX" = yes; then + AC_DEFINE([_POSIX_SOURCE], [1], + [Define to 1 if you need to in order for `stat' and other + things to work.]) + AC_DEFINE([_POSIX_1_SOURCE], [2], + [Define to 2 if the system does not provide POSIX.1 features + except with this defined.]) + AC_DEFINE([_MINIX], [1], + [Define to 1 if on MINIX.]) + fi + + dnl HP-UX 11.11 defines mbstate_t only if _XOPEN_SOURCE is defined to 500, + dnl regardless of whether the flags -Ae or _D_HPUX_SOURCE=1 are already + dnl provided. + case "$host_os" in + hpux*) + AC_DEFINE([_XOPEN_SOURCE], [500], + [Define to 500 only on HP-UX.]) + ;; + esac + + AH_VERBATIM([__EXTENSIONS__], +[/* Enable extensions on AIX 3, Interix. */ +#ifndef _ALL_SOURCE +# undef _ALL_SOURCE +#endif +/* Enable GNU extensions on systems that have them. */ +#ifndef _GNU_SOURCE +# undef _GNU_SOURCE +#endif +/* Enable threading extensions on Solaris. */ +#ifndef _POSIX_PTHREAD_SEMANTICS +# undef _POSIX_PTHREAD_SEMANTICS +#endif +/* Enable extensions on HP NonStop. */ +#ifndef _TANDEM_SOURCE +# undef _TANDEM_SOURCE +#endif +/* Enable general extensions on Solaris. */ +#ifndef __EXTENSIONS__ +# undef __EXTENSIONS__ +#endif +]) + AC_CACHE_CHECK([whether it is safe to define __EXTENSIONS__], + [ac_cv_safe_to_define___extensions__], + [AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM([[ +# define __EXTENSIONS__ 1 + ]AC_INCLUDES_DEFAULT])], + [ac_cv_safe_to_define___extensions__=yes], + [ac_cv_safe_to_define___extensions__=no])]) + test $ac_cv_safe_to_define___extensions__ = yes && + AC_DEFINE([__EXTENSIONS__]) + AC_DEFINE([_ALL_SOURCE]) + AC_DEFINE([_GNU_SOURCE]) + AC_DEFINE([_POSIX_PTHREAD_SEMANTICS]) + AC_DEFINE([_TANDEM_SOURCE]) +])# AC_USE_SYSTEM_EXTENSIONS + +# gl_USE_SYSTEM_EXTENSIONS +# ------------------------ +# Enable extensions on systems that normally disable them, +# typically due to standards-conformance issues. +AC_DEFUN([gl_USE_SYSTEM_EXTENSIONS], + [AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])]) diff --git a/configure.ac b/configure.ac index ea06419f..43154b86 100644 --- a/configure.ac +++ b/configure.ac @@ -50,6 +50,7 @@ AC_SUBST(MEMCACHED_VERSION) VERSION=$MEMCACHED_RELEASE AM_INIT_AUTOMAKE($PACKAG$, $VERSION, nostdinc no-define -Wall -Werror) +AC_USE_SYSTEM_EXTENSIONS AC_PROG_CC AC_PROG_CC_C99 @@ -67,6 +68,7 @@ AC_SEARCH_LIBS(socket, socket) AC_SEARCH_LIBS(gethostbyname, nsl) AC_SEARCH_LIBS(floorf, m) + sinclude(config/pod2man.m4) sinclude(config/debug.m4) sinclude(config/dtrace.m4) @@ -78,11 +80,26 @@ sinclude(config/setsockopt.m4) sinclude(config/hsieh.m4) sinclude(config/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" +then + building_from_hg=yes +else + building_from_hg=no +fi + # We only support GCC and Sun's forte at the moment if test "$GCC" = "yes" then - #CFLAGS="-W -std=iso9899:1999 -Wall -Wextra -Wstrict-aliasing -pedantic -Wundef -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls -O3 $CFLAGS" - CFLAGS="-W -Wall -Wextra -Wno-strict-aliasing -pedantic -Werror -O3 -ggdb $CFLAGS" + 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 -O3 -ggdb $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 -O3 -ggdb $CXXFLAGS" if test "$ENABLE_DEBUG" = "yes" then diff --git a/libmemcached/md5.c b/libmemcached/md5.c index ef43035a..6558d5c8 100644 --- a/libmemcached/md5.c +++ b/libmemcached/md5.c @@ -30,6 +30,8 @@ documentation and/or software. */ +#include "common.h" + #include #include diff --git a/libmemcached/memcached.hh b/libmemcached/memcached.hh index 479693a7..56879566 100644 --- a/libmemcached/memcached.hh +++ b/libmemcached/memcached.hh @@ -13,12 +13,12 @@ class Memcached public: - Memcached() + Memcached() : memc(), result() { memcached_create(&memc); } - Memcached(memcached_st *clone) + Memcached(memcached_st *clone) : memc(), result() { memcached_clone(&memc, clone); } @@ -61,7 +61,7 @@ public: { return memcached_set(&memc, key, strlen(key), value, value_length, - (time_t)0, (uint32_t)0); + time_t(0), uint32_t(0)); } memcached_return set_by_key(const char *master_key, const char *key, @@ -70,8 +70,8 @@ public: return memcached_set_by_key(&memc, master_key, strlen(master_key), key, strlen(key), value, value_length, - (time_t)0, - (uint32_t)0 ); + time_t(0), + uint32_t(0) ); } memcached_return increment(const char *key, unsigned int offset, uint64_t *value) @@ -89,9 +89,7 @@ public: 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); + return memcached_add(&memc, key, strlen(key), value, value_length, 0, 0); } memcached_return add_by_key(const char *master_key, const char *key, const char *value, size_t value_length) @@ -99,7 +97,7 @@ public: return memcached_add_by_key(&memc, master_key, strlen(master_key), key, strlen(key), value, value_length, - (time_t)0, (uint32_t)0); + 0, 0); } memcached_return replace(const char *key, const char *value, @@ -107,24 +105,21 @@ public: { return memcached_replace(&memc, key, strlen(key), value, value_length, - (time_t)0, (uint32_t)0); + 0, 0); } 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), - value, value_length, - (time_t)0, (uint32_t)0); + value, value_length, 0, 0); } 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); + value, value_length, 0, 0); } memcached_return prepend_by_key(const char *master_key, const char *key, const char *value, size_t value_length) @@ -132,17 +127,15 @@ public: return memcached_prepend_by_key(&memc, master_key, strlen(master_key), key, strlen(key), value, value_length, - (time_t)0, - (uint32_t)0); + 0, + 0); } 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); + value, value_length, 0, 0); } memcached_return append_by_key(const char *master_key, const char *key, const char *value, size_t value_length) @@ -150,18 +143,13 @@ public: return memcached_append_by_key(&memc, master_key, strlen(master_key), key, strlen(key), - value, value_length, - (time_t)0, - (uint32_t)0); + value, value_length, 0, 0); } 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, - (time_t)0, - (uint32_t)0, - cas); + value, value_length, 0, 0, cas); } memcached_return cas_by_key(const char *master_key, const char *key, const char *value, size_t value_length, @@ -171,20 +159,18 @@ public: master_key, strlen(master_key), key, strlen(key), value, value_length, - (time_t)0, - (uint32_t)0, - cas); + 0, 0, cas); } // using 'remove' vs. 'delete' since 'delete' is a keyword memcached_return remove(const char *key) { - return memcached_delete (&memc, key, strlen(key), (time_t)0); + return memcached_delete (&memc, key, strlen(key), 0); } 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); + key, strlen(key), 0); } ~Memcached() { diff --git a/tests/atomsmasher.c b/tests/atomsmasher.c index 08aa86f7..500e2e8e 100644 --- a/tests/atomsmasher.c +++ b/tests/atomsmasher.c @@ -1,6 +1,8 @@ /* Sample test application. */ +#include "libmemcached/common.h" + #include #include #include @@ -11,7 +13,6 @@ #include #include #include "server.h" -#include "../libmemcached/common.h" #include "../clients/generator.h" #include "../clients/execute.h" diff --git a/tests/function.c b/tests/function.c index f6bbf59c..cfa5f597 100644 --- a/tests/function.c +++ b/tests/function.c @@ -1,6 +1,8 @@ /* Sample test application. */ +#include "libmemcached/common.h" + #include #include #include @@ -11,8 +13,8 @@ #include #include #include "server.h" -#include "../clients/generator.h" -#include "../clients/execute.h" +#include "clients/generator.h" +#include "clients/execute.h" #ifndef INT64_MAX #define INT64_MAX LONG_MAX @@ -2311,7 +2313,7 @@ static test_return user_supplied_bug17(memcached_st *memc) From Andrei on IRC */ -test_return user_supplied_bug19(memcached_st *memc) +static test_return user_supplied_bug19(memcached_st *memc) { memcached_st *m; memcached_server_st *s; @@ -2332,7 +2334,7 @@ test_return user_supplied_bug19(memcached_st *memc) } /* CAS test from Andei */ -test_return user_supplied_bug20(memcached_st *memc) +static test_return user_supplied_bug20(memcached_st *memc) { memcached_return status; memcached_result_st *result, result_obj; @@ -2364,7 +2366,7 @@ test_return user_supplied_bug20(memcached_st *memc) } #include "ketama_test_cases.h" -test_return user_supplied_bug18(memcached_st *trash) +static test_return user_supplied_bug18(memcached_st *trash) { memcached_return rc; int value; @@ -2423,7 +2425,7 @@ test_return user_supplied_bug18(memcached_st *trash) return 0; } -test_return auto_eject_hosts(memcached_st *trash) +static test_return auto_eject_hosts(memcached_st *trash) { (void) trash; @@ -3615,7 +3617,7 @@ static test_return udp_set_too_big_test(memcached_st *memc) return post_udp_op_check(memc,expected_ids); } -test_return udp_delete_test(memcached_st *memc) +static test_return udp_delete_test(memcached_st *memc) { unsigned int x= 0; unsigned int num_iters= 1025; //request id rolls over at 1024 @@ -3648,7 +3650,7 @@ static test_return udp_buffered_delete_test(memcached_st *memc) return udp_delete_test(memc); } -test_return udp_verbosity_test(memcached_st *memc) +static test_return udp_verbosity_test(memcached_st *memc) { memcached_return rc; uint16_t *expected_ids= get_udp_request_ids(memc); @@ -3661,14 +3663,14 @@ test_return udp_verbosity_test(memcached_st *memc) return post_udp_op_check(memc,expected_ids); } -test_return udp_quit_test(memcached_st *memc) +static test_return udp_quit_test(memcached_st *memc) { uint16_t *expected_ids= get_udp_request_ids(memc); memcached_quit(memc); return post_udp_op_check(memc, expected_ids); } -test_return udp_flush_test(memcached_st *memc) +static test_return udp_flush_test(memcached_st *memc) { memcached_return rc; uint16_t *expected_ids= get_udp_request_ids(memc); @@ -3681,7 +3683,7 @@ test_return udp_flush_test(memcached_st *memc) return post_udp_op_check(memc,expected_ids); } -test_return udp_incr_test(memcached_st *memc) +static test_return udp_incr_test(memcached_st *memc) { memcached_return rc; char *key= "incr"; @@ -3700,7 +3702,7 @@ test_return udp_incr_test(memcached_st *memc) return post_udp_op_check(memc, expected_ids); } -test_return udp_decr_test(memcached_st *memc) +static test_return udp_decr_test(memcached_st *memc) { memcached_return rc; char *key= "decr"; @@ -3720,7 +3722,7 @@ test_return udp_decr_test(memcached_st *memc) } -test_return udp_stat_test(memcached_st *memc) +static test_return udp_stat_test(memcached_st *memc) { memcached_stat_st * rv= NULL; memcached_return rc; @@ -3732,7 +3734,7 @@ test_return udp_stat_test(memcached_st *memc) return post_udp_op_check(memc, expected_ids); } -test_return udp_version_test(memcached_st *memc) +static test_return udp_version_test(memcached_st *memc) { memcached_return rc; uint16_t *expected_ids = get_udp_request_ids(memc); @@ -3741,7 +3743,7 @@ test_return udp_version_test(memcached_st *memc) return post_udp_op_check(memc, expected_ids); } -test_return udp_get_test(memcached_st *memc) +static test_return udp_get_test(memcached_st *memc) { memcached_return rc; char *key= "foo"; @@ -3753,7 +3755,7 @@ test_return udp_get_test(memcached_st *memc) return post_udp_op_check(memc, expected_ids); } -test_return udp_mixed_io_test(memcached_st *memc) +static test_return udp_mixed_io_test(memcached_st *memc) { test_st current_op; test_st mixed_io_ops [] ={ @@ -3776,7 +3778,7 @@ test_return udp_mixed_io_test(memcached_st *memc) return TEST_SUCCESS; } -test_return hsieh_avaibility_test (memcached_st *memc) +static test_return hsieh_avaibility_test (memcached_st *memc) { memcached_return expected_rc= MEMCACHED_FAILURE; #ifdef HAVE_HSIEH_HASH diff --git a/tests/plus.cpp b/tests/plus.cpp index ec29b159..7bb2a293 100644 --- a/tests/plus.cpp +++ b/tests/plus.cpp @@ -15,7 +15,15 @@ #include "test.h" -extern "C" test_return basic_test(memcached_st *memc) +extern "C" { + test_return basic_test(memcached_st *memc); + uint8_t increment_test(memcached_st *memc); + test_return basic_master_key_test(memcached_st *memc); + void *world_create(void); + void world_destroy(void *p); +} + +test_return basic_test(memcached_st *memc) { Memcached foo(memc); const char *value_set= "This is some data"; @@ -30,7 +38,7 @@ extern "C" test_return basic_test(memcached_st *memc) return TEST_SUCCESS; } -extern "C" uint8_t increment_test(memcached_st *memc) +uint8_t increment_test(memcached_st *memc) { Memcached mcach(memc); memcached_return rc; @@ -63,7 +71,7 @@ extern "C" uint8_t increment_test(memcached_st *memc) return 0; } -extern "C" test_return basic_master_key_test(memcached_st *memc) +test_return basic_master_key_test(memcached_st *memc) { Memcached foo(memc); const char *value_set= "Data for server A"; @@ -111,10 +119,11 @@ extern "C" void *world_create(void) return construct; } -extern "C" void world_destroy(void *p) +void world_destroy(void *p) { - server_startup_st *construct= (server_startup_st *)p; - memcached_server_st *servers= (memcached_server_st *)construct->servers; + server_startup_st *construct= static_cast(p); + memcached_server_st *servers= + static_cast(construct->servers); memcached_server_list_free(servers); server_shutdown(construct); diff --git a/tests/server.c b/tests/server.c index d0942edf..2528787c 100644 --- a/tests/server.c +++ b/tests/server.c @@ -4,14 +4,16 @@ #define TEST_PORT_BASE MEMCACHED_DEFAULT_PORT+10 +#include "libmemcached/libmemcached_config.h" + #include #include #include #include #include +#include #include #include -#include "libmemcached/libmemcached_config.h" #include "server.h" void server_startup(server_startup_st *construct) @@ -38,6 +40,25 @@ void server_startup(server_startup_st *construct) int count; int status; + sprintf(buffer, "/tmp/%umemc.pid", x); + if (access(buffer, F_OK) == 0) + { + FILE *fp= fopen(buffer, "r"); + remove(buffer); + + if (fp != NULL) + { + if (fgets(buffer, sizeof(buffer), fp) != NULL) + { + pid_t pid = atol(buffer); + if (pid != 0) + kill(pid, SIGTERM); + } + + fclose(fp); + } + } + if (x == 0) { sprintf(buffer, "%s -d -P /tmp/%umemc.pid -t 1 -p %u -U %u -m 128", @@ -86,7 +107,6 @@ void server_shutdown(server_startup_st *construct) char buffer[1024]; /* Nothing special for number */ sprintf(buffer, "cat /tmp/%umemc.pid | xargs kill", x); system(buffer); - sprintf(buffer, "/tmp/%umemc.pid", x); unlink(buffer); }