X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=libmemcached%2Fassert.hpp;h=cd4a194b2b1ce305e074e5f090ca82abead4d2ee;hb=dbc62573e1a6dc8cbcc97d0898e8615b0916d6ab;hp=6858879c180faeddc8f33608224c2e5135d21593;hpb=920b0f21e75bb5b145a7de7383f5ae8c4a2c358a;p=awesomized%2Flibmemcached diff --git a/libmemcached/assert.hpp b/libmemcached/assert.hpp index 6858879c..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,14 +37,34 @@ #pragma once -#include -#include +#ifdef __cplusplus +# include +#else +# include +#endif // __cplusplus #ifdef NDEBUG -#define assert_msg(__expr, __mesg) (void)(__expr); (void)(__mesg); +# 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)) \ @@ -55,4 +75,19 @@ do \ } \ } 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