From: Trond Norbye Date: Wed, 14 Oct 2009 10:31:33 +0000 (+0200) Subject: Bug #447237: const-correctness in interface X-Git-Tag: 0.35~11^2~4 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=d3849dc8d77725e4997f40e0d988787b3e913bd9;p=m6w6%2Flibmemcached Bug #447237: const-correctness in interface --- diff --git a/docs/memcached_get.pod b/docs/memcached_get.pod index 4c80fb3e..5dde1edc 100644 --- a/docs/memcached_get.pod +++ b/docs/memcached_get.pod @@ -23,7 +23,8 @@ C Client Library for memcached (libmemcached, -lmemcached) memcached_return memcached_mget (memcached_st *ptr, - char **keys, size_t *key_length, + const char * const *keys, + const size_t *key_length, size_t number_of_keys); char * memcached_get_by_key(memcached_st *ptr, @@ -36,7 +37,8 @@ C Client Library for memcached (libmemcached, -lmemcached) memcached_return memcached_mget_by_key(memcached_st *ptr, const char *master_key, size_t master_key_length, - char **keys, size_t *key_length, + const char * const *keys, + const size_t *key_length, size_t number_of_keys); char *memcached_fetch (memcached_st *ptr, @@ -56,8 +58,8 @@ C Client Library for memcached (libmemcached, -lmemcached) memcached_mget_execute(memcached_st *ptr, const char *master_key, size_t master_key_length, - const char **keys, - size_t *key_length, + const char * const *keys, + const size_t *key_length, size_t number_of_keys, memcached_execute_function *callback, void *context, diff --git a/libmemcached/common.h b/libmemcached/common.h index 96b83463..30fc4e12 100644 --- a/libmemcached/common.h +++ b/libmemcached/common.h @@ -136,7 +136,8 @@ LIBMEMCACHED_LOCAL void server_list_free(memcached_st *ptr, memcached_server_st *servers); LIBMEMCACHED_LOCAL -memcached_return memcached_key_test(const char **keys, size_t *key_length, +memcached_return memcached_key_test(const char * const *keys, + const size_t *key_length, size_t number_of_keys); diff --git a/libmemcached/memcached_get.c b/libmemcached/memcached_get.c index 53c76f4b..90cf456f 100644 --- a/libmemcached/memcached_get.c +++ b/libmemcached/memcached_get.c @@ -15,12 +15,12 @@ char *memcached_get(memcached_st *ptr, const char *key, } static memcached_return memcached_mget_by_key_real(memcached_st *ptr, - const char *master_key, - size_t master_key_length, - const char **keys, - size_t *key_length, - size_t number_of_keys, - bool mget_mode); + const char *master_key, + size_t master_key_length, + const char * const *keys, + const size_t *key_length, + size_t number_of_keys, + bool mget_mode); char *memcached_get_by_key(memcached_st *ptr, const char *master_key, @@ -42,10 +42,9 @@ char *memcached_get_by_key(memcached_st *ptr, } /* Request the key */ - *error= memcached_mget_by_key_real(ptr, - master_key, - master_key_length, - (const char **)&key, &key_length, 1, false); + *error= memcached_mget_by_key_real(ptr, master_key, master_key_length, + (const char * const *)&key, + &key_length, 1, false); value= memcached_fetch(ptr, NULL, NULL, value_length, flags, error); @@ -110,7 +109,8 @@ char *memcached_get_by_key(memcached_st *ptr, } memcached_return memcached_mget(memcached_st *ptr, - const char **keys, size_t *key_length, + const char * const *keys, + const size_t *key_length, size_t number_of_keys) { return memcached_mget_by_key(ptr, NULL, 0, keys, key_length, number_of_keys); @@ -119,17 +119,18 @@ memcached_return memcached_mget(memcached_st *ptr, static memcached_return binary_mget_by_key(memcached_st *ptr, unsigned int master_server_key, bool is_master_key_set, - const char **keys, size_t *key_length, + const char * const *keys, + const size_t *key_length, size_t number_of_keys, bool mget_mode); static memcached_return memcached_mget_by_key_real(memcached_st *ptr, - const char *master_key, - size_t master_key_length, - const char **keys, - size_t *key_length, - size_t number_of_keys, - bool mget_mode) + const char *master_key, + size_t master_key_length, + const char * const *keys, + const size_t *key_length, + size_t number_of_keys, + bool mget_mode) { unsigned int x; memcached_return rc= MEMCACHED_NOTFOUND; @@ -155,7 +156,7 @@ static memcached_return memcached_mget_by_key_real(memcached_st *ptr, if (master_key && master_key_length) { - if ((ptr->flags & MEM_VERIFY_KEY) && (memcached_key_test((const char **)&master_key, &master_key_length, 1) == MEMCACHED_BAD_KEY_PROVIDED)) + if ((ptr->flags & MEM_VERIFY_KEY) && (memcached_key_test((const char * const *)&master_key, &master_key_length, 1) == MEMCACHED_BAD_KEY_PROVIDED)) return MEMCACHED_BAD_KEY_PROVIDED; master_server_key= memcached_generate_hash(ptr, master_key, master_key_length); is_master_key_set= true; @@ -269,8 +270,8 @@ static memcached_return memcached_mget_by_key_real(memcached_st *ptr, memcached_return memcached_mget_by_key(memcached_st *ptr, const char *master_key, size_t master_key_length, - const char **keys, - size_t *key_length, + const char * const *keys, + const size_t *key_length, size_t number_of_keys) { return memcached_mget_by_key_real(ptr, master_key, master_key_length, keys, @@ -280,8 +281,8 @@ memcached_return memcached_mget_by_key(memcached_st *ptr, memcached_return memcached_mget_execute(memcached_st *ptr, const char *master_key, size_t master_key_length, - const char **keys, - size_t *key_length, + const char * const *keys, + const size_t *key_length, size_t number_of_keys, memcached_execute_function *callback, void *context, @@ -308,7 +309,8 @@ memcached_return memcached_mget_execute(memcached_st *ptr, static memcached_return simple_binary_mget(memcached_st *ptr, unsigned int master_server_key, bool is_master_key_set, - const char **keys, size_t *key_length, + const char * const *keys, + const size_t *key_length, size_t number_of_keys, bool mget_mode) { memcached_return rc= MEMCACHED_NOTFOUND; @@ -410,9 +412,12 @@ static memcached_return simple_binary_mget(memcached_st *ptr, } static memcached_return replication_binary_mget(memcached_st *ptr, - uint32_t* hash, bool* dead_servers, - const char **keys, size_t *key_length, - size_t number_of_keys, bool mget_mode) + uint32_t* hash, + bool* dead_servers, + const char *const *keys, + const size_t *key_length, + size_t number_of_keys, + bool mget_mode) { memcached_return rc= MEMCACHED_NOTFOUND; uint32_t x; @@ -511,8 +516,10 @@ static memcached_return replication_binary_mget(memcached_st *ptr, static memcached_return binary_mget_by_key(memcached_st *ptr, unsigned int master_server_key, bool is_master_key_set, - const char **keys, size_t *key_length, - size_t number_of_keys, bool mget_mode) + const char * const *keys, + const size_t *key_length, + size_t number_of_keys, + bool mget_mode) { memcached_return rc; diff --git a/libmemcached/memcached_get.h b/libmemcached/memcached_get.h index 6e10ad18..11dd7fee 100644 --- a/libmemcached/memcached_get.h +++ b/libmemcached/memcached_get.h @@ -23,7 +23,8 @@ char *memcached_get(memcached_st *ptr, LIBMEMCACHED_API memcached_return memcached_mget(memcached_st *ptr, - const char **keys, size_t *key_length, + const char * const *keys, + const size_t *key_length, size_t number_of_keys); LIBMEMCACHED_API @@ -38,8 +39,8 @@ LIBMEMCACHED_API memcached_return memcached_mget_by_key(memcached_st *ptr, const char *master_key, size_t master_key_length, - const char **keys, - size_t *key_length, + const char * const *keys, + const size_t *key_length, size_t number_of_keys); LIBMEMCACHED_API @@ -57,8 +58,8 @@ LIBMEMCACHED_API memcached_return memcached_mget_execute(memcached_st *ptr, const char *master_key, size_t master_key_length, - const char **keys, - size_t *key_length, + const char * const *keys, + const size_t *key_length, size_t number_of_keys, memcached_execute_function *callback, void *context, diff --git a/libmemcached/memcached_key.c b/libmemcached/memcached_key.c index c8a3a0eb..9aac1ebc 100644 --- a/libmemcached/memcached_key.c +++ b/libmemcached/memcached_key.c @@ -1,6 +1,7 @@ #include "common.h" -memcached_return memcached_key_test(const char **keys, size_t *key_length, +memcached_return memcached_key_test(const char * const *keys, + const size_t *key_length, size_t number_of_keys) { uint32_t x; @@ -14,8 +15,6 @@ memcached_return memcached_key_test(const char **keys, size_t *key_length, if (rc != MEMCACHED_SUCCESS) return rc; - - for (y= 0; y < *(key_length + x); y++) { if ((isgraph(keys[x][y])) == 0)