* 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)
* SUCH DAMAGE.
*
* $Id$
+ *
+ * This is the default backend function for libvarnish' assert facilities.
*/
#include "config.h"
#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;