From 7b30155c3b85ef95cd1841efb1b109aa918ed52b Mon Sep 17 00:00:00 2001 From: Date: Sun, 20 Jan 2008 21:00:46 -0800 Subject: [PATCH] Fixed bug found by Evan Weaver where increment was not returning propper error on not found. Commented out Patrick's missing pod file. --- ChangeLog | 2 ++ docs/Makefile.am | 8 ++++---- lib/memcached.c | 2 -- lib/memcached_auto.c | 6 +++--- lib/memcached_io.c | 1 - tests/function.c | 43 ++++++++++++++++++++++++++++++++++++++++++- 6 files changed, 51 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3bebceb1..cffb7a4a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,6 @@ + * For for bug found by Evan Weaver where increment() was not returning + propper error of value was not found. * Fix for bad null pointer on flag by Toru Maesaka. * Refactor of all IO to just pass in the active server * Problem configuring (PKG_CHECK_MODULES) fixed by removal of "rpath" in diff --git a/docs/Makefile.am b/docs/Makefile.am index 6eaf8eeb..e4cb08bf 100644 --- a/docs/Makefile.am +++ b/docs/Makefile.am @@ -22,7 +22,7 @@ EXTRA_DIST = libmemcached.pod\ memcp.pod\ memcached_delete.pod\ memcached_set.pod\ - memcached_version.pod\ + memcached_version.pod\ memflush.pod man_MANS = libmemcached.3\ @@ -79,7 +79,7 @@ man_MANS = libmemcached.3\ memcached_strerror.3\ memcached_quit.3\ memcached_verbosity.3\ - memcached_lib_version.3\ +# memcached_lib_version.3\ memcached_version.3 libmemcached.3: libmemcached.pod @@ -259,8 +259,8 @@ memcached_result_cas.3: memcached_result_st.pod memcached_version.3: memcached_version.pod pod2man -c "libmemcached" -r "" -s 3 memcached_version.pod > memcached_version.3 -memcached_lib_version.3: memcached_version.pod - pod2man -c "libmemcached" -r "" -s 3 memcached_version.pod > memcached_lib_version.3 +#memcached_lib_version.3: memcached_version.pod +# pod2man -c "libmemcached" -r "" -s 3 memcached_version.pod > memcached_lib_version.3 memcp.1: memcp.pod pod2man -c "libmemcached" -r "" -s 1 memcp.pod > memcp.1 diff --git a/lib/memcached.c b/lib/memcached.c index 5d89e721..31c12ab3 100644 --- a/lib/memcached.c +++ b/lib/memcached.c @@ -60,7 +60,6 @@ memcached_st *memcached_clone(memcached_st *clone, memcached_st *ptr) memcached_return rc= MEMCACHED_SUCCESS; memcached_st *new_clone; - WATCHPOINT; if (ptr == NULL) return memcached_create(clone); @@ -70,7 +69,6 @@ memcached_st *memcached_clone(memcached_st *clone, memcached_st *ptr) return NULL; } - WATCHPOINT; new_clone= memcached_create(clone); if (new_clone == NULL) diff --git a/lib/memcached_auto.c b/lib/memcached_auto.c index f21f8f2f..4af85e97 100644 --- a/lib/memcached_auto.c +++ b/lib/memcached_auto.c @@ -35,16 +35,16 @@ static memcached_return memcached_auto(memcached_st *ptr, /* So why recheck responce? Because the protocol is brain dead :) The number returned might end up equaling one of the string - values. Less chance of a mistake with memcmp() so we will + values. Less chance of a mistake with strncmp() so we will use it. We still called memcached_response() though since it worked its magic for non-blocking IO. */ - if (!memcmp(buffer, "ERROR\r\n", MEMCACHED_DEFAULT_COMMAND_SIZE)) + if (!strncmp(buffer, "ERROR\r\n", 7)) { *value= 0; rc= MEMCACHED_PROTOCOL_ERROR; } - else if (!memcmp(buffer, "NOT_FOUND\r\n", MEMCACHED_DEFAULT_COMMAND_SIZE)) + else if (!strncmp(buffer, "NOT_FOUND\r\n", 11)) { *value= 0; rc= MEMCACHED_NOTFOUND; diff --git a/lib/memcached_io.c b/lib/memcached_io.c index 1ef7a465..be186c4b 100644 --- a/lib/memcached_io.c +++ b/lib/memcached_io.c @@ -234,7 +234,6 @@ static ssize_t io_flush(memcached_server_st *ptr, if ((ssize_t)(sent_length= write(ptr->fd, local_write_ptr, write_length)) == -1) { - WATCHPOINT_STRING("Error in write occurred"); switch (errno) { case ENOBUFS: diff --git a/tests/function.c b/tests/function.c index 51b4c74a..77a39781 100644 --- a/tests/function.c +++ b/tests/function.c @@ -889,11 +889,14 @@ uint8_t get_stats_keys(memcached_st *memc) return 0; } -uint8_t version_string_test(void) +uint8_t version_string_test(memcached_st *memc) { const char *version_string; + version_string= memcached_lib_version(); + assert(!strcmp(version_string, LIBMEMCACHED_VERSION_STRING)); + return 0; } @@ -1599,6 +1602,43 @@ uint8_t user_supplied_bug11(memcached_st *memc) return 0; } +/* + Bug found where incr was not returning MEMCACHED_NOTFOUND when object did not exist. +*/ +uint8_t user_supplied_bug12(memcached_st *memc) +{ + memcached_return rc; + uint32_t flags; + size_t value_length; + char *value; + uint64_t number_value; + + value= memcached_get(memc, "autoincrement", strlen("autoincrement"), + &value_length, &flags, &rc); + assert(value == NULL); + assert(rc == MEMCACHED_NOTFOUND); + + rc= memcached_increment(memc, "autoincrement", strlen("autoincrement"), + 1, &number_value); + + assert(value == NULL); + assert(rc == MEMCACHED_NOTFOUND); + + rc= memcached_set(memc, "autoincrement", strlen("autoincrement"), "1", 1, 0, 0); + + value= memcached_get(memc, "autoincrement", strlen("autoincrement"), + &value_length, &flags, &rc); + assert(value); + assert(rc == MEMCACHED_SUCCESS); + + rc= memcached_increment(memc, "autoincrement", strlen("autoincrement"), + 1, &number_value); + assert(number_value == 2); + assert(rc == MEMCACHED_SUCCESS); + + return 0; +} + uint8_t result_static(memcached_st *memc) { memcached_result_st result; @@ -2228,6 +2268,7 @@ test_st user_tests[] ={ {"user_supplied_bug9", 1, user_supplied_bug9 }, {"user_supplied_bug10", 1, user_supplied_bug10 }, {"user_supplied_bug11", 1, user_supplied_bug11 }, + {"user_supplied_bug12", 1, user_supplied_bug12 }, {0, 0, 0} }; -- 2.30.2