Commit bb974b0f authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Make the backend function of libvarnish' assert facilities pluggable.



git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@2970 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 3c177933
...@@ -72,25 +72,26 @@ int vtmpfile(char *); ...@@ -72,25 +72,26 @@ int vtmpfile(char *);
* handle gracefully, such as malloc failure. * handle gracefully, such as malloc failure.
*/ */
typedef void lbv_assert_f(const char *, const char *, int, const char *, int, int);
extern lbv_assert_f *lbv_assert;
#ifdef WITHOUT_ASSERTS #ifdef WITHOUT_ASSERTS
#define assert(e) ((void)(e)) #define assert(e) ((void)(e))
#else /* WITH_ASSERTS */ #else /* WITH_ASSERTS */
#define assert(e) \ #define assert(e) \
do { \ do { \
if (!(e)) \ if (!(e)) \
lbv_assert(__func__, __FILE__, __LINE__, #e, errno); \ lbv_assert(__func__, __FILE__, __LINE__, #e, errno, 0); \
} while (0) } while (0)
#endif #endif
#define xxxassert(e) \ #define xxxassert(e) \
do { \ do { \
if (!(e)) \ if (!(e)) \
lbv_xxxassert(__func__, __FILE__, __LINE__, #e, errno); \ lbv_assert(__func__, __FILE__, __LINE__, #e, errno, 1); \
} while (0) } while (0)
void lbv_assert(const char *, const char *, int, const char *, int);
void lbv_xxxassert(const char *, const char *, int, const char *, int);
/* Assert zero return value */ /* Assert zero return value */
#define AZ(foo) do { assert((foo) == 0); } while (0) #define AZ(foo) do { assert((foo) == 0); } while (0)
#define AN(foo) do { assert((foo) != 0); } while (0) #define AN(foo) do { assert((foo) != 0); } while (0)
......
...@@ -27,6 +27,8 @@ ...@@ -27,6 +27,8 @@
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* $Id$ * $Id$
*
* This is the default backend function for libvarnish' assert facilities.
*/ */
#include "config.h" #include "config.h"
...@@ -37,30 +39,25 @@ ...@@ -37,30 +39,25 @@
#include "libvarnish.h" #include "libvarnish.h"
void static void
lbv_xxxassert(const char *func, const char *file, int line, const char *cond, int err) lbv_assert_default(const char *func, const char *file, int line, const char *cond, int err, int xxx)
{ {
fprintf(stderr, if (xxx) {
"Missing errorhandling code in %s(), %s line %d:\n"
" Condition(%s) not true.\n",
func, file, line, cond);
if (err)
fprintf(stderr, fprintf(stderr,
" errno = %d (%s)\n", err, strerror(err)); "Missing errorhandling code in %s(), %s line %d:\n"
abort(); " Condition(%s) not true.\n",
} func, file, line, cond);
} else {
void fprintf(stderr,
lbv_assert(const char *func, const char *file, int line, const char *cond, int err) "Assert error in %s(), %s line %d:\n"
{ " Condition(%s) not true.\n",
func, file, line, cond);
fprintf(stderr, }
"Assert error in %s(), %s line %d:\n"
" Condition(%s) not true.\n",
func, file, line, cond);
if (err) if (err)
fprintf(stderr, fprintf(stderr,
" errno = %d (%s)\n", err, strerror(err)); " errno = %d (%s)\n", err, strerror(err));
abort(); abort();
} }
lbv_assert_f *lbv_assert = lbv_assert_default;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment