From 09b4ff9a9b7c62b4511ab10c9305eba757fea34b Mon Sep 17 00:00:00 2001 From: Brian Aker Date: Thu, 26 Apr 2012 19:09:29 -0700 Subject: [PATCH] Update header check. --- ChangeLog | 3 +++ configure.ac | 9 ++++++++- docs/memcached_behavior.rst | 2 +- libmemcached/allocators.cc | 31 +++++++++++++++++++++++-------- libmemcached/analyze.cc | 22 +++++++++++++++------- libmemcached/backtrace.cc | 10 +++++----- libmemcached/common.h | 8 +++++--- libmemcached/error.cc | 13 +++++++------ libmemcached/memcached.cc | 32 +++++++++++++++++++++++++++----- libmemcached/memory.h | 22 ++++++++++++++++++++-- 10 files changed, 114 insertions(+), 38 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4de2dd47..e0807f77 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +1.0.7 +* Add API call for exist calls. + 1.0.6 Sat Apr 7 18:26:49 PDT 2012 * Fixes for gcc 4.7, lp:961812 * Fix for restart issue that happens under testing. diff --git a/configure.ac b/configure.ac index 19c54d5c..ac2b28b3 100644 --- a/configure.ac +++ b/configure.ac @@ -122,15 +122,22 @@ AC_CHECK_FUNCS([strtoul]) AC_CHECK_FUNCS([strtoull]) AC_CHECK_HEADERS([arpa/inet.h]) +AC_CHECK_HEADERS([errno.h]) +AC_CHECK_HEADERS([execinfo.h]) AC_CHECK_HEADERS([fcntl.h]) +AC_CHECK_HEADERS([inttypes.h]) AC_CHECK_HEADERS([libintl.h]) AC_CHECK_HEADERS([limits.h]) AC_CHECK_HEADERS([malloc.h]) +AC_CHECK_HEADERS([math.h]) AC_CHECK_HEADERS([netdb.h]) AC_CHECK_HEADERS([netinet/in.h]) +AC_CHECK_HEADERS([pthread.h]) +AC_CHECK_HEADERS([stdarg.h]) AC_CHECK_HEADERS([stddef.h]) +AC_CHECK_HEADERS([stdlib.h]) AC_CHECK_HEADERS([sys/time.h]) -AC_CHECK_HEADERS([execinfo.h]) +AC_CHECK_HEADERS([unistd.h]) AC_CHECK_HEADERS([cxxabi.h], AC_DEFINE([HAVE_CXXABI_H], [1], [Have cxxabi.h]), AC_DEFINE([HAVE_CXXABI_H], [0], [Have cxxabi.h])) diff --git a/docs/memcached_behavior.rst b/docs/memcached_behavior.rst index ee1bb234..6c401282 100644 --- a/docs/memcached_behavior.rst +++ b/docs/memcached_behavior.rst @@ -143,7 +143,7 @@ Sets the compatibility mode. The value can be set to either MEMCACHED_KETAMA_COM .. c:type:: MEMCACHED_BEHAVIOR_POLL_TIMEOUT -Modify the timeout value that is used by poll. The default value is -1. An signed int pointer must be passed to memcached_behavior_set to change this value. For memcached_behavior_get a signed int value will be cast and returned as the unsigned long long. +Modify the timeout value that is used by poll. The default value is -1. An signed int must be passed to memcached_behavior_set to change this value (this requires casting). For memcached_behavior_get a signed int value will be cast and returned as the unsigned long long. .. c:type:: MEMCACHED_BEHAVIOR_USER_DATA .. deprecated:: < 0.30 diff --git a/libmemcached/allocators.cc b/libmemcached/allocators.cc index 98c87591..aaa66dba 100644 --- a/libmemcached/allocators.cc +++ b/libmemcached/allocators.cc @@ -41,18 +41,18 @@ void _libmemcached_free(const memcached_st*, void *mem, void*) { if (mem) { - free(mem); + std::free(mem); } } void *_libmemcached_malloc(const memcached_st *, size_t size, void *) { - return malloc(size); + return std::malloc(size); } void *_libmemcached_realloc(const memcached_st*, void *mem, size_t size, void *) { - return realloc(mem, size); + return std::realloc(mem, size); } void *_libmemcached_calloc(const memcached_st *self, size_t nelem, size_t size, void *context) @@ -68,7 +68,7 @@ void *_libmemcached_calloc(const memcached_st *self, size_t nelem, size_t size, return ret; } - return calloc(nelem, size); + return std::calloc(nelem, size); } struct memcached_allocator_t memcached_allocators_return_default(void) @@ -126,8 +126,23 @@ void memcached_get_memory_allocators(const memcached_st *self, return; } - *mem_malloc= self->allocators.malloc; - *mem_free= self->allocators.free; - *mem_realloc= self->allocators.realloc; - *mem_calloc= self->allocators.calloc; + if (mem_malloc) + { + *mem_malloc= self->allocators.malloc; + } + + if (mem_free) + { + *mem_free= self->allocators.free; + } + + if (mem_realloc) + { + *mem_realloc= self->allocators.realloc; + } + + if (mem_calloc) + { + *mem_calloc= self->allocators.calloc; + } } diff --git a/libmemcached/analyze.cc b/libmemcached/analyze.cc index 576b6a6b..7115d06f 100644 --- a/libmemcached/analyze.cc +++ b/libmemcached/analyze.cc @@ -42,7 +42,9 @@ static void calc_average_item_size(memcached_analysis_st *result, const uint64_t total_bytes) { if (total_items > 0 && total_bytes > 0) + { result->average_item_size= (uint32_t) (total_bytes / total_items); + } } static void calc_hit_ratio(memcached_analysis_st *result, @@ -65,19 +67,25 @@ memcached_analysis_st *memcached_analyze(memcached_st *memc, { uint64_t total_items= 0, total_bytes= 0; uint64_t total_get_cmds= 0, total_get_hits= 0; - uint32_t server_count; - if (not memc or not memc_stat) + if (memc == NULL or memc_stat == NULL) { return NULL; } + memcached_return_t not_used; + if (error == NULL) + { + error= ¬_used; + } + *error= MEMCACHED_SUCCESS; - server_count= memcached_server_count(memc); - memcached_analysis_st *result= (memcached_analysis_st*)calloc(memcached_server_count(memc), - sizeof(memcached_analysis_st)); + uint32_t server_count= memcached_server_count(memc); + memcached_analysis_st *result= (memcached_analysis_st*)libmemcached_xcalloc(memc, + memcached_server_count(memc), + memcached_analysis_st); - if (not result) + if (result == NULL) { *error= MEMCACHED_MEMORY_ALLOCATION_FAILURE; return NULL; @@ -107,5 +115,5 @@ memcached_analysis_st *memcached_analyze(memcached_st *memc, void memcached_analyze_free(memcached_analysis_st *ptr) { - free(ptr); + libmemcached_free(ptr->root, ptr); } diff --git a/libmemcached/backtrace.cc b/libmemcached/backtrace.cc index 8fb8acc7..3924e0b0 100644 --- a/libmemcached/backtrace.cc +++ b/libmemcached/backtrace.cc @@ -69,11 +69,11 @@ void custom_backtrace(void) fprintf(stderr, "Number of stack frames obtained: %lu\n", (unsigned long)size); - char *named_function= (char *)::realloc(NULL, 1024); + char *named_function= (char *)std::realloc(NULL, 1024); if (named_function == NULL) { - ::free(strings); + std::free(strings); return; } @@ -82,7 +82,7 @@ void custom_backtrace(void) if (USE_DEMANGLE) { size_t sz= 200; - char *named_function_ptr= (char *)::realloc(named_function, sz); + char *named_function_ptr= (char *)std::realloc(named_function, sz); if (named_function_ptr == NULL) { continue; @@ -139,7 +139,7 @@ void custom_backtrace(void) } } - ::free(named_function); - ::free(strings); + std::free(named_function); + std::free(strings); #endif // HAVE_EXECINFO_H } diff --git a/libmemcached/common.h b/libmemcached/common.h index e6b24944..f7559376 100644 --- a/libmemcached/common.h +++ b/libmemcached/common.h @@ -49,17 +49,19 @@ #include #include #include -#include +#include +#include +#include #else #include #include #include #include +#include +#include #endif -#include #include -#include #include #include diff --git a/libmemcached/error.cc b/libmemcached/error.cc index 1ca355b8..b2af961a 100644 --- a/libmemcached/error.cc +++ b/libmemcached/error.cc @@ -208,6 +208,7 @@ memcached_return_t memcached_set_error(memcached_server_st& self, memcached_retu { assert_msg(rc != MEMCACHED_ERRNO, "Programmer error, MEMCACHED_ERRNO was set to be returned to client"); assert_msg(rc != MEMCACHED_SOME_ERRORS, "Programmer error, MEMCACHED_SOME_ERRORS was about to be set on a memcached_server_st"); + memcached_string_t tmp= { str, length }; return memcached_set_error(self, rc, at, tmp); } @@ -458,13 +459,13 @@ static void _error_free(memcached_error_t *error) _error_free(error->next); - if (error && error->root) + if (error and error->root) { libmemcached_free(error->root, error); } else if (error) { - free(error); + libmemcached_free(error->root, error); } } @@ -524,7 +525,7 @@ memcached_return_t memcached_last_error(memcached_st *memc) return MEMCACHED_INVALID_ARGUMENTS; } - if (not memc->error_messages) + if (memc->error_messages == NULL) { return MEMCACHED_SUCCESS; } @@ -539,7 +540,7 @@ int memcached_last_error_errno(memcached_st *memc) return 0; } - if (not memc->error_messages) + if (memc->error_messages == NULL) { return 0; } @@ -554,12 +555,12 @@ const char *memcached_server_error(memcached_server_instance_st server) return NULL; } - if (not server->error_messages) + if (server->error_messages == NULL) { return memcached_strerror(server->root, MEMCACHED_SUCCESS); } - if (not server->error_messages->size) + if (server->error_messages->size == 0) { return memcached_strerror(server->root, server->error_messages->rc); } diff --git a/libmemcached/memcached.cc b/libmemcached/memcached.cc index cd0768eb..2eb91281 100644 --- a/libmemcached/memcached.cc +++ b/libmemcached/memcached.cc @@ -124,7 +124,7 @@ static inline bool _memcached_init(memcached_st *self) return true; } -static void _free(memcached_st *ptr, bool release_st) +static void __memcached_free(memcached_st *ptr, bool release_st) { /* If we have anything open, lets close it now */ send_quit(ptr); @@ -174,7 +174,7 @@ memcached_st *memcached_create(memcached_st *ptr) } else { - ptr= (memcached_st *)malloc(sizeof(memcached_st)); + ptr= (memcached_st *)libmemcached_xmalloc(NULL, memcached_st); if (ptr == NULL) { @@ -244,7 +244,7 @@ memcached_return_t memcached_reset(memcached_st *ptr) bool stored_is_allocated= memcached_is_allocated(ptr); uint64_t query_id= ptr->query_id; - _free(ptr, false); + __memcached_free(ptr, false); memcached_create(ptr); memcached_set_allocated(ptr, stored_is_allocated); ptr->query_id= query_id; @@ -283,7 +283,7 @@ void memcached_free(memcached_st *ptr) { if (ptr) { - _free(ptr, true); + __memcached_free(ptr, true); } } @@ -384,11 +384,21 @@ memcached_st *memcached_clone(memcached_st *clone, const memcached_st *source) void *memcached_get_user_data(const memcached_st *ptr) { + if (ptr == NULL) + { + return NULL; + } + return ptr->user_data; } void *memcached_set_user_data(memcached_st *ptr, void *data) { + if (ptr == NULL) + { + return NULL; + } + void *ret= ptr->user_data; ptr->user_data= data; @@ -402,18 +412,30 @@ memcached_return_t memcached_push(memcached_st *destination, const memcached_st memcached_server_write_instance_st memcached_server_instance_fetch(memcached_st *ptr, uint32_t server_key) { + if (ptr == NULL) + { + return NULL; + } + return &ptr->servers[server_key]; } memcached_server_instance_st memcached_server_instance_by_position(const memcached_st *ptr, uint32_t server_key) { + if (ptr == NULL) + { + return NULL; + } + return &ptr->servers[server_key]; } uint64_t memcached_query_id(const memcached_st *self) { - if (not self) + if (self == NULL) + { return 0; + } return self->query_id; } diff --git a/libmemcached/memory.h b/libmemcached/memory.h index dd009237..06cc9985 100644 --- a/libmemcached/memory.h +++ b/libmemcached/memory.h @@ -36,6 +36,8 @@ #pragma once +#include + #include #ifdef __cplusplus @@ -54,7 +56,11 @@ static inline void libmemcached_free(const memcached_st *self, void *mem) } else if (mem) { +#ifdef __cplusplus + std::free(mem); +#else free(mem); +#endif } } @@ -65,7 +71,11 @@ static inline void *libmemcached_malloc(const memcached_st *self, const size_t s return self->allocators.malloc(self, size, self->allocators.context); } +#ifdef __cplusplus + return std::malloc(size); +#else return malloc(size); +#endif } #define libmemcached_xmalloc(__memcachd_st, __type) ((__type *)libmemcached_malloc((__memcachd_st), sizeof(__type))) @@ -76,7 +86,11 @@ static inline void *libmemcached_realloc(const memcached_st *self, void *mem, si return self->allocators.realloc(self, mem, nmemb * size, self->allocators.context); } - return realloc(mem, size); +#ifdef __cplusplus + return std::realloc(mem, size); +#else + return realloc(mem, size); +#endif } #define libmemcached_xrealloc(__memcachd_st, __mem, __nelem, __type) ((__type *)libmemcached_realloc((__memcachd_st), (__mem), (__nelem), sizeof(__type))) #define libmemcached_xvalloc(__memcachd_st, __nelem, __type) ((__type *)libmemcached_realloc((__memcachd_st), NULL, (__nelem), sizeof(__type))) @@ -88,6 +102,10 @@ static inline void *libmemcached_calloc(const memcached_st *self, size_t nelem, return self->allocators.calloc(self, nelem, size, self->allocators.context); } - return calloc(nelem, size); +#ifdef __cplusplus + return std::calloc(nelem, size); +#else + return calloc(nelem, size); +#endif } #define libmemcached_xcalloc(__memcachd_st, __nelem, __type) ((__type *)libmemcached_calloc((__memcachd_st), (__nelem), sizeof(__type))) -- 2.30.2