From: Brian Aker Date: Sun, 16 Sep 2012 21:01:09 +0000 (-0400) Subject: Fix situation where test case might bomb if not enough memory is available. X-Git-Tag: 1.0.11~1^2 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=af788b4b866ef0220dcdc4c357efbcbdb942cd27;p=awesomized%2Flibmemcached Fix situation where test case might bomb if not enough memory is available. --- diff --git a/libmemcached-1.0/error.h b/libmemcached-1.0/error.h index 81492597..7fdc18b8 100644 --- a/libmemcached-1.0/error.h +++ b/libmemcached-1.0/error.h @@ -41,6 +41,9 @@ extern "C" { #endif +LIBMEMCACHED_API + const char *memcached_error(const memcached_st *); + LIBMEMCACHED_API const char *memcached_last_error_message(const memcached_st *); diff --git a/libmemcached/error.cc b/libmemcached/error.cc index 99316f1d..6ae5cba1 100644 --- a/libmemcached/error.cc +++ b/libmemcached/error.cc @@ -495,24 +495,29 @@ void memcached_error_free(memcached_server_st& self) self.error_messages= NULL; } +const char *memcached_error(const memcached_st *memc) +{ + return memcached_last_error_message(memc); +} + const char *memcached_last_error_message(const memcached_st *memc) { - if (memc == NULL) + if (memc) { - return memcached_strerror(memc, MEMCACHED_INVALID_ARGUMENTS); - } + if (memc->error_messages) + { + if (memc->error_messages->size == 0) + { + return memc->error_messages->message; + } - if (memc->error_messages == NULL) - { - return memcached_strerror(memc, MEMCACHED_SUCCESS); - } + return memcached_strerror(memc, memc->error_messages->rc); + } - if (memc->error_messages->size == 0) - { - return memcached_strerror(memc, memc->error_messages->rc); + return memcached_strerror(memc, MEMCACHED_SUCCESS); } - return memc->error_messages->message; + return memcached_strerror(memc, MEMCACHED_INVALID_ARGUMENTS); } bool memcached_has_current_error(memcached_st &memc) @@ -534,17 +539,17 @@ bool memcached_has_current_error(org::libmemcached::Instance& server) memcached_return_t memcached_last_error(const memcached_st *memc) { - if (memc == NULL) + if (memc) { - return MEMCACHED_INVALID_ARGUMENTS; - } + if (memc->error_messages) + { + return memc->error_messages->rc; + } - if (memc->error_messages == NULL) - { return MEMCACHED_SUCCESS; } - return memc->error_messages->rc; + return MEMCACHED_INVALID_ARGUMENTS; } int memcached_last_error_errno(const memcached_st *memc) diff --git a/tests/libmemcached-1.0/mem_functions.cc b/tests/libmemcached-1.0/mem_functions.cc index d439e35e..a6adac1b 100644 --- a/tests/libmemcached-1.0/mem_functions.cc +++ b/tests/libmemcached-1.0/mem_functions.cc @@ -1754,6 +1754,11 @@ test_return_t block_add_regression(memcached_st *memc) global_pairs[x].key, global_pairs[x].key_length, &blob[0], blob.size(), time_t(0), uint32_t(0)); + if (rc == MEMCACHED_MEMORY_ALLOCATION_FAILURE) + { + Error << memcached_last_error_message(memc); + return TEST_SKIPPED; + } test_compare(*memc, MEMCACHED_SUCCESS); test_compare(rc, MEMCACHED_SUCCESS); }