[experimental-ims] f5fe417 Move INCOMPL() into the VAS family and apply a bit of polish while there.
Poul-Henning Kamp
phk at FreeBSD.org
Thu Dec 18 10:27:53 CET 2014
commit f5fe41770bc33069377a11a4032a32faa8452f9f
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Tue Aug 14 07:03:18 2012 +0000
Move INCOMPL() into the VAS family and apply a bit of polish while there.
diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index 35c2b52..add0150 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -984,13 +984,6 @@ void VSL_Flush(struct vsl_log *, int overflow);
VSL((tag), (id), __VA_ARGS__); \
} while (0)
-#define INCOMPL() do { \
- VSL(SLT_Debug, 0, "INCOMPLETE AT: %s(%d)", __func__, __LINE__); \
- fprintf(stderr, \
- "INCOMPLETE AT: %s(%d)\n", \
- (const char *)__func__, __LINE__); \
- abort(); \
- } while (0)
#endif
/* cache_response.c */
diff --git a/bin/varnishd/cache/cache_panic.c b/bin/varnishd/cache/cache_panic.c
index c38da38..e6b0941 100644
--- a/bin/varnishd/cache/cache_panic.c
+++ b/bin/varnishd/cache/cache_panic.c
@@ -343,9 +343,9 @@ pan_backtrace(void)
/*--------------------------------------------------------------------*/
-static void
+static void __attribute__((__noreturn__))
pan_ic(const char *func, const char *file, int line, const char *cond,
- int err, int xxx)
+ int err, enum vas_e kind)
{
const char *q;
const struct req *req;
@@ -353,23 +353,28 @@ pan_ic(const char *func, const char *file, int line, const char *cond,
AZ(pthread_mutex_lock(&panicstr_mtx)); /* Won't be released,
we're going to die
anyway */
- switch(xxx) {
- case 3:
+ switch(kind) {
+ case VAS_WRONG:
VSB_printf(pan_vsp,
"Wrong turn at %s:%d:\n%s\n", file, line, cond);
break;
- case 2:
+ case VAS_VCL:
VSB_printf(pan_vsp,
"Panic from VCL:\n %s\n", cond);
break;
- case 1:
+ case VAS_MISSING:
VSB_printf(pan_vsp,
"Missing errorhandling code in %s(), %s line %d:\n"
" Condition(%s) not true.",
func, file, line, cond);
break;
+ case VAS_INCOMPLETE:
+ VSB_printf(pan_vsp,
+ "Incomplete code in %s(), %s line %d:\n",
+ func, file, line);
+ break;
default:
- case 0:
+ case VAS_ASSERT:
VSB_printf(pan_vsp,
"Assert error in %s(), %s line %d:\n"
" Condition(%s) not true.\n",
diff --git a/bin/varnishtest/vtc_log.c b/bin/varnishtest/vtc_log.c
index 402b49f..1fc3760 100644
--- a/bin/varnishtest/vtc_log.c
+++ b/bin/varnishtest/vtc_log.c
@@ -285,14 +285,14 @@ vtc_hexdump(struct vtclog *vl, int lvl, const char *pfx,
/**********************************************************************/
-static void
+static void __attribute__((__noreturn__))
vtc_log_VAS_Fail(const char *func, const char *file, int line,
- const char *cond, int err, int xxx)
+ const char *cond, int err, enum vas_e why)
{
struct vtclog *vl;
(void)err;
- (void)xxx;
+ (void)why;
vl = pthread_getspecific(log_key);
if (vl == NULL || vl->act) {
fprintf(stderr,
@@ -303,6 +303,7 @@ vtc_log_VAS_Fail(const char *func, const char *file, int line,
vtc_log(vl, 0, "Assert error in %s(), %s line %d:"
" Condition(%s) not true.\n", func, file, line, cond);
}
+ abort();
}
-vas_f *VAS_Fail = vtc_log_VAS_Fail;
+vas_f *VAS_Fail __attribute__((__noreturn__)) = vtc_log_VAS_Fail;
diff --git a/include/vas.h b/include/vas.h
index ff20036..246acc1 100644
--- a/include/vas.h
+++ b/include/vas.h
@@ -38,24 +38,37 @@
#ifndef VAS_H_INCLUDED
#define VAS_H_INCLUDED
-typedef void vas_f(const char *, const char *, int, const char *, int, int);
+enum vas_e {
+ VAS_WRONG,
+ VAS_MISSING,
+ VAS_ASSERT,
+ VAS_INCOMPLETE,
+ VAS_VCL,
+};
-extern vas_f *VAS_Fail;
+typedef void vas_f(const char *, const char *, int, const char *, int,
+ enum vas_e);
+
+extern vas_f *VAS_Fail __attribute__((__noreturn__));
#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); \
+ if (!(e)) { \
+ VAS_Fail(__func__, __FILE__, __LINE__, \
+ #e, errno, VAS_ASSERT); \
+ } \
} while (0)
#endif
#define xxxassert(e) \
do { \
- if (!(e)) \
- VAS_Fail(__func__, __FILE__, __LINE__, #e, errno, 1); \
+ if (!(e)) { \
+ VAS_Fail(__func__, __FILE__, __LINE__, \
+ #e, errno, VAS_MISSING); \
+ } \
} while (0)
/* Assert zero return value */
@@ -66,8 +79,13 @@ do { \
#define diagnostic(foo) assert(foo)
#define WRONG(expl) \
do { \
- VAS_Fail(__func__, __FILE__, __LINE__, expl, errno, 3); \
- abort(); \
+ VAS_Fail(__func__, __FILE__, __LINE__, expl, errno, VAS_WRONG); \
+} while (0)
+
+#define INCOMPL() \
+do { \
+ VAS_Fail(__func__, __FILE__, __LINE__, \
+ "", errno, VAS_INCOMPLETE); \
} while (0)
#endif
diff --git a/lib/libvarnish/vas.c b/lib/libvarnish/vas.c
index 6f69928..d63763d 100644
--- a/lib/libvarnish/vas.c
+++ b/lib/libvarnish/vas.c
@@ -37,16 +37,24 @@
#include "vas.h"
-static void
+static void __attribute__((__noreturn__))
VAS_Fail_default(const char *func, const char *file, int line,
- const char *cond, int err, int xxx)
+ const char *cond, int err, enum vas_e kind)
{
- if (xxx) {
+ if (kind == VAS_MISSING) {
fprintf(stderr,
"Missing errorhandling code in %s(), %s line %d:\n"
" Condition(%s) not true.\n",
func, file, line, cond);
+ } else if (kind == VAS_INCOMPLETE) {
+ fprintf(stderr,
+ "Incompelte code in %s(), %s line %d:\n",
+ func, file, line);
+ } else if (kind == VAS_WRONG) {
+ fprintf(stderr,
+ "Wrong turn in %s(), %s line %d:\n",
+ func, file, line);
} else {
fprintf(stderr,
"Assert error in %s(), %s line %d:\n"
@@ -59,4 +67,4 @@ VAS_Fail_default(const char *func, const char *file, int line,
abort();
}
-vas_f *VAS_Fail = VAS_Fail_default;
+vas_f *VAS_Fail __attribute__((__noreturn__)) = VAS_Fail_default;
diff --git a/lib/libvmod_debug/vmod_debug.c b/lib/libvmod_debug/vmod_debug.c
index cd23473..fd1a135 100644
--- a/lib/libvmod_debug/vmod_debug.c
+++ b/lib/libvmod_debug/vmod_debug.c
@@ -45,7 +45,7 @@ vmod_panic(struct req *req, const char *str, ...)
va_start(ap, str);
b = VRT_String(req->http->ws, "PANIC: ", str, ap);
va_end(ap);
- VAS_Fail("VCL", "", 0, b, 0, 2);
+ VAS_Fail("VCL", "", 0, b, 0, VAS_VCL);
}
const char * __match_proto__(td_debug_author)
More information about the varnish-commit
mailing list