From 8fa220229fdb895f6f07311124e9c71943fdbad4 Mon Sep 17 00:00:00 2001 From: Brian Aker Date: Fri, 22 Jan 2010 11:04:16 -0800 Subject: [PATCH] Modified Hashkit class (turned it into an actual class). --- libhashkit/hashkit.c | 9 --- libhashkit/hashkit.h | 24 +++--- libhashkit/types.h | 2 - libmemcached/memcached.h | 162 ++++++++++++--------------------------- m4/pandora_warnings.m4 | 2 +- tests/hash_plus.cc | 1 + tests/include.am | 24 +++++- 7 files changed, 79 insertions(+), 145 deletions(-) diff --git a/libhashkit/hashkit.c b/libhashkit/hashkit.c index c58ab69f..47c9e580 100644 --- a/libhashkit/hashkit.c +++ b/libhashkit/hashkit.c @@ -106,12 +106,3 @@ bool hashkit_compare(const hashkit_st *first, const hashkit_st *second) return false; } - -#ifdef __cplusplus -hashkit_st operator=(const hashkit_st& source) -{ - hashkit_clone(this, &source); - - return *this; -} -#endif diff --git a/libhashkit/hashkit.h b/libhashkit/hashkit.h index 5f19f9d3..bab3bc08 100644 --- a/libhashkit/hashkit.h +++ b/libhashkit/hashkit.h @@ -63,28 +63,24 @@ struct hashkit_st struct { bool is_allocated:1; } options; +}; #ifdef __cplusplus +class Hashkit : private hashkit_st { + +public: - hashkit_st() : - base_hash(), - distribution_hash(), - flags(), - options() + Hashkit() { hashkit_create(this); } - hashkit_st(const hashkit_st& source) : - base_hash(), - distribution_hash(), - flags(), - options() + Hashkit(const Hashkit& source) { hashkit_clone(this, &source); } - hashkit_st& operator=(const hashkit_st& source) + Hashkit& operator=(const Hashkit& source) { hashkit_free(this); hashkit_clone(this, &source); @@ -92,7 +88,7 @@ struct hashkit_st return *this; } - friend bool operator==(const hashkit_st &left, const hashkit_st &right) + friend bool operator==(const Hashkit &left, const Hashkit &right) { return hashkit_compare(&left, &right); } @@ -117,12 +113,12 @@ struct hashkit_st return hashkit_set_function(this, hash_algorithm); } - ~hashkit_st() + ~Hashkit() { hashkit_free(this); } -#endif }; +#endif #endif /* HASHKIT_H */ diff --git a/libhashkit/types.h b/libhashkit/types.h index 6b7e29b2..8d396962 100644 --- a/libhashkit/types.h +++ b/libhashkit/types.h @@ -12,8 +12,6 @@ #ifdef __cplusplus -typedef struct hashkit_st Hashkit; - extern "C" { #endif diff --git a/libmemcached/memcached.h b/libmemcached/memcached.h index 5b92d635..66f8a495 100644 --- a/libmemcached/memcached.h +++ b/libmemcached/memcached.h @@ -52,33 +52,6 @@ #include #include -#ifdef __cplusplus -extern "C" { -#endif - -LIBMEMCACHED_API -void memcached_servers_reset(memcached_st *ptr); - -LIBMEMCACHED_API -memcached_st *memcached_create(memcached_st *ptr); - -LIBMEMCACHED_API -void memcached_free(memcached_st *ptr); - -LIBMEMCACHED_API -memcached_st *memcached_clone(memcached_st *clone, const memcached_st *ptr); - -LIBMEMCACHED_API -void *memcached_get_user_data(const memcached_st *ptr); - -LIBMEMCACHED_API -void *memcached_set_user_data(memcached_st *ptr, void *data); - -#ifdef __cplusplus -} // extern "C" -#endif - - struct memcached_st { /** @note these are static and should not change without a call to behavior. @@ -151,110 +124,69 @@ struct memcached_st { bool is_allocated:1; } options; +}; + #ifdef __cplusplus - memcached_st() : - state(), - flags(), - distribution(), - hashkit(), - continuum_points_counter(), - number_of_hosts(), - servers(), - last_disconnected_server(), - snd_timeout(), - rcv_timeout(), - server_failure_limit(), - io_msg_watermark(), - io_bytes_watermark(), - io_key_prefetch(), - cached_errno(), - poll_timeout(), - connect_timeout(), - retry_timeout(), - continuum_count(), - send_size(), - recv_size(), - user_data(), - next_distribution_rebuild(), - prefix_key_length(), - number_of_replicas(), - distribution_hashkit(), - result(), - continuum(), - allocators(), - on_clone(), - on_cleanup(), - get_key_failure(), - delete_trigger(), - callbacks(), - prefix_key(), - options() +extern "C" { +#endif + +LIBMEMCACHED_API +void memcached_servers_reset(memcached_st *ptr); + +LIBMEMCACHED_API +memcached_st *memcached_create(memcached_st *ptr); + +LIBMEMCACHED_API +void memcached_free(memcached_st *ptr); + +LIBMEMCACHED_API +memcached_st *memcached_clone(memcached_st *clone, const memcached_st *ptr); + +LIBMEMCACHED_API +void *memcached_get_user_data(const memcached_st *ptr); + +LIBMEMCACHED_API +void *memcached_set_user_data(memcached_st *ptr, void *data); + +#ifdef __cplusplus +} // extern "C" +#endif + + +// Local Only Inline +static inline memcached_server_st *memcached_server_instance_fetch(memcached_st *ptr, uint32_t server_key) +{ + return &ptr->servers[server_key]; +} + +#ifdef __cplusplus +class Memcached : private memcached_st { +public: + + Memcached() { memcached_create(this); } - ~memcached_st() + ~Memcached() { memcached_free(this); } - memcached_st(const memcached_st& source) : - state(), - flags(), - distribution(), - hashkit(), - continuum_points_counter(), - number_of_hosts(), - servers(), - last_disconnected_server(), - snd_timeout(), - rcv_timeout(), - server_failure_limit(), - io_msg_watermark(), - io_bytes_watermark(), - io_key_prefetch(), - cached_errno(), - poll_timeout(), - connect_timeout(), - retry_timeout(), - continuum_count(), - send_size(), - recv_size(), - user_data(), - next_distribution_rebuild(), - prefix_key_length(), - number_of_replicas(), - distribution_hashkit(), - result(), - continuum(), - allocators(), - on_clone(), - on_cleanup(), - get_key_failure(), - delete_trigger(), - callbacks(), - prefix_key(), - options() - { - memcached_clone(this, &source); - } + Memcached(const Memcached& source) + { + memcached_clone(this, &source); + } - memcached_st& operator=(const memcached_st& source) + Memcached& operator=(const Memcached& source) { memcached_free(this); memcached_clone(this, &source); return *this; } - -#endif }; - - -// Local Only Inline -static inline memcached_server_st *memcached_server_instance_fetch(memcached_st *ptr, uint32_t server_key) -{ - return &ptr->servers[server_key]; -} +#endif #endif /* __LIBMEMCACHED_MEMCACHED_H__ */ + diff --git a/m4/pandora_warnings.m4 b/m4/pandora_warnings.m4 index eb0f7b4c..2044cc91 100644 --- a/m4/pandora_warnings.m4 +++ b/m4/pandora_warnings.m4 @@ -145,7 +145,7 @@ uint16_t x= htons(80); m4_if(PW_LESS_WARNINGS,[no],[ BASE_WARNINGS_FULL="-Wformat=2 ${W_CONVERSION} -Wstrict-aliasing" CC_WARNINGS_FULL="-Wswitch-default -Wswitch-enum -Wwrite-strings" - CXX_WARNINGS_FULL="-Weffc++ -Wold-style-cast" + CXX_WARNINGS_FULL="-Wold-style-cast" ],[ BASE_WARNINGS_FULL="-Wformat ${NO_STRICT_ALIASING}" ]) diff --git a/tests/hash_plus.cc b/tests/hash_plus.cc index 30e14106..1d0b9e83 100644 --- a/tests/hash_plus.cc +++ b/tests/hash_plus.cc @@ -14,6 +14,7 @@ static test_return_t exists_test(void *obj) { Hashkit hashk; (void)obj; + (void)hashk; return TEST_SUCCESS; } diff --git a/tests/include.am b/tests/include.am index 73b88342..64041535 100644 --- a/tests/include.am +++ b/tests/include.am @@ -37,6 +37,7 @@ noinst_HEADERS+= \ noinst_PROGRAMS+= \ tests/atomsmasher \ tests/hashplus \ + tests/memplus \ tests/startservers \ tests/testapp \ tests/testhashkit \ @@ -82,6 +83,10 @@ tests_hashplus_SOURCES = tests/hash_plus.cc tests_hashplus_LDADD = $(tests_testhashkit_LDADD) tests_hashplus_DEPENDENCIES = $(tests_testhashkit_LDADD) +tests_memplus_SOURCES = tests/mem_plus.cc +tests_memplus_LDADD = tests/libtest.la tests/libserver.la libmemcached/libmemcached.la +tests_memplus_DEPENDENCIES = $(tests_memplus_LDADD) + test: test-docs test-mem test-hash memcapable echo "Tests completed" @@ -204,7 +209,9 @@ MEMSLAP_COMMAND= clients/memslap $(COLLECTION) $(SUITE) MEM_COMMAND= tests/testapp $(COLLECTION) $(SUITE) -MEMPLUS_COMMAND= tests/testplus $(COLLECTION) $(SUITE) +TESTPLUS_COMMAND= tests/testplus $(COLLECTION) $(SUITE) + +MEMPLUS_COMMAND= tests/memplus $(COLLECTION) $(SUITE) HASHPLUS_COMMAND= tests/hashplus $(COLLECTION) $(SUITE) @@ -219,7 +226,7 @@ test-atom: tests/atomsmasher $(ATOM_COMMAND) test-plus: tests/testplus - $(MEMPLUS_COMMAND) + $(TESTPLUS_COMMAND) test-hash: tests/testhashkit $(HASH_COMMAND) @@ -227,6 +234,9 @@ test-hash: tests/testhashkit test-hashplus: tests/hashplus $(HASHPLUS_COMMAND) +test-memplus: tests/memplus + $(MEMPLUS_COMMAND) + pahole-mem: tests/testapp $(PAHOLE_COMMAND) $(MEM_COMMAND) @@ -237,7 +247,7 @@ gdb-atom: tests/atomsmasher $(DEBUG_COMMAND) $(ATOM_COMMAND) gdb-plus: tests/testplus - $(DEBUG_COMMAND) $(MEMPLUS_COMMAND) + $(DEBUG_COMMAND) $(TESTPLUS_COMMAND) gdb-hash: tests/testhashkit $(DEBUG_COMMAND) $(HASH_COMMAND) @@ -245,6 +255,9 @@ gdb-hash: tests/testhashkit gdb-hashplus: tests/hashplus $(DEBUG_COMMAND) $(HASHPLUS_COMMAND) +gdb-memplus: tests/memplus + $(DEBUG_COMMAND) $(MEMPLUS_COMMAND) + gdb-memslap: clients/memslap $(DEBUG_COMMAND) $(MEMSLAP_COMMAND) @@ -255,7 +268,7 @@ valgrind-atom: tests/atomsmasher $(VALGRIND_COMMAND) $(ATOM_COMMAND) valgrind-plus: tests/testplus - $(VALGRIND_COMMAND) $(MEMPLUS_COMMAND) + $(VALGRIND_COMMAND) $(TESTPLUS_COMMAND) valgrind-hash: tests/testhashkit $(VALGRIND_COMMAND) $(HASH_COMMAND) @@ -263,6 +276,9 @@ valgrind-hash: tests/testhashkit valgrind-hashplus: tests/hashplus $(VALGRIND_COMMAND) $(HASHPLUS_COMMAND) +valgrind-memplus: tests/memplus + $(VALGRIND_COMMAND) $(MEMPLUS_COMMAND) + valgrind-memslap: clients/memslap $(VALGRIND_COMMAND) $(MEMSLAP_COMMAND) -- 2.30.2