X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=libmemcached%2Fassert.hpp;h=cd4a194b2b1ce305e074e5f090ca82abead4d2ee;hb=bb98ce33936edc0dc914652c0227f95727518b16;hp=8a46784ed22803a501e7091e2cb1dc628653fe8e;hpb=7abcaebdc4c3dd11b779eaef58a7371fb82ae888;p=awesomized%2Flibmemcached diff --git a/libmemcached/assert.hpp b/libmemcached/assert.hpp index 8a46784e..cd4a194b 100644 --- a/libmemcached/assert.hpp +++ b/libmemcached/assert.hpp @@ -2,7 +2,7 @@ * * libmcachedd client library. * - * Copyright (C) 2011 Data Differential, http://datadifferential.com/ + * Copyright (C) 2011-2013 Data Differential, http://datadifferential.com/ * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -37,21 +37,57 @@ #pragma once -#include -#include +#ifdef __cplusplus +# include +#else +# include +#endif // __cplusplus #ifdef NDEBUG -#define assert(__expr, __mesg) ((void)0) +# define assert_msg(__expr, __mesg) (void)(__expr); (void)(__mesg); +# define assert_vmsg(__expr, __mesg, ...) (void)(__expr); (void)(__mesg); +#else + +# ifdef _WIN32 +# include +# else +# include +# endif + +#ifdef __cplusplus +# include +# include #else +# include +# include +#endif + +# include -#define assert_msg(__expr, __mesg) \ +# define assert_msg(__expr, __mesg) \ do \ { \ if (not (__expr)) \ { \ - fprintf(stderr, "\nAssertion \"%s\" failed for function \"%s\" likely for %s, at %s:%d\n", #__expr, __func__, (#__mesg), __FILE__, __LINE__);\ + fprintf(stderr, "\n%s:%d Assertion \"%s\" failed for function \"%s\" likely for %s\n", __FILE__, __LINE__, #__expr, __func__, (#__mesg));\ + custom_backtrace(); \ abort(); \ } \ } while (0) -#endif +# define assert_vmsg(__expr, __mesg, ...) \ +do \ +{ \ + if (not (__expr)) \ + { \ + size_t ask= snprintf(0, 0, (__mesg), __VA_ARGS__); \ + ask++; \ + char *_error_message= (char*)alloca(sizeof(char) * ask); \ + size_t _error_message_size= snprintf(_error_message, ask, (__mesg), __VA_ARGS__); \ + fprintf(stderr, "\n%s:%d Assertion '%s' failed for function '%s' [ %.*s ]\n", __FILE__, __LINE__, #__expr, __func__, int(_error_message_size), _error_message);\ + custom_backtrace(); \ + abort(); \ + } \ +} while (0) + +#endif // NDEBUG