From: Brian Aker Date: Wed, 14 Sep 2011 04:54:24 +0000 (-0700) Subject: Fix --disable-assert, lp:829810 X-Git-Tag: 0.53~18 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=9a6c3f77b862f9d7bf05926989c501cac2476c71;p=awesomized%2Flibmemcached Fix --disable-assert, lp:829810 --- diff --git a/libhashkit/hashkit.cc b/libhashkit/hashkit.cc index 7f3514d1..96e39515 100644 --- a/libhashkit/hashkit.cc +++ b/libhashkit/hashkit.cc @@ -23,7 +23,7 @@ static inline hashkit_st *_hashkit_create(hashkit_st *self) { if (not self) { - self= new hashkit_st; + self= (hashkit_st*)calloc(1, sizeof(hashkit_st)); if (not self) { return NULL; @@ -55,7 +55,7 @@ void hashkit_free(hashkit_st *self) { if (hashkit_is_allocated(self)) { - delete self; + free(self); } } diff --git a/libmemcached/assert.hpp b/libmemcached/assert.hpp index acd0198e..787d844a 100644 --- a/libmemcached/assert.hpp +++ b/libmemcached/assert.hpp @@ -41,7 +41,7 @@ #include #ifdef NDEBUG -#define assert(__expr, __mesg) ((void)0) +#define assert_msg(__expr, __mesg) (void)(__expr); (void)(__mesg); #else #define assert_msg(__expr, __mesg) \ diff --git a/libmemcached/behavior.cc b/libmemcached/behavior.cc index 2a1e7537..6036aebd 100644 --- a/libmemcached/behavior.cc +++ b/libmemcached/behavior.cc @@ -250,10 +250,10 @@ memcached_return_t memcached_behavior_set(memcached_st *ptr, case MEMCACHED_BEHAVIOR_MAX: default: - /* Shouldn't get here */ - assert_msg(0, "Invalid behavior passed to memcached_behavior_set()"); - return memcached_set_error(*ptr, MEMCACHED_INVALID_ARGUMENTS, MEMCACHED_AT, - memcached_literal_param("Invalid behavior passed to memcached_behavior_set()")); + /* Shouldn't get here */ + assert_msg(0, "Invalid behavior passed to memcached_behavior_set()"); + return memcached_set_error(*ptr, MEMCACHED_INVALID_ARGUMENTS, MEMCACHED_AT, + memcached_literal_param("Invalid behavior passed to memcached_behavior_set()")); } return MEMCACHED_SUCCESS; diff --git a/libmemcached/hosts.cc b/libmemcached/hosts.cc index 5c4cf175..179b7c29 100644 --- a/libmemcached/hosts.cc +++ b/libmemcached/hosts.cc @@ -219,7 +219,7 @@ static memcached_return_t update_continuum(memcached_st *ptr) if (is_ketama_weighted) { float pct= (float)list[host_index].weight / (float)total_weight; - pointer_per_server= (uint32_t) ((floorf((float) (pct * MEMCACHED_POINTS_PER_SERVER_KETAMA / 4 * (float)live_servers + 0.0000000001))) * 4); + pointer_per_server= (uint32_t) ((floor((float) (pct * MEMCACHED_POINTS_PER_SERVER_KETAMA / 4 * (float)live_servers + 0.0000000001))) * 4); pointer_per_hash= 4; if (DEBUG) { diff --git a/libmemcached/protocol/cache.h b/libmemcached/protocol/cache.h index a96fba99..6f84feaa 100644 --- a/libmemcached/protocol/cache.h +++ b/libmemcached/protocol/cache.h @@ -1,22 +1,56 @@ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * Libmemcached library + * + * Copyright (C) 2011 Data Differential, http://datadifferential.com/ + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * + * * The names of its contributors may not be used to endorse or + * promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + /* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ -#ifndef CACHE_H -#define CACHE_H +#pragma once + #include #ifdef HAVE_UMEM_H -#include -#define cache_t umem_cache_t -#define cache_alloc(a) umem_cache_alloc(a, UMEM_DEFAULT) -#define cache_free(a, b) umem_cache_free(a, b) -#define cache_create(a,b,c,d,e) umem_cache_create((char*)a, b, c, d, e, NULL, NULL, NULL, 0) -#define cache_destroy(a) umem_cache_destroy(a); - +# include +# define cache_t umem_cache_t +# define cache_alloc(a) umem_cache_alloc(a, UMEM_DEFAULT) +# define cache_free(a, b) umem_cache_free(a, b) +# define cache_create(a,b,c,d,e) umem_cache_create((char*)a, b, c, d, e, NULL, NULL, NULL, 0) +# define cache_destroy(a) umem_cache_destroy(a); #else - -#ifndef NDEBUG +# ifndef NDEBUG /* may be used for debug purposes */ extern int cache_error; -#endif +# endif /** * Constructor used to initialize allocated objects @@ -111,6 +145,4 @@ void* cache_alloc(cache_t* handle); * @param ptr pointer to the object to return. */ void cache_free(cache_t* handle, void* ptr); -#endif - -#endif +#endif // HAVE_UMEM_H diff --git a/m4/pandora_have_libgtest.m4 b/m4/pandora_have_libgtest.m4 deleted file mode 100644 index fe269fb1..00000000 --- a/m4/pandora_have_libgtest.m4 +++ /dev/null @@ -1,47 +0,0 @@ -dnl Copyright (C) 2010 Monty Taylor -dnl This file is free software; Monty Taylor -dnl gives unlimited permission to copy and/or distribute it, -dnl with or without modifications, as long as this notice is preserved. - -AC_DEFUN([_PANDORA_SEARCH_LIBGTEST],[ - AC_REQUIRE([AC_LIB_PREFIX]) - - dnl -------------------------------------------------------------------- - dnl Check for libgtest - dnl -------------------------------------------------------------------- - - AC_ARG_ENABLE([libgtest], - [AS_HELP_STRING([--disable-libgtest], - [Build with libgtest support @<:@default=on@:>@])], - [ac_enable_libgtest="$enableval"], - [ac_enable_libgtest="yes"]) - - AS_IF([test "x$ac_enable_libgtest" = "xyes"],[ - AC_LANG_PUSH(C++) - save_CXXFLAGS="${CXXFLAGS}" - CXXFLAGS="${AM_CXXFLAGS} ${CXXFLAGS}" - AC_LIB_HAVE_LINKFLAGS(gtest,,[ - #include -TEST(pandora_test_libgtest, PandoraTest) -{ - ASSERT_EQ(1, 1); -} - ],[]) - CXXFLAGS="${save_CXXFLAGS}" - AC_LANG_POP() - ],[ - ac_cv_libgtest="no" - ]) - - AM_CONDITIONAL(HAVE_LIBGTEST, [test "x${ac_cv_libgtest}" = "xyes"]) -]) - -AC_DEFUN([PANDORA_HAVE_LIBGTEST],[ - AC_REQUIRE([_PANDORA_SEARCH_LIBGTEST]) -]) - -AC_DEFUN([PANDORA_REQUIRE_LIBGTEST],[ - AC_REQUIRE([_PANDORA_SEARCH_LIBGTEST]) - AS_IF([test "x${ac_cv_libgtest}" = "xno"], - AC_MSG_ERROR([libgtest is required for ${PACKAGE}])) -]) diff --git a/tests/hashkit_functions.cc b/tests/hashkit_functions.cc index c8ca5241..12cd3988 100644 --- a/tests/hashkit_functions.cc +++ b/tests/hashkit_functions.cc @@ -192,7 +192,7 @@ static test_return_t crc_run (hashkit_st *hashk) uint32_t hash_val; hash_val= libhashkit_crc32(*ptr, strlen(*ptr)); - assert(crc_values[x] == hash_val); + test_compare(crc_values[x], hash_val); } return TEST_SUCCESS; @@ -209,7 +209,7 @@ static test_return_t fnv1_64_run (hashkit_st *hashk) uint32_t hash_val; hash_val= libhashkit_fnv1_64(*ptr, strlen(*ptr)); - assert(fnv1_64_values[x] == hash_val); + test_compare(fnv1_64_values[x], hash_val); } return TEST_SUCCESS; @@ -226,7 +226,7 @@ static test_return_t fnv1a_64_run (hashkit_st *hashk) uint32_t hash_val; hash_val= libhashkit_fnv1a_64(*ptr, strlen(*ptr)); - assert(fnv1a_64_values[x] == hash_val); + test_compare(fnv1a_64_values[x], hash_val); } return TEST_SUCCESS; @@ -243,7 +243,7 @@ static test_return_t fnv1_32_run (hashkit_st *hashk) uint32_t hash_val; hash_val= libhashkit_fnv1_32(*ptr, strlen(*ptr)); - assert(fnv1_32_values[x] == hash_val); + test_compare(fnv1_32_values[x], hash_val); } return TEST_SUCCESS; @@ -260,7 +260,7 @@ static test_return_t fnv1a_32_run (hashkit_st *hashk) uint32_t hash_val; hash_val= libhashkit_fnv1a_32(*ptr, strlen(*ptr)); - assert(fnv1a_32_values[x] == hash_val); + test_compare(fnv1a_32_values[x], hash_val); } return TEST_SUCCESS; @@ -281,7 +281,7 @@ static test_return_t hsieh_run (hashkit_st *hashk) #else hash_val= 1; #endif - assert(hsieh_values[x] == hash_val); + test_compare(hsieh_values[x], hash_val); } return TEST_SUCCESS; @@ -307,7 +307,7 @@ static test_return_t murmur_run (hashkit_st *hashk) #else hash_val= 1; #endif - assert(murmur_values[x] == hash_val); + test_compare(murmur_values[x], hash_val); } return TEST_SUCCESS; @@ -325,7 +325,7 @@ static test_return_t jenkins_run (hashkit_st *hashk) uint32_t hash_val; hash_val= libhashkit_jenkins(*ptr, strlen(*ptr)); - assert(jenkins_values[x] == hash_val); + test_compare(jenkins_values[x], hash_val); } return TEST_SUCCESS;