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 *);
* 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)
......
......@@ -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;
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