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

Move INCOMPL() into the VAS family and apply a bit of polish while there.

parent 158b428a
......@@ -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 */
......
......@@ -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",
......
......@@ -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;
......@@ -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
......@@ -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;
......@@ -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)
......
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