From: phk Date: Sun, 20 Jul 2008 10:03:42 +0000 (+0000) Subject: Make the backend function of libvarnish' assert facilities pluggable. X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9682b07008591ccdf1b4c531bb3018f6f4a92d7e;p=varnish Make the backend function of libvarnish' assert facilities pluggable. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@2970 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- diff --git a/varnish-cache/include/libvarnish.h b/varnish-cache/include/libvarnish.h index e68d21a3..15acdc68 100644 --- a/varnish-cache/include/libvarnish.h +++ b/varnish-cache/include/libvarnish.h @@ -72,25 +72,26 @@ int vtmpfile(char *); * 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 #define assert(e) ((void)(e)) #else /* WITH_ASSERTS */ #define assert(e) \ do { \ if (!(e)) \ - lbv_assert(__func__, __FILE__, __LINE__, #e, errno); \ + lbv_assert(__func__, __FILE__, __LINE__, #e, errno, 0); \ } while (0) #endif #define xxxassert(e) \ do { \ if (!(e)) \ - lbv_xxxassert(__func__, __FILE__, __LINE__, #e, errno); \ + lbv_assert(__func__, __FILE__, __LINE__, #e, errno, 1); \ } 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 */ #define AZ(foo) do { assert((foo) == 0); } while (0) #define AN(foo) do { assert((foo) != 0); } while (0) diff --git a/varnish-cache/lib/libvarnish/assert.c b/varnish-cache/lib/libvarnish/assert.c index b9ea7399..405548a7 100644 --- a/varnish-cache/lib/libvarnish/assert.c +++ b/varnish-cache/lib/libvarnish/assert.c @@ -27,6 +27,8 @@ * SUCH DAMAGE. * * $Id$ + * + * This is the default backend function for libvarnish' assert facilities. */ #include "config.h" @@ -37,30 +39,25 @@ #include "libvarnish.h" -void -lbv_xxxassert(const char *func, const char *file, int line, const char *cond, int err) +static void +lbv_assert_default(const char *func, const char *file, int line, const char *cond, int err, int xxx) { - fprintf(stderr, - "Missing errorhandling code in %s(), %s line %d:\n" - " Condition(%s) not true.\n", - func, file, line, cond); - if (err) + if (xxx) { fprintf(stderr, - " errno = %d (%s)\n", err, strerror(err)); - abort(); -} - -void -lbv_assert(const char *func, const char *file, int line, const char *cond, int err) -{ - - fprintf(stderr, - "Assert error in %s(), %s line %d:\n" - " Condition(%s) not true.\n", - func, file, line, cond); + "Missing errorhandling code in %s(), %s line %d:\n" + " Condition(%s) not true.\n", + func, file, line, cond); + } else { + fprintf(stderr, + "Assert error in %s(), %s line %d:\n" + " Condition(%s) not true.\n", + func, file, line, cond); + } if (err) fprintf(stderr, " errno = %d (%s)\n", err, strerror(err)); abort(); } + +lbv_assert_f *lbv_assert = lbv_assert_default;