From: Brian Aker Date: Tue, 2 Mar 2010 22:16:10 +0000 (-0800) Subject: Correction to API for custom hash settings. X-Git-Tag: 0.40~36 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=7344d3186d1daf8256f211a80da15c370b9884a8;p=awesomized%2Flibmemcached Correction to API for custom hash settings. --- diff --git a/libmemcached/hash.c b/libmemcached/hash.c index b418d2e1..dda30395 100644 --- a/libmemcached/hash.c +++ b/libmemcached/hash.c @@ -124,7 +124,15 @@ uint32_t memcached_generate_hash(const memcached_st *ptr, const char *key, size_ return dispatch_host(ptr, _generate_hash_wrapper(ptr, key, key_length)); } -hashkit_st *memcached_get_hashkit(memcached_st *ptr) +const hashkit_st *memcached_get_hashkit(const memcached_st *ptr) { return &ptr->hashkit; } + +memcached_return_t memcached_set_hashkit(memcached_st *self, hashkit_st *hashk) +{ + hashkit_free(&self->hashkit); + hashkit_clone(&self->hashkit, hashk); + + return MEMCACHED_SUCCESS; +} diff --git a/libmemcached/hash.h b/libmemcached/hash.h index 5f601229..0e664266 100644 --- a/libmemcached/hash.h +++ b/libmemcached/hash.h @@ -21,7 +21,10 @@ LIBMEMCACHED_API uint32_t memcached_generate_hash_value(const char *key, size_t key_length, memcached_hash_t hash_algorithm); LIBMEMCACHED_API -hashkit_st *memcached_get_hashkit(memcached_st *ptr); +const hashkit_st *memcached_get_hashkit(const memcached_st *ptr); + +LIBMEMCACHED_API +memcached_return_t memcached_set_hashkit(memcached_st *ptr, hashkit_st *hashk); LIBMEMCACHED_API uint32_t memcached_generate_hash(const memcached_st *ptr, const char *key, size_t key_length); diff --git a/tests/mem_functions.c b/tests/mem_functions.c index 84ac0dc1..6534378b 100644 --- a/tests/mem_functions.c +++ b/tests/mem_functions.c @@ -4766,7 +4766,8 @@ static test_return_t memcached_get_hashkit_test (memcached_st *memc) { uint32_t x; const char **ptr; - hashkit_st *kit; + const hashkit_st *kit; + hashkit_st new_kit; hashkit_return_t hash_rc; uint32_t md5_hosts[]= {4U, 1U, 0U, 1U, 4U, 2U, 0U, 3U, 0U, 0U, 3U, 1U, 0U, 0U, 1U, 3U, 0U, 0U, 0U, 3U, 1U, 0U, 4U, 4U, 3U}; @@ -4774,9 +4775,12 @@ static test_return_t memcached_get_hashkit_test (memcached_st *memc) kit= memcached_get_hashkit(memc); - hash_rc= hashkit_set_custom_function(kit, hash_md5_test_function, NULL); + hashkit_clone(&new_kit, kit); + hash_rc= hashkit_set_custom_function(&new_kit, hash_md5_test_function, NULL); test_true(hash_rc == HASHKIT_SUCCESS); + memcached_set_hashkit(memc, &new_kit); + /* Verify Setting the hash. */ @@ -4800,9 +4804,11 @@ static test_return_t memcached_get_hashkit_test (memcached_st *memc) test_true(md5_hosts[x] == hash_val); } - hash_rc= hashkit_set_custom_function(kit, hash_crc_test_function, NULL); + hash_rc= hashkit_set_custom_function(&new_kit, hash_crc_test_function, NULL); test_true(hash_rc == HASHKIT_SUCCESS); + memcached_set_hashkit(memc, &new_kit); + /* Verify Setting the hash. */