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

Use the same assert code in libvarnishapi as in libvarnish



git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@4884 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 49ef6b71
......@@ -367,7 +367,7 @@ void
PAN_Init(void)
{
lbv_assert = pan_ic;
vas_fail = pan_ic;
vsp = &vsps;
AN(vsb_new(vsp, loghead->panicstr, sizeof loghead->panicstr,
VSB_FIXEDLEN));
......
......@@ -902,7 +902,7 @@ VRT_panic(struct sess *sp, const char *str, ...)
va_start(ap, str);
b = vrt_assemble_string(sp->http, "PANIC: ", str, ap);
va_end(ap);
lbv_assert("VCL", "", 0, b, 0, 2);
vas_fail("VCL", "", 0, b, 0, 2);
}
/*--------------------------------------------------------------------*/
......
......@@ -29,6 +29,7 @@ nobase_noinst_HEADERS = \
persistent.h \
purge_vars.h \
svnid.h \
vas.h \
vsha256.h \
vqueue.h \
vpf.h \
......
......@@ -33,6 +33,8 @@
#include <time.h>
#include <stdint.h>
#include "vas.h"
#ifndef NULL
#define NULL ((void*)0)
#endif
......@@ -103,48 +105,6 @@ void varnish_version(const char *);
int vtmpfile(char *);
char *vreadfile(const char *fn);
/*
* assert(), AN() and AZ() are static checks that should not happen.
* In general asserts should be cheap, such as checking return
* values and similar.
* diagnostic() are asserts which are so expensive that we may want
* to compile them out for performance at a later date.
* xxxassert(), XXXAN() and XXXAZ() marks conditions we ought to
* 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, 0); \
} while (0)
#endif
#define xxxassert(e) \
do { \
if (!(e)) \
lbv_assert(__func__, __FILE__, __LINE__, #e, errno, 1); \
} while (0)
/* Assert zero return value */
#define AZ(foo) do { assert((foo) == 0); } while (0)
#define AN(foo) do { assert((foo) != 0); } while (0)
#define XXXAZ(foo) do { xxxassert((foo) == 0); } while (0)
#define XXXAN(foo) do { xxxassert((foo) != 0); } while (0)
#define diagnostic(foo) assert(foo)
#define WRONG(expl) \
do { \
lbv_assert(__func__, __FILE__, __LINE__, expl, errno, 3); \
abort(); \
} while (0)
const char* svn_version(void);
/* Safe printf into a fixed-size buffer */
......
/*-
* Copyright (c) 2006 Verdens Gang AS
* Copyright (c) 2006-2009 Linpro AS
* All rights reserved.
*
* Author: Poul-Henning Kamp <phk@phk.freebsd.dk>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id$
*
* assert(), AN() and AZ() are static checks that should not happen.
* In general asserts should be cheap, such as checking return
* values and similar.
* diagnostic() are asserts which are so expensive that we may want
* to compile them out for performance at a later date.
* xxxassert(), XXXAN() and XXXAZ() marks conditions we ought to
* handle gracefully, such as malloc failure.
*/
#ifndef VAS_H_INCLUDED
#define VAS_H_INCLUDED
#include <errno.h>
typedef void vas_f(const char *, const char *, int, const char *, int, int);
extern vas_f *vas_fail;
#ifdef WITHOUT_ASSERTS
#define assert(e) ((void)(e))
#else /* WITH_ASSERTS */
#define assert(e) \
do { \
if (!(e)) \
vas_fail(__func__, __FILE__, __LINE__, #e, errno, 0); \
} while (0)
#endif
#define xxxassert(e) \
do { \
if (!(e)) \
vas_fail(__func__, __FILE__, __LINE__, #e, errno, 1); \
} while (0)
/* Assert zero return value */
#define AZ(foo) do { assert((foo) == 0); } while (0)
#define AN(foo) do { assert((foo) != 0); } while (0)
#define XXXAZ(foo) do { xxxassert((foo) == 0); } while (0)
#define XXXAN(foo) do { xxxassert((foo) != 0); } while (0)
#define diagnostic(foo) assert(foo)
#define WRONG(expl) \
do { \
vas_fail(__func__, __FILE__, __LINE__, expl, errno, 3); \
abort(); \
} while (0)
#endif
......@@ -41,7 +41,7 @@ SVNID("$Id$")
#include "libvarnish.h"
static void
lbv_assert_default(const char *func, const char *file, int line,
vas_fail_default(const char *func, const char *file, int line,
const char *cond, int err, int xxx)
{
......@@ -62,4 +62,4 @@ lbv_assert_default(const char *func, const char *file, int line,
abort();
}
lbv_assert_f *lbv_assert = lbv_assert_default;
vas_f *vas_fail = vas_fail_default;
......@@ -115,7 +115,7 @@ str2bytes(const char *p, uintmax_t *r, uintmax_t rel)
#ifdef NUM_C_TEST
/* Compile with: "cc -o foo -DNUM_C_TEST -I../.. -I../../include num.c -lm" */
#include <assert.h>
#include "vas.h"
#include <math.h>
#include <stdio.h>
#include <string.h>
......
......@@ -10,6 +10,7 @@ libvarnishapi_la_SOURCES = \
vsl.h \
\
../libvarnish/vin.c \
../libvarnish/assert.c \
base64.c \
vsl.c \
vsl_arg.c \
......
......@@ -36,7 +36,6 @@ SVNID("$Id$")
#include <sys/mman.h>
#include <sys/stat.h>
#include <assert.h>
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
......@@ -44,6 +43,7 @@ SVNID("$Id$")
#include <string.h>
#include <unistd.h>
#include "vas.h"
#include "shmlog.h"
#include "vre.h"
#include "vbm.h"
......
......@@ -35,7 +35,6 @@ SVNID("$Id$")
#include <sys/types.h>
#include <sys/stat.h>
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
......@@ -44,6 +43,7 @@ SVNID("$Id$")
#include <string.h>
#include <unistd.h>
#include "vas.h"
#include "shmlog.h"
#include "vre.h"
#include "vbm.h"
......
......@@ -35,12 +35,12 @@ SVNID("$Id$")
#include <sys/types.h>
#include <sys/stat.h>
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "vas.h"
#include "shmlog.h"
#include "vre.h"
#include "vbm.h"
......
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