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); ...@@ -984,13 +984,6 @@ void VSL_Flush(struct vsl_log *, int overflow);
VSL((tag), (id), __VA_ARGS__); \ VSL((tag), (id), __VA_ARGS__); \
} while (0) } 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 #endif
/* cache_response.c */ /* cache_response.c */
......
...@@ -343,9 +343,9 @@ pan_backtrace(void) ...@@ -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, 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 char *q;
const struct req *req; const struct req *req;
...@@ -353,23 +353,28 @@ pan_ic(const char *func, const char *file, int line, const char *cond, ...@@ -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, AZ(pthread_mutex_lock(&panicstr_mtx)); /* Won't be released,
we're going to die we're going to die
anyway */ anyway */
switch(xxx) { switch(kind) {
case 3: case VAS_WRONG:
VSB_printf(pan_vsp, VSB_printf(pan_vsp,
"Wrong turn at %s:%d:\n%s\n", file, line, cond); "Wrong turn at %s:%d:\n%s\n", file, line, cond);
break; break;
case 2: case VAS_VCL:
VSB_printf(pan_vsp, VSB_printf(pan_vsp,
"Panic from VCL:\n %s\n", cond); "Panic from VCL:\n %s\n", cond);
break; break;
case 1: case VAS_MISSING:
VSB_printf(pan_vsp, VSB_printf(pan_vsp,
"Missing errorhandling code in %s(), %s line %d:\n" "Missing errorhandling code in %s(), %s line %d:\n"
" Condition(%s) not true.", " Condition(%s) not true.",
func, file, line, cond); func, file, line, cond);
break; break;
case VAS_INCOMPLETE:
VSB_printf(pan_vsp,
"Incomplete code in %s(), %s line %d:\n",
func, file, line);
break;
default: default:
case 0: case VAS_ASSERT:
VSB_printf(pan_vsp, VSB_printf(pan_vsp,
"Assert error in %s(), %s line %d:\n" "Assert error in %s(), %s line %d:\n"
" Condition(%s) not true.\n", " Condition(%s) not true.\n",
......
...@@ -285,14 +285,14 @@ vtc_hexdump(struct vtclog *vl, int lvl, const char *pfx, ...@@ -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, 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; struct vtclog *vl;
(void)err; (void)err;
(void)xxx; (void)why;
vl = pthread_getspecific(log_key); vl = pthread_getspecific(log_key);
if (vl == NULL || vl->act) { if (vl == NULL || vl->act) {
fprintf(stderr, fprintf(stderr,
...@@ -303,6 +303,7 @@ vtc_log_VAS_Fail(const char *func, const char *file, int line, ...@@ -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:" vtc_log(vl, 0, "Assert error in %s(), %s line %d:"
" Condition(%s) not true.\n", func, file, line, cond); " 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 @@ ...@@ -38,24 +38,37 @@
#ifndef VAS_H_INCLUDED #ifndef VAS_H_INCLUDED
#define 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 #ifdef WITHOUT_ASSERTS
#define assert(e) ((void)(e)) #define assert(e) ((void)(e))
#else /* WITH_ASSERTS */ #else /* WITH_ASSERTS */
#define assert(e) \ #define assert(e) \
do { \ do { \
if (!(e)) \ if (!(e)) { \
VAS_Fail(__func__, __FILE__, __LINE__, #e, errno, 0); \ VAS_Fail(__func__, __FILE__, __LINE__, \
#e, errno, VAS_ASSERT); \
} \
} while (0) } while (0)
#endif #endif
#define xxxassert(e) \ #define xxxassert(e) \
do { \ do { \
if (!(e)) \ if (!(e)) { \
VAS_Fail(__func__, __FILE__, __LINE__, #e, errno, 1); \ VAS_Fail(__func__, __FILE__, __LINE__, \
#e, errno, VAS_MISSING); \
} \
} while (0) } while (0)
/* Assert zero return value */ /* Assert zero return value */
...@@ -66,8 +79,13 @@ do { \ ...@@ -66,8 +79,13 @@ do { \
#define diagnostic(foo) assert(foo) #define diagnostic(foo) assert(foo)
#define WRONG(expl) \ #define WRONG(expl) \
do { \ do { \
VAS_Fail(__func__, __FILE__, __LINE__, expl, errno, 3); \ VAS_Fail(__func__, __FILE__, __LINE__, expl, errno, VAS_WRONG); \
abort(); \ } while (0)
#define INCOMPL() \
do { \
VAS_Fail(__func__, __FILE__, __LINE__, \
"", errno, VAS_INCOMPLETE); \
} while (0) } while (0)
#endif #endif
...@@ -37,16 +37,24 @@ ...@@ -37,16 +37,24 @@
#include "vas.h" #include "vas.h"
static void static void __attribute__((__noreturn__))
VAS_Fail_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) const char *cond, int err, enum vas_e kind)
{ {
if (xxx) { if (kind == VAS_MISSING) {
fprintf(stderr, fprintf(stderr,
"Missing errorhandling code in %s(), %s line %d:\n" "Missing errorhandling code in %s(), %s line %d:\n"
" Condition(%s) not true.\n", " Condition(%s) not true.\n",
func, file, line, cond); 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 { } else {
fprintf(stderr, fprintf(stderr,
"Assert error in %s(), %s line %d:\n" "Assert error in %s(), %s line %d:\n"
...@@ -59,4 +67,4 @@ VAS_Fail_default(const char *func, const char *file, int line, ...@@ -59,4 +67,4 @@ VAS_Fail_default(const char *func, const char *file, int line,
abort(); 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, ...) ...@@ -45,7 +45,7 @@ vmod_panic(struct req *req, const char *str, ...)
va_start(ap, str); va_start(ap, str);
b = VRT_String(req->http->ws, "PANIC: ", str, ap); b = VRT_String(req->http->ws, "PANIC: ", str, ap);
va_end(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) 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