From: Padraig O'Sullivan Date: Sat, 18 Jul 2009 17:37:40 +0000 (-0400) Subject: Build fixes for libmemcached/memcached_io.c file. X-Git-Tag: 0.32~7^2^2 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=177497693368fb7f68494e57e92bb9e68658334b;p=m6w6%2Flibmemcached Build fixes for libmemcached/memcached_io.c file. --- diff --git a/libmemcached/memcached_io.c b/libmemcached/memcached_io.c index 69771d71..411040f6 100644 --- a/libmemcached/memcached_io.c +++ b/libmemcached/memcached_io.c @@ -146,8 +146,8 @@ memcached_return memcached_io_read(memcached_server_st *ptr, } ptr->io_bytes_sent = 0; - ptr->read_data_length= data_read; - ptr->read_buffer_length= data_read; + ptr->read_data_length= (size_t) data_read; + ptr->read_buffer_length= (size_t) data_read; ptr->read_ptr= ptr->read_buffer; } @@ -174,7 +174,7 @@ memcached_return memcached_io_read(memcached_server_st *ptr, } ptr->server_failure_counter= 0; - *nread = (size_t)(buffer_ptr - (char*)buffer); + *nread = (ssize_t)(buffer_ptr - (char*)buffer); return MEMCACHED_SUCCESS; } @@ -242,7 +242,7 @@ ssize_t memcached_io_write(memcached_server_st *ptr, return -1; } - return original_length; + return (ssize_t) original_length; } memcached_return memcached_io_close(memcached_server_st *ptr) @@ -408,11 +408,11 @@ static ssize_t io_flush(memcached_server_st *ptr, return -1; } - ptr->io_bytes_sent += sent_length; + ptr->io_bytes_sent += (uint32_t) sent_length; local_write_ptr+= sent_length; - write_length-= sent_length; - return_length+= sent_length; + write_length-= (uint32_t) sent_length; + return_length+= (uint32_t) sent_length; } WATCHPOINT_ASSERT(write_length == 0); @@ -426,7 +426,7 @@ static ssize_t io_flush(memcached_server_st *ptr, else ptr->write_buffer_offset= 0; - return return_length; + return (ssize_t) return_length; } /* @@ -456,7 +456,7 @@ memcached_return memcached_safe_read(memcached_server_st *ptr, if (rc != MEMCACHED_SUCCESS) return rc; - offset+= nread; + offset+= (size_t) nread; } return MEMCACHED_SUCCESS; @@ -524,13 +524,13 @@ static void increment_udp_message_id(memcached_server_st *ptr) { struct udp_datagram_header_st *header= (struct udp_datagram_header_st *)ptr->write_buffer; uint16_t cur_req= get_udp_datagram_request_id(header); - uint16_t msg_num= get_msg_num_from_request_id(cur_req); - uint16_t thread_id= get_thread_id_from_request_id(cur_req); + int msg_num= get_msg_num_from_request_id(cur_req); + int thread_id= get_thread_id_from_request_id(cur_req); if (((++msg_num) & UDP_REQUEST_ID_THREAD_MASK) != 0) msg_num= 0; - header->request_id= htons(thread_id | msg_num); + header->request_id= htons((uint16_t) (thread_id | msg_num)); } memcached_return memcached_io_init_udp_header(memcached_server_st *ptr, uint16_t thread_id) @@ -539,7 +539,7 @@ memcached_return memcached_io_init_udp_header(memcached_server_st *ptr, uint16_t return MEMCACHED_FAILURE; struct udp_datagram_header_st *header= (struct udp_datagram_header_st *)ptr->write_buffer; - header->request_id= htons(generate_udp_request_thread_id(thread_id)); + header->request_id= htons((uint16_t) (generate_udp_request_thread_id(thread_id))); header->num_datagrams= htons(1); header->sequence_number= htons(0); diff --git a/libmemcached/memcached_parse.c b/libmemcached/memcached_parse.c index ca1a08e6..ec695cfa 100644 --- a/libmemcached/memcached_parse.c +++ b/libmemcached/memcached_parse.c @@ -10,7 +10,7 @@ memcached_server_st *memcached_servers_parse(const char *server_strings) { char *string; - unsigned int port; + uint32_t port; uint32_t weight; const char *begin_ptr; const char *end_ptr; @@ -32,7 +32,7 @@ memcached_server_st *memcached_servers_parse(const char *server_strings) if (string) { - memcpy(buffer, begin_ptr, string - begin_ptr); + memcpy(buffer, begin_ptr, (size_t) (string - begin_ptr)); buffer[(unsigned int)(string - begin_ptr)]= 0; begin_ptr= string+1; } @@ -52,7 +52,7 @@ memcached_server_st *memcached_servers_parse(const char *server_strings) ptr++; - port= strtoul(ptr, (char **)NULL, 10); + port= (uint32_t) strtoul(ptr, (char **)NULL, 10); ptr2= index(ptr, ' '); if (! ptr2) @@ -60,7 +60,7 @@ memcached_server_st *memcached_servers_parse(const char *server_strings) if (ptr2) { ptr2++; - weight = strtoul(ptr2, (char **)NULL, 10); + weight = (uint32_t) strtoul(ptr2, (char **)NULL, 10); } } diff --git a/libmemcached/memcached_purge.c b/libmemcached/memcached_purge.c index 624f6245..40c8ad61 100644 --- a/libmemcached/memcached_purge.c +++ b/libmemcached/memcached_purge.c @@ -42,7 +42,7 @@ memcached_return memcached_purge(memcached_server_st *ptr) * data to be sent from the server (the commands was in the output buffer * and just flushed */ - long timeo= ptr->root->poll_timeout; + int32_t timeo= ptr->root->poll_timeout; ptr->root->poll_timeout= 2000; result_ptr= memcached_result_create(ptr->root, &result); @@ -68,7 +68,7 @@ memcached_return memcached_purge(memcached_server_st *ptr) } memcached_result_free(result_ptr); - ptr->root->poll_timeout=timeo; + ptr->root->poll_timeout= timeo; } ptr->root->purging= 0; diff --git a/libmemcached/memcached_quit.c b/libmemcached/memcached_quit.c index c202d433..9a200a1e 100644 --- a/libmemcached/memcached_quit.c +++ b/libmemcached/memcached_quit.c @@ -43,7 +43,7 @@ void memcached_quit_server(memcached_server_st *ptr, uint8_t io_death) memcached_io_close(ptr); ptr->fd= -1; - ptr->write_buffer_offset= (ptr->type == MEMCACHED_CONNECTION_UDP) ? UDP_DATAGRAM_HEADER_LENGTH : 0 ; + ptr->write_buffer_offset= (size_t) ((ptr->type == MEMCACHED_CONNECTION_UDP) ? UDP_DATAGRAM_HEADER_LENGTH : 0); ptr->read_buffer_length= 0; ptr->read_ptr= ptr->read_buffer; memcached_server_response_reset(ptr); diff --git a/libmemcached/memcached_response.c b/libmemcached/memcached_response.c index ba0691b5..f617f27f 100644 --- a/libmemcached/memcached_response.c +++ b/libmemcached/memcached_response.c @@ -125,7 +125,7 @@ static memcached_return textual_value_fetch(memcached_server_st *ptr, if (end_ptr == string_ptr) goto read_error; for (next_ptr= string_ptr; isdigit(*string_ptr); string_ptr++); - result->flags= strtoul(next_ptr, &string_ptr, 10); + result->flags= (uint32_t) strtoul(next_ptr, &string_ptr, 10); if (end_ptr == string_ptr) goto read_error; @@ -250,7 +250,9 @@ static memcached_return textual_read_one_response(memcached_server_st *ptr, memory in the struct, which is important, for something that rarely should happen? */ - rel_ptr= (char *)ptr->root->call_realloc(ptr->root, ptr->cached_server_error, endptr - startptr + 1); + rel_ptr= (char *)ptr->root->call_realloc(ptr->root, + ptr->cached_server_error, + (size_t) (endptr - startptr + 1)); if (rel_ptr == NULL) { @@ -261,7 +263,7 @@ static memcached_return textual_read_one_response(memcached_server_st *ptr, } ptr->cached_server_error= rel_ptr; - memcpy(ptr->cached_server_error, startptr, endptr - startptr); + memcpy(ptr->cached_server_error, startptr, (size_t) (endptr - startptr)); ptr->cached_server_error[endptr - startptr]= 0; return MEMCACHED_SERVER_ERROR; } @@ -461,7 +463,7 @@ static memcached_return binary_read_one_response(memcached_server_st *ptr, size_t nr= (bodylen > SMALL_STRING_LEN) ? SMALL_STRING_LEN : bodylen; if (memcached_safe_read(ptr, hole, nr) != MEMCACHED_SUCCESS) return MEMCACHED_UNKNOWN_READ_FAILURE; - bodylen -= nr; + bodylen-= (uint32_t) nr; } /* This might be an error from one of the quiet commands.. if diff --git a/libmemcached/memcached_stats.c b/libmemcached/memcached_stats.c index 84008908..0f4a97f7 100644 --- a/libmemcached/memcached_stats.c +++ b/libmemcached/memcached_stats.c @@ -40,15 +40,15 @@ static memcached_return set_data(memcached_stat_st *memc_stat, char *key, char * } else if (!strcmp("pid", key)) { - memc_stat->pid= strtol(value, (char **)NULL, 10); + memc_stat->pid= (uint32_t) strtol(value, (char **)NULL, 10); } else if (!strcmp("uptime", key)) { - memc_stat->uptime= strtol(value, (char **)NULL, 10); + memc_stat->uptime= (uint32_t) strtol(value, (char **)NULL, 10); } else if (!strcmp("time", key)) { - memc_stat->time= strtol(value, (char **)NULL, 10); + memc_stat->time= (uint32_t) strtol(value, (char **)NULL, 10); } else if (!strcmp("version", key)) { @@ -57,7 +57,7 @@ static memcached_return set_data(memcached_stat_st *memc_stat, char *key, char * } else if (!strcmp("pointer_size", key)) { - memc_stat->pointer_size= strtol(value, (char **)NULL, 10); + memc_stat->pointer_size= (uint32_t) strtol(value, (char **)NULL, 10); } else if (!strcmp("rusage_user", key)) { @@ -65,8 +65,8 @@ static memcached_return set_data(memcached_stat_st *memc_stat, char *key, char * for (walk_ptr= value; (!ispunct(*walk_ptr)); walk_ptr++); *walk_ptr= 0; walk_ptr++; - memc_stat->rusage_user_seconds= strtol(value, (char **)NULL, 10); - memc_stat->rusage_user_microseconds= strtol(walk_ptr, (char **)NULL, 10); + memc_stat->rusage_user_seconds= (uint32_t) strtol(value, (char **)NULL, 10); + memc_stat->rusage_user_microseconds= (uint32_t) strtol(walk_ptr, (char **)NULL, 10); } else if (!strcmp("rusage_system", key)) { @@ -74,52 +74,52 @@ static memcached_return set_data(memcached_stat_st *memc_stat, char *key, char * for (walk_ptr= value; (!ispunct(*walk_ptr)); walk_ptr++); *walk_ptr= 0; walk_ptr++; - memc_stat->rusage_system_seconds= strtol(value, (char **)NULL, 10); - memc_stat->rusage_system_microseconds= strtol(walk_ptr, (char **)NULL, 10); + memc_stat->rusage_system_seconds= (uint32_t) strtol(value, (char **)NULL, 10); + memc_stat->rusage_system_microseconds= (uint32_t) strtol(walk_ptr, (char **)NULL, 10); } else if (!strcmp("curr_items", key)) { - memc_stat->curr_items= strtol(value, (char **)NULL, 10); + memc_stat->curr_items= (uint32_t) strtol(value, (char **)NULL, 10); } else if (!strcmp("total_items", key)) { - memc_stat->total_items= strtol(value, (char **)NULL, 10); + memc_stat->total_items= (uint32_t) strtol(value, (char **)NULL, 10); } else if (!strcmp("bytes_read", key)) { - memc_stat->bytes_read= strtoll(value, (char **)NULL, 10); + memc_stat->bytes_read= (uint32_t) strtoll(value, (char **)NULL, 10); } else if (!strcmp("bytes_written", key)) { - memc_stat->bytes_written= strtoll(value, (char **)NULL, 10); + memc_stat->bytes_written= (uint32_t) strtoll(value, (char **)NULL, 10); } else if (!strcmp("bytes", key)) { - memc_stat->bytes= strtoll(value, (char **)NULL, 10); + memc_stat->bytes= (uint32_t) strtoll(value, (char **)NULL, 10); } else if (!strcmp("curr_connections", key)) { - memc_stat->curr_connections= strtoll(value, (char **)NULL, 10); + memc_stat->curr_connections= (uint32_t) strtoll(value, (char **)NULL, 10); } else if (!strcmp("total_connections", key)) { - memc_stat->total_connections= strtoll(value, (char **)NULL, 10); + memc_stat->total_connections= (uint32_t) strtoll(value, (char **)NULL, 10); } else if (!strcmp("connection_structures", key)) { - memc_stat->connection_structures= strtol(value, (char **)NULL, 10); + memc_stat->connection_structures= (uint32_t) strtol(value, (char **)NULL, 10); } else if (!strcmp("cmd_get", key)) { - memc_stat->cmd_get= strtoll(value, (char **)NULL, 10); + memc_stat->cmd_get= (uint64_t) strtoll(value, (char **)NULL, 10); } else if (!strcmp("cmd_set", key)) { - memc_stat->cmd_set= strtoll(value, (char **)NULL, 10); + memc_stat->cmd_set= (uint64_t) strtoll(value, (char **)NULL, 10); } else if (!strcmp("get_hits", key)) { - memc_stat->get_hits= strtoll(value, (char **)NULL, 10); + memc_stat->get_hits= (uint64_t) strtoll(value, (char **)NULL, 10); } else if (!strcmp("get_misses", key)) { @@ -131,11 +131,11 @@ static memcached_return set_data(memcached_stat_st *memc_stat, char *key, char * } else if (!strcmp("limit_maxbytes", key)) { - memc_stat->limit_maxbytes= strtoll(value, (char **)NULL, 10); + memc_stat->limit_maxbytes= (uint64_t) strtoll(value, (char **)NULL, 10); } else if (!strcmp("threads", key)) { - memc_stat->threads= strtol(value, (char **)NULL, 10); + memc_stat->threads= (uint32_t) strtol(value, (char **)NULL, 10); } else if (!(strcmp("delete_misses", key) == 0 ||/* New stats in the 1.3 beta */ strcmp("delete_hits", key) == 0 ||/* Just swallow them for now.. */ @@ -162,7 +162,7 @@ char *memcached_stat_get_value(memcached_st *ptr, memcached_stat_st *memc_stat, const char *key, memcached_return *error) { char buffer[SMALL_STRING_LEN]; - size_t length; + int length; char *ret; *error= MEMCACHED_SUCCESS; @@ -217,8 +217,8 @@ char *memcached_stat_get_value(memcached_st *ptr, memcached_stat_st *memc_stat, return NULL; } - ret= ptr->call_malloc(ptr, length + 1); - memcpy(ret, buffer, length); + ret= ptr->call_malloc(ptr, (size_t) (length + 1)); + memcpy(ret, buffer, (size_t) length); ret[length]= '\0'; return ret; @@ -239,14 +239,14 @@ static memcached_return binary_stats_fetch(memcached_st *ptr, if (args != NULL) { - int len= strlen(args); + size_t len= strlen(args); rc= memcached_validate_key_length(len, true); unlikely (rc != MEMCACHED_SUCCESS) return rc; request.message.header.request.keylen= htons((uint16_t)len); - request.message.header.request.bodylen= htonl(len); + request.message.header.request.bodylen= htonl((uint32_t) len); if ((memcached_do(&ptr->hosts[server_key], request.bytes, sizeof(request.bytes), 0) != MEMCACHED_SUCCESS) || @@ -305,11 +305,11 @@ static memcached_return ascii_stats_fetch(memcached_st *ptr, size_t send_length; if (args) - send_length= snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, - "stats %s\r\n", args); + send_length= (size_t) snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, + "stats %s\r\n", args); else - send_length= snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, - "stats\r\n"); + send_length= (size_t) snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, + "stats\r\n"); if (send_length >= MEMCACHED_DEFAULT_COMMAND_SIZE) return MEMCACHED_WRITE_FAILURE; diff --git a/libmemcached/memcached_storage.c b/libmemcached/memcached_storage.c index e10f85f0..ecefc566 100644 --- a/libmemcached/memcached_storage.c +++ b/libmemcached/memcached_storage.c @@ -91,14 +91,14 @@ static inline memcached_return memcached_send(memcached_st *ptr, server_key= memcached_generate_hash(ptr, master_key, master_key_length); if (cas) - write_length= snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, - "%s %s%.*s %u %llu %zu %llu%s\r\n", - storage_op_string(verb), - ptr->prefix_key, - (int)key_length, key, flags, - (unsigned long long)expiration, value_length, - (unsigned long long)cas, - (ptr->flags & MEM_NOREPLY) ? " noreply" : ""); + write_length= (size_t) snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, + "%s %s%.*s %u %llu %zu %llu%s\r\n", + storage_op_string(verb), + ptr->prefix_key, + (int)key_length, key, flags, + (unsigned long long)expiration, value_length, + (unsigned long long)cas, + (ptr->flags & MEM_NOREPLY) ? " noreply" : ""); else { char *buffer_ptr= buffer; @@ -118,11 +118,11 @@ static inline memcached_return memcached_send(memcached_st *ptr, buffer_ptr++; write_length= (size_t)(buffer_ptr - buffer); - write_length+= snprintf(buffer_ptr, MEMCACHED_DEFAULT_COMMAND_SIZE, - "%u %llu %zu%s\r\n", - flags, - (unsigned long long)expiration, value_length, - (ptr->flags & MEM_NOREPLY) ? " noreply" : ""); + write_length+= (size_t) snprintf(buffer_ptr, MEMCACHED_DEFAULT_COMMAND_SIZE, + "%u %llu %zu%s\r\n", + flags, + (unsigned long long)expiration, value_length, + (ptr->flags & MEM_NOREPLY) ? " noreply" : ""); } if (ptr->flags & MEM_USE_UDP && ptr->flags & MEM_BUFFER_REQUESTS) @@ -429,7 +429,7 @@ static memcached_return memcached_send_binary(memcached_st *ptr, uint64_t cas, memcached_storage_action verb) { - char flush; + uint8_t flush; protocol_binary_request_set request= {.bytes= {0}}; size_t send_length= sizeof(request.bytes); uint32_t server_key= memcached_generate_hash(ptr, master_key, @@ -450,13 +450,13 @@ static memcached_return memcached_send_binary(memcached_st *ptr, request.message.body.expiration= htonl((uint32_t)expiration); } - request.message.header.request.bodylen= htonl(key_length + value_length + - request.message.header.request.extlen); + request.message.header.request.bodylen= htonl((uint32_t) (key_length + value_length + + request.message.header.request.extlen)); if (cas) request.message.header.request.cas= htonll(cas); - flush= ((server->root->flags & MEM_BUFFER_REQUESTS) && verb == SET_OP) ? 0 : 1; + flush= (uint8_t) (((server->root->flags & MEM_BUFFER_REQUESTS) && verb == SET_OP) ? 0 : 1); if ((server->root->flags & MEM_USE_UDP) && !flush) { @@ -470,7 +470,7 @@ static memcached_return memcached_send_binary(memcached_st *ptr, /* write the header */ if ((memcached_do(server, (const char*)request.bytes, send_length, 0) != MEMCACHED_SUCCESS) || (memcached_io_write(server, key, key_length, 0) == -1) || - (memcached_io_write(server, value, value_length, flush) == -1)) + (memcached_io_write(server, value, value_length, (char) flush) == -1)) { memcached_io_reset(server); return MEMCACHED_WRITE_FAILURE; @@ -490,7 +490,7 @@ static memcached_return memcached_send_binary(memcached_st *ptr, if ((memcached_do(srv, (const char*)request.bytes, send_length, 0) != MEMCACHED_SUCCESS) || (memcached_io_write(srv, key, key_length, 0) == -1) || - (memcached_io_write(srv, value, value_length, flush) == -1)) + (memcached_io_write(srv, value, value_length, (char) flush) == -1)) memcached_io_reset(srv); else memcached_server_response_decrement(srv); diff --git a/libmemcached/memcached_string.c b/libmemcached/memcached_string.c index 5b9e9281..614343c8 100644 --- a/libmemcached/memcached_string.c +++ b/libmemcached/memcached_string.c @@ -4,7 +4,7 @@ memcached_return memcached_string_check(memcached_string_st *string, size_t need { if (need && need > (size_t)(string->current_size - (size_t)(string->end - string->string))) { - size_t current_offset= string->end - string->string; + size_t current_offset= (size_t) (string->end - string->string); char *new_value; size_t adjust; size_t new_size; diff --git a/libmemcached/memcached_verbosity.c b/libmemcached/memcached_verbosity.c index 43132786..fd56316d 100644 --- a/libmemcached/memcached_verbosity.c +++ b/libmemcached/memcached_verbosity.c @@ -7,8 +7,8 @@ memcached_return memcached_verbosity(memcached_st *ptr, unsigned int verbosity) memcached_return rc; char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE]; - send_length= snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, - "verbosity %u\r\n", verbosity); + send_length= (size_t) snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, + "verbosity %u\r\n", verbosity); unlikely (send_length >= MEMCACHED_DEFAULT_COMMAND_SIZE) return MEMCACHED_WRITE_FAILURE; diff --git a/libmemcached/murmur_hash.c b/libmemcached/murmur_hash.c index edb9e777..b9513440 100644 --- a/libmemcached/murmur_hash.c +++ b/libmemcached/murmur_hash.c @@ -25,13 +25,13 @@ uint32_t murmur_hash(const char *key, size_t length) */ const unsigned int m= 0x5bd1e995; - const unsigned int seed= (0xdeadbeef * length); + const size_t seed= (0xdeadbeef * length); const int r= 24; // Initialize the hash to a 'random' value - unsigned int h= seed ^ length; + size_t h= seed ^ length; // Mix 4 bytes at a time into the hash @@ -72,5 +72,5 @@ uint32_t murmur_hash(const char *key, size_t length) h *= m; h ^= h >> 15; - return h; + return (uint32_t) h; }