From: Brian Aker Date: Fri, 18 Dec 2009 02:37:31 +0000 (-0800) Subject: ICC cleanups X-Git-Tag: 0.37~58 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=98c99981e0ebe7f716bea2e4d95434d159103fcd;p=m6w6%2Flibmemcached ICC cleanups --- diff --git a/clients/memcp.c b/clients/memcp.c index d9594d78..617057b3 100644 --- a/clients/memcp.c +++ b/clients/memcp.c @@ -32,7 +32,7 @@ #define PROGRAM_DESCRIPTION "Copy a set of files to a memcached cluster." /* Prototypes */ -void options_parse(int argc, char *argv[]); +static void options_parse(int argc, char *argv[]); static int opt_binary=0; static int opt_verbose= 0; @@ -76,7 +76,7 @@ int main(int argc, char *argv[]) memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL, (uint64_t)opt_binary); - while (optind < argc) + while (optind < argc) { struct stat sbuf; int fd; @@ -100,7 +100,7 @@ int main(int argc, char *argv[]) else ptr= argv[optind]; - if (opt_verbose) + if (opt_verbose) { static const char *opstr[] = { "set", "add", "replace" }; printf("op: %s\nsource file: %s\nlength: %zu\n" @@ -111,13 +111,13 @@ int main(int argc, char *argv[]) if ((file_buffer_ptr= (char *)malloc(sizeof(char) * (size_t)sbuf.st_size)) == NULL) { - fprintf(stderr, "malloc: %s\n", strerror(errno)); + fprintf(stderr, "malloc: %s\n", strerror(errno)); exit(1); } if ((read_length= read(fd, file_buffer_ptr, (size_t)sbuf.st_size)) == -1) { - fprintf(stderr, "read: %s\n", strerror(errno)); + fprintf(stderr, "read: %s\n", strerror(errno)); exit(1); } @@ -142,7 +142,7 @@ int main(int argc, char *argv[]) if (rc != MEMCACHED_SUCCESS) { - fprintf(stderr, "memcp: %s: memcache error %s", + fprintf(stderr, "memcp: %s: memcache error %s", ptr, memcached_strerror(memc, rc)); if (memc->cached_errno) fprintf(stderr, " system error %s", strerror(memc->cached_errno)); @@ -164,7 +164,7 @@ int main(int argc, char *argv[]) return 0; } -void options_parse(int argc, char *argv[]) +static void options_parse(int argc, char *argv[]) { int option_index= 0; int option_rv; @@ -191,7 +191,7 @@ void options_parse(int argc, char *argv[]) {0, 0, 0, 0}, }; - while (1) + while (1) { option_rv= getopt_long(argc, argv, "Vhvds:", long_options, &option_index); diff --git a/clients/memdump.c b/clients/memdump.c index 582939fa..4329c1bd 100644 --- a/clients/memdump.c +++ b/clients/memdump.c @@ -32,7 +32,7 @@ #define PROGRAM_DESCRIPTION "Dump all values from one or many servers." /* Prototypes */ -void options_parse(int argc, char *argv[]); +static void options_parse(int argc, char *argv[]); static int opt_binary=0; static int opt_verbose= 0; @@ -40,8 +40,8 @@ static char *opt_servers= NULL; static char *opt_hash= NULL; /* Print the keys and counter how many were found */ -static memcached_return_t key_printer(memcached_st *ptr __attribute__((unused)), - const char *key, size_t key_length, +static memcached_return_t key_printer(memcached_st *ptr __attribute__((unused)), + const char *key, size_t key_length, void *context __attribute__((unused))) { printf("%.*s\n", (uint32_t)key_length, key); @@ -106,7 +106,7 @@ int main(int argc, char *argv[]) return 0; } -void options_parse(int argc, char *argv[]) +static void options_parse(int argc, char *argv[]) { int option_index= 0; int option_rv; @@ -123,7 +123,7 @@ void options_parse(int argc, char *argv[]) {0, 0, 0, 0} }; - while (1) + while (1) { option_rv= getopt_long(argc, argv, "Vhvds:", long_options, &option_index); diff --git a/clients/memrm.c b/clients/memrm.c index e7525fd5..0f6ad453 100644 --- a/clients/memrm.c +++ b/clients/memrm.c @@ -28,7 +28,7 @@ static char *opt_hash= NULL; #define PROGRAM_DESCRIPTION "Erase a key or set of keys from a memcached cluster." /* Prototypes */ -void options_parse(int argc, char *argv[]); +static void options_parse(int argc, char *argv[]); int main(int argc, char *argv[]) { @@ -59,16 +59,16 @@ int main(int argc, char *argv[]) memcached_server_list_free(servers); memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL, (uint64_t) opt_binary); - - while (optind < argc) + + while (optind < argc) { - if (opt_verbose) + if (opt_verbose) printf("key: %s\nexpires: %llu\n", argv[optind], (unsigned long long)opt_expire); rc = memcached_delete(memc, argv[optind], strlen(argv[optind]), opt_expire); - if (rc != MEMCACHED_SUCCESS) + if (rc != MEMCACHED_SUCCESS) { - fprintf(stderr, "memrm: %s: memcache error %s", + fprintf(stderr, "memrm: %s: memcache error %s", argv[optind], memcached_strerror(memc, rc)); if (memc->cached_errno) fprintf(stderr, " system error %s", strerror(memc->cached_errno)); @@ -89,7 +89,7 @@ int main(int argc, char *argv[]) } -void options_parse(int argc, char *argv[]) +static void options_parse(int argc, char *argv[]) { memcached_programs_help_st help_options[]= { @@ -111,7 +111,7 @@ void options_parse(int argc, char *argv[]) int option_index= 0; int option_rv; - while (1) + while (1) { option_rv= getopt_long(argc, argv, "Vhvds:", long_options, &option_index); if (option_rv == -1) break; diff --git a/clients/memslap.c b/clients/memslap.c index d08b4d9b..ac35e9d2 100644 --- a/clients/memslap.c +++ b/clients/memslap.c @@ -13,6 +13,7 @@ * Mingqiang Zhuang * */ +#include #include #include diff --git a/libmemcached/analyze.c b/libmemcached/analyze.c index 5c1c7e47..79ea17b9 100644 --- a/libmemcached/analyze.c +++ b/libmemcached/analyze.c @@ -67,7 +67,7 @@ memcached_analysis_st *memcached_analyze(memcached_st *memc, uint64_t total_get_cmds= 0, total_get_hits= 0; uint32_t server_count, x; memcached_analysis_st *result; - + *error= MEMCACHED_SUCCESS; server_count= memcached_server_count(memc); result= (memcached_analysis_st*)calloc(memc->number_of_hosts, @@ -84,7 +84,7 @@ memcached_analysis_st *memcached_analyze(memcached_st *memc, 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].limit_maxbytes, memc_stat[x].bytes); total_get_hits+= memc_stat[x].get_hits; diff --git a/libmemcached/hosts.c b/libmemcached/hosts.c index 27a86a7b..e0224222 100644 --- a/libmemcached/hosts.c +++ b/libmemcached/hosts.c @@ -6,7 +6,7 @@ static memcached_return_t server_add(memcached_st *ptr, const char *hostname, in_port_t port, uint32_t weight, memcached_connection_t type); -memcached_return_t update_continuum(memcached_st *ptr); +static memcached_return_t update_continuum(memcached_st *ptr); static int compare_servers(const void *p1, const void *p2) { @@ -106,7 +106,7 @@ static int continuum_item_cmp(const void *t1, const void *t2) return -1; } -memcached_return_t update_continuum(memcached_st *ptr) +static memcached_return_t update_continuum(memcached_st *ptr) { uint32_t host_index; uint32_t continuum_index= 0; @@ -256,16 +256,17 @@ memcached_return_t update_continuum(memcached_st *ptr) if (list[host_index].port == MEMCACHED_DEFAULT_PORT) { sort_host_length= (size_t) snprintf(sort_host, MEMCACHED_MAX_HOST_SORT_LENGTH, - "%s-%d", + "%s-%u", list[host_index].hostname, pointer_index - 1); } else { sort_host_length= (size_t) snprintf(sort_host, MEMCACHED_MAX_HOST_SORT_LENGTH, - "%s:%d-%d", + "%s:%u-%u", list[host_index].hostname, - list[host_index].port, pointer_index - 1); + (uint32_t)list[host_index].port, + pointer_index - 1); } WATCHPOINT_ASSERT(sort_host_length); diff --git a/libmemcached/memcached.c b/libmemcached/memcached.c index 2fa4f42c..329e170d 100644 --- a/libmemcached/memcached.c +++ b/libmemcached/memcached.c @@ -5,8 +5,6 @@ memcached_st *memcached_create(memcached_st *ptr) { - memcached_result_st *result_ptr; - if (ptr == NULL) { ptr= (memcached_st *)calloc(1, sizeof(memcached_st)); @@ -27,8 +25,11 @@ memcached_st *memcached_create(memcached_st *ptr) memcached_set_memory_allocators(ptr, NULL, NULL, NULL, NULL); - result_ptr= memcached_result_create(ptr, &ptr->result); - WATCHPOINT_ASSERT(result_ptr); + if (! memcached_result_create(ptr, &ptr->result)) + { + memcached_free(ptr); + return NULL; + } ptr->poll_timeout= MEMCACHED_DEFAULT_TIMEOUT; ptr->connect_timeout= MEMCACHED_DEFAULT_TIMEOUT; ptr->retry_timeout= 0; diff --git a/libmemcached/memcached.h b/libmemcached/memcached.h index ddde6952..47968139 100644 --- a/libmemcached/memcached.h +++ b/libmemcached/memcached.h @@ -173,14 +173,14 @@ memcached_return_t memcached_decrement(memcached_st *ptr, uint64_t *value); LIBMEMCACHED_API -memcached_return_t memcached_increment_by_key(memcached_st *ptr, +memcached_return_t memcached_increment_by_key(memcached_st *ptr, const char *master_key, size_t master_key_length, const char *key, size_t key_length, uint64_t offset, uint64_t *value); LIBMEMCACHED_API -memcached_return_t memcached_decrement_by_key(memcached_st *ptr, +memcached_return_t memcached_decrement_by_key(memcached_st *ptr, const char *master_key, size_t master_key_length, const char *key, size_t key_length, uint64_t offset, @@ -258,28 +258,28 @@ memcached_return_t memcached_flush_buffers(memcached_st *mem); LIBMEMCACHED_API memcached_return_t memcached_server_add_udp(memcached_st *ptr, - const char *hostname, - in_port_t port); + const char *hostname, + in_port_t port); LIBMEMCACHED_API memcached_return_t memcached_server_add_unix_socket(memcached_st *ptr, - const char *filename); + const char *filename); LIBMEMCACHED_API -memcached_return_t memcached_server_add(memcached_st *ptr, +memcached_return_t memcached_server_add(memcached_st *ptr, const char *hostname, in_port_t port); LIBMEMCACHED_API memcached_return_t memcached_server_add_udp_with_weight(memcached_st *ptr, - const char *hostname, - in_port_t port, - uint32_t weight); + const char *hostname, + in_port_t port, + uint32_t weight); LIBMEMCACHED_API memcached_return_t memcached_server_add_unix_socket_with_weight(memcached_st *ptr, - const char *filename, - uint32_t weight); + const char *filename, + uint32_t weight); LIBMEMCACHED_API memcached_return_t memcached_server_add_with_weight(memcached_st *ptr, const char *hostname, - in_port_t port, - uint32_t weight); + in_port_t port, + uint32_t weight); LIBMEMCACHED_API void memcached_server_list_free(memcached_server_st *ptr); diff --git a/libmemcached/quit.c b/libmemcached/quit.c index 3c117ade..4abadb94 100644 --- a/libmemcached/quit.c +++ b/libmemcached/quit.c @@ -27,9 +27,12 @@ void memcached_quit_server(memcached_server_st *ptr, uint8_t io_death) rc= memcached_do(ptr, request.bytes, sizeof(request.bytes), 1); } else + { rc= memcached_do(ptr, "quit\r\n", 6, 1); + } WATCHPOINT_ASSERT(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_FETCH_NOTFINISHED); + (void)rc; // Shut up ICC /* read until socket is closed, or there is an error * closing the socket before all data is read diff --git a/libmemcached/response.c b/libmemcached/response.c index a87ac249..4c37c051 100644 --- a/libmemcached/response.c +++ b/libmemcached/response.c @@ -317,18 +317,6 @@ static memcached_return_t textual_read_one_response(memcached_server_st *ptr, /* NOTREACHED */ } -char *memcached_result_value(memcached_result_st *ptr) -{ - memcached_string_st *sptr= &ptr->value; - return memcached_string_value(sptr); -} - -size_t memcached_result_length(memcached_result_st *ptr) -{ - memcached_string_st *sptr= &ptr->value; - return memcached_string_length(sptr); -} - static memcached_return_t binary_read_one_response(memcached_server_st *ptr, char *buffer, size_t buffer_length, memcached_result_st *result) diff --git a/libmemcached/result.c b/libmemcached/result.c index b9052a19..03cd4fc3 100644 --- a/libmemcached/result.c +++ b/libmemcached/result.c @@ -86,3 +86,17 @@ void memcached_result_free(memcached_result_st *ptr) ptr->options.is_initialized= false; } } + + +char *memcached_result_value(memcached_result_st *ptr) +{ + memcached_string_st *sptr= &ptr->value; + return memcached_string_value(sptr); +} + +size_t memcached_result_length(memcached_result_st *ptr) +{ + memcached_string_st *sptr= &ptr->value; + return memcached_string_length(sptr); +} + diff --git a/libmemcached/result.h b/libmemcached/result.h index 2602fce3..c685984a 100644 --- a/libmemcached/result.h +++ b/libmemcached/result.h @@ -46,10 +46,13 @@ memcached_result_st *memcached_result_create(memcached_st *ptr, #define memcached_result_value(A) memcached_string_value((A)->value) #define memcached_result_length(A) memcached_string_length((A)->value) #else + LIBMEMCACHED_API char *memcached_result_value(memcached_result_st *ptr); + LIBMEMCACHED_API size_t memcached_result_length(memcached_result_st *ptr); + #endif #define memcached_result_flags(A) (A)->flags #define memcached_result_cas(A) (A)->cas diff --git a/libmemcached/string.c b/libmemcached/string.c index 846a3316..615d54f7 100644 --- a/libmemcached/string.c +++ b/libmemcached/string.c @@ -83,7 +83,7 @@ memcached_string_st *memcached_string_create(memcached_st *memc, memcached_strin } memcached_return_t memcached_string_append_character(memcached_string_st *string, - char character) + char character) { memcached_return_t rc; @@ -99,7 +99,7 @@ memcached_return_t memcached_string_append_character(memcached_string_st *string } memcached_return_t memcached_string_append(memcached_string_st *string, - const char *value, size_t length) + const char *value, size_t length) { memcached_return_t rc; diff --git a/tests/function.c b/tests/function.c index 9332ebd7..a580f396 100644 --- a/tests/function.c +++ b/tests/function.c @@ -800,16 +800,16 @@ static test_return_t bad_key_test(memcached_st *memc) } #define READ_THROUGH_VALUE "set for me" -static memcached_return_t read_through_trigger(memcached_st *memc __attribute__((unused)), - char *key __attribute__((unused)), - size_t key_length __attribute__((unused)), - memcached_result_st *result) +static memcached_return_t read_through_trigger(memcached_st *memc __attribute__((unused)), + char *key __attribute__((unused)), + size_t key_length __attribute__((unused)), + memcached_result_st *result) { return memcached_result_set_value(result, READ_THROUGH_VALUE, strlen(READ_THROUGH_VALUE)); } -static test_return_t read_through(memcached_st *memc) +static test_return_t read_through(memcached_st *memc) { memcached_return_t rc; const char *key= "foo"; @@ -822,8 +822,8 @@ static test_return_t read_through(memcached_st *memc) &string_length, &flags, &rc); test_truth(rc == MEMCACHED_NOTFOUND); - test_truth(string_length == 0); - test_truth(!string); + test_false(string_length); + test_false(string); rc= memcached_callback_set(memc, MEMCACHED_CALLBACK_GET_FAILURE, *(void **)&cb); @@ -834,7 +834,7 @@ static test_return_t read_through(memcached_st *memc) test_truth(rc == MEMCACHED_SUCCESS); test_truth(string_length == strlen(READ_THROUGH_VALUE)); - test_truth(!strcmp(READ_THROUGH_VALUE, string)); + test_strcmp(READ_THROUGH_VALUE, string); free(string); string= memcached_get(memc, key, strlen(key), @@ -885,8 +885,8 @@ static test_return_t get_test(memcached_st *memc) &string_length, &flags, &rc); test_truth(rc == MEMCACHED_NOTFOUND); - test_truth(string_length == 0); - test_truth(!string); + test_false(string_length); + test_false(string); return TEST_SUCCESS; } @@ -1158,8 +1158,8 @@ static test_return_t stats_servername_test(memcached_st *memc) memcached_return_t rc; memcached_stat_st memc_stat; rc= memcached_stat_servername(&memc_stat, NULL, - memc->hosts[0].hostname, - memc->hosts[0].port); + memc->hosts[0].hostname, + memc->hosts[0].port); return TEST_SUCCESS; } @@ -1664,7 +1664,6 @@ static test_return_t get_stats_keys(memcached_st *memc) test_truth(rc == MEMCACHED_SUCCESS); for (ptr= stat_list; *ptr; ptr++) test_truth(*ptr); - fflush(stdout); free(stat_list);