From 7e0ffed050b62cc5dcf5d16c148185074bfd7d50 Mon Sep 17 00:00:00 2001 From: Trond Norbye Date: Wed, 11 Mar 2009 21:06:43 +0100 Subject: [PATCH] Fix coding style violations --- clients/memslap.c | 6 ++-- libmemcached/byteorder.c | 6 ++-- libmemcached/hsieh_hash.c | 9 +++-- libmemcached/jenkins_hash.c | 11 +++++-- libmemcached/memcached_connect.c | 6 ++-- libmemcached/memcached_get.c | 3 +- libmemcached/memcached_quit.c | 3 +- libmemcached/memcached_response.c | 3 +- libmemcached/memcached_storage.c | 6 ++-- tests/atomsmasher.c | 3 +- tests/function.c | 55 +++++++++++++++++-------------- tests/server.c | 7 ++-- 12 files changed, 72 insertions(+), 46 deletions(-) diff --git a/clients/memslap.c b/clients/memslap.c index cd170eb1..d42c06ae 100644 --- a/clients/memslap.c +++ b/clients/memslap.c @@ -145,9 +145,9 @@ 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 i= 0; - for(i= 0; i < servers[0].count; i++ ) - servers[i].type= MEMCACHED_CONNECTION_UDP; + unsigned int x= 0; + for(x= 0; x < servers[0].count; x++ ) + servers[x].type= MEMCACHED_CONNECTION_UDP; } memcached_server_push(memc, servers); diff --git a/libmemcached/byteorder.c b/libmemcached/byteorder.c index c020785b..28889aae 100644 --- a/libmemcached/byteorder.c +++ b/libmemcached/byteorder.c @@ -20,10 +20,12 @@ static inline uint64_t swap64(uint64_t in) #endif } -uint64_t ntohll(uint64_t value) { +uint64_t ntohll(uint64_t value) +{ return swap64(value); } -uint64_t htonll(uint64_t value) { +uint64_t htonll(uint64_t value) +{ return swap64(value); } diff --git a/libmemcached/hsieh_hash.c b/libmemcached/hsieh_hash.c index e6c23cd9..91d515f2 100644 --- a/libmemcached/hsieh_hash.c +++ b/libmemcached/hsieh_hash.c @@ -22,13 +22,15 @@ uint32_t hsieh_hash(const char *key, size_t key_length) uint32_t hash = 0, tmp; int rem; - if (key_length <= 0 || key == NULL) return 0; + if (key_length <= 0 || key == NULL) + return 0; rem = key_length & 3; key_length >>= 2; /* Main loop */ - for (;key_length > 0; key_length--) { + for (;key_length > 0; key_length--) + { hash += get16bits (key); tmp = (get16bits (key+2) << 11) ^ hash; hash = (hash << 16) ^ tmp; @@ -37,7 +39,8 @@ uint32_t hsieh_hash(const char *key, size_t key_length) } /* Handle end cases */ - switch (rem) { + switch (rem) + { case 3: hash += get16bits (key); hash ^= hash << 16; hash ^= key[sizeof (uint16_t)] << 18; diff --git a/libmemcached/jenkins_hash.c b/libmemcached/jenkins_hash.c index 940e4718..409a4054 100644 --- a/libmemcached/jenkins_hash.c +++ b/libmemcached/jenkins_hash.c @@ -63,7 +63,8 @@ uint32_t jenkins_hash(const void *key, size_t length, uint32_t initval) a = b = c = 0xdeadbeef + ((uint32_t)length) + initval; u.ptr = key; - if ((u.i & 0x3) == 0) { + if ((u.i & 0x3) == 0) + { const uint32_t *k = (const uint32_t *)key; /* read 32-bit chunks */ /*------ all but last block: aligned reads and affect 32 bits of (a,b,c) */ @@ -104,7 +105,9 @@ uint32_t jenkins_hash(const void *key, size_t length, uint32_t initval) case 0 : return c; /* zero length strings require no mixing */ } - } else if ((u.i & 0x1) == 0) { + } + else if ((u.i & 0x1) == 0) + { const uint16_t *k = (const uint16_t *)key; /* read 16-bit chunks */ const uint8_t *k8; @@ -151,7 +154,9 @@ uint32_t jenkins_hash(const void *key, size_t length, uint32_t initval) case 0 : return c; /* zero length requires no mixing */ } - } else { /* need to read the key one byte at a time */ + } + else + { /* need to read the key one byte at a time */ const uint8_t *k = (const uint8_t *)key; /*--------------- all but the last block: affect some 32 bits of (a,b,c) */ diff --git a/libmemcached/memcached_connect.c b/libmemcached/memcached_connect.c index f066c526..aca8ffd0 100644 --- a/libmemcached/memcached_connect.c +++ b/libmemcached/memcached_connect.c @@ -159,7 +159,8 @@ test_connect: (struct sockaddr *)&servAddr, sizeof(servAddr)) < 0) { - switch (errno) { + switch (errno) + { case EINPROGRESS: case EALREADY: case EINTR: @@ -209,7 +210,8 @@ static memcached_return network_connect(memcached_server_st *ptr) while (use != NULL) { /* Memcache server does not support IPV6 in udp mode, so skip if not ipv4 */ - if (ptr->type == MEMCACHED_CONNECTION_UDP && use->ai_family != AF_INET) { + if (ptr->type == MEMCACHED_CONNECTION_UDP && use->ai_family != AF_INET) + { use= use->ai_next; continue; } diff --git a/libmemcached/memcached_get.c b/libmemcached/memcached_get.c index 3305a772..2de7acbd 100644 --- a/libmemcached/memcached_get.c +++ b/libmemcached/memcached_get.c @@ -293,7 +293,8 @@ static memcached_return binary_mget_by_key(memcached_st *ptr, memcached_return vk; vk= memcached_validate_key_length(key_length[x], ptr->flags & MEM_BINARY_PROTOCOL); - unlikely (vk != MEMCACHED_SUCCESS) { + unlikely (vk != MEMCACHED_SUCCESS) + { if (x > 0) memcached_io_reset(&ptr->hosts[server_key]); return vk; diff --git a/libmemcached/memcached_quit.c b/libmemcached/memcached_quit.c index 592bde9f..80b9314a 100644 --- a/libmemcached/memcached_quit.c +++ b/libmemcached/memcached_quit.c @@ -26,7 +26,8 @@ void memcached_quit_server(memcached_server_st *ptr, uint8_t io_death) request.message.header.request.opcode = PROTOCOL_BINARY_CMD_QUIT; request.message.header.request.datatype = PROTOCOL_BINARY_RAW_BYTES; rc= memcached_do(ptr, request.bytes, sizeof(request.bytes), 1); - } else + } + else rc= memcached_do(ptr, "quit\r\n", 6, 1); WATCHPOINT_ASSERT(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_FETCH_NOTFINISHED); diff --git a/libmemcached/memcached_response.c b/libmemcached/memcached_response.c index 940c9f88..e9f82b0a 100644 --- a/libmemcached/memcached_response.c +++ b/libmemcached/memcached_response.c @@ -50,7 +50,8 @@ memcached_return memcached_response(memcached_server_st *ptr, * compatibility. */ if ((ptr->root->flags & MEM_BINARY_PROTOCOL) == 0) - while (memcached_server_response_count(ptr) > 1) { + while (memcached_server_response_count(ptr) > 1) + { memcached_return rc= memcached_read_one_response(ptr, buffer, buffer_length, result); unlikely (rc != MEMCACHED_END && diff --git a/libmemcached/memcached_storage.c b/libmemcached/memcached_storage.c index 9acc7c3b..0243de50 100644 --- a/libmemcached/memcached_storage.c +++ b/libmemcached/memcached_storage.c @@ -105,7 +105,8 @@ static inline memcached_return memcached_send(memcached_st *ptr, (unsigned long long)expiration, value_length, (ptr->flags & MEM_NOREPLY) ? " noreply" : ""); - if (ptr->flags & MEM_USE_UDP && ptr->flags & MEM_BUFFER_REQUESTS) { + if (ptr->flags & MEM_USE_UDP && ptr->flags & MEM_BUFFER_REQUESTS) + { size_t cmd_size= write_length + value_length + 2; if (cmd_size > MAX_UDP_DATAGRAM_LENGTH - UDP_DATAGRAM_HEADER_LENGTH) return MEMCACHED_WRITE_FAILURE; @@ -338,7 +339,8 @@ memcached_return memcached_cas_by_key(memcached_st *ptr, return rc; } -static inline uint8_t get_com_code(memcached_storage_action verb, bool noreply) { +static inline uint8_t get_com_code(memcached_storage_action verb, bool noreply) +{ uint8_t ret; if (noreply) diff --git a/tests/atomsmasher.c b/tests/atomsmasher.c index 7c4c8ae3..08aa86f7 100644 --- a/tests/atomsmasher.c +++ b/tests/atomsmasher.c @@ -186,7 +186,8 @@ static test_return add_test(memcached_st *memc) static test_return many_adds(memcached_st *memc) { unsigned int i; - for (i = 0; i < TEST_COUNTER; i++){ + for (i = 0; i < TEST_COUNTER; i++) + { add_test(memc); } return 0; diff --git a/tests/function.c b/tests/function.c index 09d2673e..8cd48ead 100644 --- a/tests/function.c +++ b/tests/function.c @@ -2228,7 +2228,7 @@ test_return user_supplied_bug18(memcached_st *trash) { memcached_return rc; int value; - int i; + int x; memcached_server_st *server_pool; memcached_st *memc; @@ -2270,11 +2270,11 @@ test_return user_supplied_bug18(memcached_st *trash) assert(memcached_generate_hash(memc, (char *)"VDEAAAAA", 8) == memc->continuum[0].index); /* verify the standard ketama set. */ - for (i= 0; i < 99; i++) + for (x= 0; x < 99; x++) { - uint32_t server_idx = memcached_generate_hash(memc, test_cases[i].key, strlen(test_cases[i].key)); + uint32_t server_idx = memcached_generate_hash(memc, test_cases[x].key, strlen(test_cases[x].key)); char *hostname = memc->hosts[server_idx].hostname; - assert(strcmp(hostname, test_cases[i].server) == 0); + assert(strcmp(hostname, test_cases[x].server) == 0); } memcached_server_list_free(server_pool); @@ -3173,7 +3173,8 @@ static test_return analyzer_test(memcached_st *memc) return TEST_SUCCESS; } -static void increment_request_id(uint16_t *id) { +static void increment_request_id(uint16_t *id) +{ (*id)++; if ((*id & UDP_REQUEST_ID_THREAD_MASK) != 0) *id= 0; @@ -3183,21 +3184,22 @@ static uint16_t *get_udp_request_ids(memcached_st *memc) { uint16_t *ids= malloc(sizeof(uint16_t) * memc->number_of_hosts); assert(ids != NULL); - unsigned int i; - for (i= 0; i < memc->number_of_hosts; i++) - ids[i]= get_udp_datagram_request_id((struct udp_datagram_header_st *) memc->hosts[i].write_buffer); + unsigned int x; + for (x= 0; x < memc->number_of_hosts; x++) + ids[x]= get_udp_datagram_request_id((struct udp_datagram_header_st *) memc->hosts[x].write_buffer); return ids; } -static test_return post_udp_op_check(memcached_st *memc, uint16_t *expected_req_ids) { - unsigned int i; +static test_return post_udp_op_check(memcached_st *memc, uint16_t *expected_req_ids) +{ + unsigned int x; memcached_server_st *cur_server = memc->hosts; uint16_t *cur_req_ids = get_udp_request_ids(memc); - for (i= 0; i < memc->number_of_hosts; i++) + for (x= 0; x < memc->number_of_hosts; x++) { - assert(cur_server[i].cursor_active == 0); - assert(cur_req_ids[i] == expected_req_ids[i]); + assert(cur_server[x].cursor_active == 0); + assert(cur_req_ids[x] == expected_req_ids[x]); } free(expected_req_ids); free(cur_req_ids); @@ -3215,15 +3217,15 @@ static memcached_return init_udp(memcached_st *memc) return MEMCACHED_FAILURE; uint32_t num_hosts= memc->number_of_hosts; - unsigned int i= 0; + unsigned int x= 0; memcached_server_st servers[num_hosts]; memcpy(servers, memc->hosts, sizeof(memcached_server_st) * num_hosts); memc->number_of_hosts= 0; memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_USE_UDP, 1); - for (i= 0; i < num_hosts; i++) + for (x= 0; x < num_hosts; x++) { - assert(memcached_server_add_udp(memc, servers[i].hostname, servers[i].port) == MEMCACHED_SUCCESS); - assert(memc->hosts[i].write_buffer_offset == UDP_DATAGRAM_HEADER_LENGTH); + assert(memcached_server_add_udp(memc, servers[x].hostname, servers[x].port) == MEMCACHED_SUCCESS); + assert(memc->hosts[x].write_buffer_offset == UDP_DATAGRAM_HEADER_LENGTH); } return MEMCACHED_SUCCESS; } @@ -3278,9 +3280,9 @@ static test_return set_udp_behavior_test(memcached_st *memc) static test_return udp_set_test(memcached_st *memc) { - unsigned int i= 0; + unsigned int x= 0; unsigned int num_iters= 1025; //request id rolls over at 1024 - for (i= 0; i < num_iters;i++) + for (x= 0; x < num_iters;x++) { memcached_return rc; char *key= "foo"; @@ -3300,9 +3302,12 @@ static test_return udp_set_test(memcached_st *memc) memc->hosts[server_key].write_buffer_offset < init_offset) increment_request_id(&expected_ids[server_key]); - if (rc == MEMCACHED_SUCCESS) { + if (rc == MEMCACHED_SUCCESS) + { assert(memc->hosts[server_key].write_buffer_offset == UDP_DATAGRAM_HEADER_LENGTH); - } else { + } + else + { assert(memc->hosts[server_key].write_buffer_offset != UDP_DATAGRAM_HEADER_LENGTH); assert(memc->hosts[server_key].write_buffer_offset <= MAX_UDP_DATAGRAM_LENGTH); } @@ -3332,9 +3337,9 @@ static test_return udp_set_too_big_test(memcached_st *memc) test_return udp_delete_test(memcached_st *memc) { - unsigned int i= 0; + unsigned int x= 0; unsigned int num_iters= 1025; //request id rolls over at 1024 - for (i= 0; i < num_iters;i++) + for (x= 0; x < num_iters;x++) { memcached_return rc; char *key= "foo"; @@ -3482,8 +3487,8 @@ test_return udp_mixed_io_test(memcached_st *memc) {"udp_decr_test", 0, udp_decr_test}, {"udp_version_test", 0, udp_version_test} }; - unsigned int i= 0; - for (i= 0; i < 500; i++) + unsigned int x= 0; + for (x= 0; x < 500; x++) { current_op= mixed_io_ops[random() % 9]; assert(current_op.function(memc) == TEST_SUCCESS); diff --git a/tests/server.c b/tests/server.c index 8a7970a0..d0942edf 100644 --- a/tests/server.c +++ b/tests/server.c @@ -38,10 +38,13 @@ void server_startup(server_startup_st *construct) int count; int status; - if(x == 0) { + if (x == 0) + { sprintf(buffer, "%s -d -P /tmp/%umemc.pid -t 1 -p %u -U %u -m 128", MEMCACHED_BINARY, x, x + TEST_PORT_BASE, x + TEST_PORT_BASE); - } else { + } + else + { sprintf(buffer, "%s -d -P /tmp/%umemc.pid -t 1 -p %u -U %u", MEMCACHED_BINARY, x, x + TEST_PORT_BASE, x + TEST_PORT_BASE); } -- 2.30.2