From 5f6c9aa8c4c26bed3779a21c9aa0707cb5c6d02d Mon Sep 17 00:00:00 2001 From: phk Date: Sun, 21 Dec 2008 17:03:37 +0000 Subject: [PATCH] Adjust to VCL_RET_* being enum instead of bitmap. This solves the "restart" procaction issue in a non-hackish way and looks better overall. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@3485 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-cache/bin/varnishd/cache.h | 2 - varnish-cache/bin/varnishd/cache_vcl.c | 7 +- varnish-cache/bin/varnishd/cache_vrt.c | 2 +- varnish-cache/include/vcl.h | 20 +++--- varnish-cache/include/vcl_returns.h | 77 +++++++++++++++------- varnish-cache/lib/libvcl/vcc_action.c | 13 ++-- varnish-cache/lib/libvcl/vcc_compile.c | 9 +-- varnish-cache/lib/libvcl/vcc_compile.h | 2 +- varnish-cache/lib/libvcl/vcc_fixed_token.c | 34 +++------- varnish-cache/lib/libvcl/vcc_xref.c | 29 ++++---- 10 files changed, 97 insertions(+), 98 deletions(-) diff --git a/varnish-cache/bin/varnishd/cache.h b/varnish-cache/bin/varnishd/cache.h index d78ae2bd..f4d68cd4 100644 --- a/varnish-cache/bin/varnishd/cache.h +++ b/varnish-cache/bin/varnishd/cache.h @@ -595,11 +595,9 @@ void VCL_Rel(struct VCL_conf **vcc); void VCL_Get(struct VCL_conf **vcc); void VCL_Poll(void); -#define VCL_RET_MAC(l,u,b,n) #define VCL_MET_MAC(l,u,b) void VCL_##l##_method(struct sess *); #include "vcl_returns.h" #undef VCL_MET_MAC -#undef VCL_RET_MAC /* cache_vrt_esi.c */ diff --git a/varnish-cache/bin/varnishd/cache_vcl.c b/varnish-cache/bin/varnishd/cache_vcl.c index fed75a20..fb65a2ae 100644 --- a/varnish-cache/bin/varnishd/cache_vcl.c +++ b/varnish-cache/bin/varnishd/cache_vcl.c @@ -300,8 +300,6 @@ ccf_config_use(struct cli *cli, const char * const *av, void *priv) /*--------------------------------------------------------------------*/ -#define VCL_RET_MAC(l,u,b,n) - #define VCL_MET_MAC(func, upper, bitmap) \ void \ VCL_##func##_method(struct sess *sp) \ @@ -313,13 +311,12 @@ VCL_##func##_method(struct sess *sp) \ sp->vcl->func##_func(sp); \ WSP(sp, SLT_VCL_return, "%s", VCC_Return_Name(sp->handling)); \ sp->cur_method = 0; \ - assert(sp->handling & bitmap); \ - assert(!(sp->handling & ~bitmap)); \ + assert((1 << sp->handling) & bitmap); \ + assert(!((1 << sp->handling) & ~bitmap)); \ } #include "vcl_returns.h" #undef VCL_MET_MAC -#undef VCL_RET_MAC /*--------------------------------------------------------------------*/ diff --git a/varnish-cache/bin/varnishd/cache_vrt.c b/varnish-cache/bin/varnishd/cache_vrt.c index 7bf5b286..70c1f75e 100644 --- a/varnish-cache/bin/varnishd/cache_vrt.c +++ b/varnish-cache/bin/varnishd/cache_vrt.c @@ -348,7 +348,7 @@ VRT_handling(struct sess *sp, unsigned hand) { CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); - assert(!(hand & (hand -1))); /* must be power of two */ + assert(hand < VCL_RET_MAX); sp->handling = hand; } diff --git a/varnish-cache/include/vcl.h b/varnish-cache/include/vcl.h index 6b29fa1b..9bd7ae6f 100644 --- a/varnish-cache/include/vcl.h +++ b/varnish-cache/include/vcl.h @@ -30,16 +30,16 @@ typedef int vcl_func_f(struct sess *sp); #define VCL_MET_MAX 12 /* VCL Returns */ -#define VCL_RET_ERROR (1 << 0) -#define VCL_RET_LOOKUP (1 << 1) -#define VCL_RET_HASH (1 << 2) -#define VCL_RET_PIPE (1 << 3) -#define VCL_RET_PASS (1 << 4) -#define VCL_RET_FETCH (1 << 5) -#define VCL_RET_DELIVER (1 << 6) -#define VCL_RET_DISCARD (1 << 7) -#define VCL_RET_KEEP (1 << 8) -#define VCL_RET_RESTART (1 << 9) +#define VCL_RET_ERROR 0 +#define VCL_RET_LOOKUP 1 +#define VCL_RET_HASH 2 +#define VCL_RET_PIPE 3 +#define VCL_RET_PASS 4 +#define VCL_RET_FETCH 5 +#define VCL_RET_DELIVER 6 +#define VCL_RET_DISCARD 7 +#define VCL_RET_KEEP 8 +#define VCL_RET_RESTART 9 #define VCL_RET_MAX 10 diff --git a/varnish-cache/include/vcl_returns.h b/varnish-cache/include/vcl_returns.h index c64bbc64..18fbc84f 100644 --- a/varnish-cache/include/vcl_returns.h +++ b/varnish-cache/include/vcl_returns.h @@ -7,43 +7,72 @@ */ #ifdef VCL_RET_MAC -#ifdef VCL_RET_MAC_E -VCL_RET_MAC_E(error, ERROR, (1 << 0), 0) -#endif -VCL_RET_MAC(lookup, LOOKUP, (1 << 1), 1) -VCL_RET_MAC(hash, HASH, (1 << 2), 2) -VCL_RET_MAC(pipe, PIPE, (1 << 3), 3) -VCL_RET_MAC(pass, PASS, (1 << 4), 4) -VCL_RET_MAC(fetch, FETCH, (1 << 5), 5) -VCL_RET_MAC(deliver, DELIVER, (1 << 6), 6) -VCL_RET_MAC(discard, DISCARD, (1 << 7), 7) -VCL_RET_MAC(keep, KEEP, (1 << 8), 8) -VCL_RET_MAC(restart, RESTART, (1 << 9), 9) +VCL_RET_MAC(error, ERROR) +VCL_RET_MAC(lookup, LOOKUP) +VCL_RET_MAC(hash, HASH) +VCL_RET_MAC(pipe, PIPE) +VCL_RET_MAC(pass, PASS) +VCL_RET_MAC(fetch, FETCH) +VCL_RET_MAC(deliver, DELIVER) +VCL_RET_MAC(discard, DISCARD) +VCL_RET_MAC(keep, KEEP) +VCL_RET_MAC(restart, RESTART) #endif #ifdef VCL_MET_MAC VCL_MET_MAC(recv,RECV, - (VCL_RET_ERROR|VCL_RET_PASS|VCL_RET_PIPE|VCL_RET_LOOKUP)) + ((1 << VCL_RET_ERROR) + | (1 << VCL_RET_PASS) + | (1 << VCL_RET_PIPE) + | (1 << VCL_RET_LOOKUP) +)) VCL_MET_MAC(pipe,PIPE, - (VCL_RET_ERROR|VCL_RET_PIPE)) + ((1 << VCL_RET_ERROR) + | (1 << VCL_RET_PIPE) +)) VCL_MET_MAC(pass,PASS, - (VCL_RET_ERROR|VCL_RET_RESTART|VCL_RET_PASS)) + ((1 << VCL_RET_ERROR) + | (1 << VCL_RET_RESTART) + | (1 << VCL_RET_PASS) +)) VCL_MET_MAC(hash,HASH, - (VCL_RET_HASH)) + ((1 << VCL_RET_HASH) +)) VCL_MET_MAC(miss,MISS, - (VCL_RET_ERROR|VCL_RET_RESTART|VCL_RET_PASS|VCL_RET_FETCH)) + ((1 << VCL_RET_ERROR) + | (1 << VCL_RET_RESTART) + | (1 << VCL_RET_PASS) + | (1 << VCL_RET_FETCH) +)) VCL_MET_MAC(hit,HIT, - (VCL_RET_ERROR|VCL_RET_RESTART|VCL_RET_PASS|VCL_RET_DELIVER)) + ((1 << VCL_RET_ERROR) + | (1 << VCL_RET_RESTART) + | (1 << VCL_RET_PASS) + | (1 << VCL_RET_DELIVER) +)) VCL_MET_MAC(fetch,FETCH, - (VCL_RET_ERROR|VCL_RET_RESTART|VCL_RET_PASS|VCL_RET_DELIVER)) + ((1 << VCL_RET_ERROR) + | (1 << VCL_RET_RESTART) + | (1 << VCL_RET_PASS) + | (1 << VCL_RET_DELIVER) +)) VCL_MET_MAC(deliver,DELIVER, - (VCL_RET_RESTART|VCL_RET_DELIVER)) + ((1 << VCL_RET_RESTART) + | (1 << VCL_RET_DELIVER) +)) VCL_MET_MAC(prefetch,PREFETCH, - (VCL_RET_FETCH|VCL_RET_PASS)) + ((1 << VCL_RET_FETCH) + | (1 << VCL_RET_PASS) +)) VCL_MET_MAC(timeout,TIMEOUT, - (VCL_RET_FETCH|VCL_RET_DISCARD)) + ((1 << VCL_RET_FETCH) + | (1 << VCL_RET_DISCARD) +)) VCL_MET_MAC(discard,DISCARD, - (VCL_RET_DISCARD|VCL_RET_KEEP)) + ((1 << VCL_RET_DISCARD) + | (1 << VCL_RET_KEEP) +)) VCL_MET_MAC(error,ERROR, - (VCL_RET_DELIVER)) + ((1 << VCL_RET_DELIVER) +)) #endif diff --git a/varnish-cache/lib/libvcl/vcc_action.c b/varnish-cache/lib/libvcl/vcc_action.c index 253fe4b7..0a452a62 100644 --- a/varnish-cache/lib/libvcl/vcc_action.c +++ b/varnish-cache/lib/libvcl/vcc_action.c @@ -48,18 +48,16 @@ parse_action(struct tokenlist *tl) Expect(tl, ID); -#define VCL_RET_MAC(l, u, b, i) \ +#define VCL_RET_MAC(l, U) \ do { \ if (vcc_IdIs(tl->t, #l)) { \ - Fb(tl, 1, "VRT_done(sp, VCL_RET_%s);\n", #u); \ - vcc_ProcAction(tl->curproc, i, tl->t); \ + Fb(tl, 1, "VRT_done(sp, VCL_RET_" #U ");\n"); \ + vcc_ProcAction(tl->curproc, VCL_RET_##U, tl->t);\ retval = 1; \ } \ } while (0); -#define VCL_RET_MAC_E(l, u, b, i) VCL_RET_MAC(l, u, b, i) #include "vcl_returns.h" #undef VCL_RET_MAC -#undef VCL_RET_MAC_E if (!retval) { vsb_printf(tl->sb, "Expected action name.\n"); vcc_ErrWhere(tl, tl->t); @@ -85,8 +83,7 @@ parse_restart(struct tokenlist *tl) ERRCHK(tl); } Fb(tl, 1, "VRT_done(sp, VCL_RET_RESTART);\n"); - assert(VCL_RET_RESTART == (1 << 9)); /* XXX: BANDAID FIXME! */ - vcc_ProcAction(tl->curproc, 9, tl->t); + vcc_ProcAction(tl->curproc, VCL_RET_RESTART, tl->t); vcc_NextToken(tl); } @@ -465,7 +462,7 @@ static struct action_table { } action_table[] = { { "restart", parse_restart }, { "error", parse_error }, -#define VCL_RET_MAC(l, u, b, i) { #l, parse_action }, +#define VCL_RET_MAC(l, U) { #l, parse_action }, #include "vcl_returns.h" #undef VCL_RET_MAC diff --git a/varnish-cache/lib/libvcl/vcc_compile.c b/varnish-cache/lib/libvcl/vcc_compile.c index e1de28d2..a658acb4 100644 --- a/varnish-cache/lib/libvcl/vcc_compile.c +++ b/varnish-cache/lib/libvcl/vcc_compile.c @@ -84,11 +84,9 @@ #include "libvarnish.h" struct method method_tab[] = { -#define VCL_RET_MAC(l,U,b,n) #define VCL_MET_MAC(l,U,m) { "vcl_"#l, m, VCL_MET_##U }, #include "vcl_returns.h" #undef VCL_MET_MAC -#undef VCL_RET_MAC { NULL, 0U, 0} }; @@ -360,12 +358,10 @@ EmitStruct(const struct tokenlist *tl) Fc(tl, 0, "\t.srcname = srcname,\n"); Fc(tl, 0, "\t.srcbody = srcbody,\n"); Fc(tl, 0, "\t.nhashcount = %u,\n", tl->nhashcount); -#define VCL_RET_MAC(l,u,b,n) #define VCL_MET_MAC(l,u,b) \ Fc(tl, 0, "\t." #l "_func = VGC_function_vcl_" #l ",\n"); #include "vcl_returns.h" #undef VCL_MET_MAC -#undef VCL_RET_MAC Fc(tl, 0, "};\n"); } @@ -669,11 +665,8 @@ VCC_Return_Name(unsigned method) { switch (method) { - case 0: return (""); -#define VCL_RET_MAC(l, u, b, i) case b: return(#l); -#define VCL_RET_MAC_E(l, u, b, i) case b: return(#l); +#define VCL_RET_MAC(l, U) case VCL_RET_##U: return(#l); #include "vcl_returns.h" -#undef VCL_RET_MAC_E #undef VCL_RET_MAC } return (NULL); diff --git a/varnish-cache/lib/libvcl/vcc_compile.h b/varnish-cache/lib/libvcl/vcc_compile.h index b27daa03..41db3715 100644 --- a/varnish-cache/lib/libvcl/vcc_compile.h +++ b/varnish-cache/lib/libvcl/vcc_compile.h @@ -142,7 +142,7 @@ struct var { struct method { const char *name; - unsigned returns; + unsigned ret_bitmap; unsigned bitval; }; diff --git a/varnish-cache/lib/libvcl/vcc_fixed_token.c b/varnish-cache/lib/libvcl/vcc_fixed_token.c index 1d0fa6ff..d2ed3db1 100644 --- a/varnish-cache/lib/libvcl/vcc_fixed_token.c +++ b/varnish-cache/lib/libvcl/vcc_fixed_token.c @@ -154,21 +154,11 @@ const char * const vcl_tnames[256] = { void vcl_output_lang_h(struct vsb *sb) { - vsb_cat(sb, "#define VCL_RET_ERROR (1 << 0)\n"); - vsb_cat(sb, "#define VCL_RET_LOOKUP (1 << 1)\n"); - vsb_cat(sb, "#define VCL_RET_HASH (1 << 2)\n"); - vsb_cat(sb, "#define VCL_RET_PIPE (1 << 3)\n"); - vsb_cat(sb, "#define VCL_RET_PASS (1 << 4)\n"); - vsb_cat(sb, "#define VCL_RET_FETCH (1 << 5)\n"); - vsb_cat(sb, "#define VCL_RET_DELIVER (1 << 6)\n"); - vsb_cat(sb, "#define VCL_RET_DISCARD (1 << 7)\n"); - vsb_cat(sb, "#define VCL_RET_KEEP (1 << 8)\n"); - vsb_cat(sb, "#define VCL_RET_RESTART (1 << 9)\n"); /* ../../include/vcl.h */ - vsb_cat(sb, "/*\n * $Id: vcc_gen_fixed_token.tcl 3482 2008-12-21 16"); - vsb_cat(sb, ":18:39Z phk $\n *\n * NB: This file is machine genera"); + vsb_cat(sb, "/*\n * $Id: vcc_gen_fixed_token.tcl 3484 2008-12-21 17"); + vsb_cat(sb, ":01:58Z phk $\n *\n * NB: This file is machine genera"); vsb_cat(sb, "ted, DO NOT EDIT!\n *\n * Edit and run vcc_gen_fixed_t"); vsb_cat(sb, "oken.tcl instead\n */\n\nstruct sess;\n"); vsb_cat(sb, "struct cli;\n\ntypedef void vcl_init_f(struct cli *);\n"); @@ -187,18 +177,14 @@ vcl_output_lang_h(struct vsb *sb) vsb_cat(sb, "#define VCL_MET_DISCARD\t\t(1 << 10)\n"); vsb_cat(sb, "#define VCL_MET_ERROR\t\t(1 << 11)\n"); vsb_cat(sb, "\n#define VCL_MET_MAX\t\t12\n\n"); - vsb_cat(sb, "/* VCL Returns */\n#define VCL_RET_ERROR\t\t(1 << 0)\n"); - vsb_cat(sb, "#define VCL_RET_LOOKUP\t\t(1 << 1)\n"); - vsb_cat(sb, "#define VCL_RET_HASH\t\t(1 << 2)\n"); - vsb_cat(sb, "#define VCL_RET_PIPE\t\t(1 << 3)\n"); - vsb_cat(sb, "#define VCL_RET_PASS\t\t(1 << 4)\n"); - vsb_cat(sb, "#define VCL_RET_FETCH\t\t(1 << 5)\n"); - vsb_cat(sb, "#define VCL_RET_DELIVER\t\t(1 << 6)\n"); - vsb_cat(sb, "#define VCL_RET_DISCARD\t\t(1 << 7)\n"); - vsb_cat(sb, "#define VCL_RET_KEEP\t\t(1 << 8)\n"); - vsb_cat(sb, "#define VCL_RET_RESTART\t\t(1 << 9)\n"); - vsb_cat(sb, "\n#define VCL_RET_MAX\t\t10\n\n"); - vsb_cat(sb, "struct VCL_conf {\n\tunsigned\tmagic;\n"); + vsb_cat(sb, "/* VCL Returns */\n#define VCL_RET_ERROR\t\t0\n"); + vsb_cat(sb, "#define VCL_RET_LOOKUP\t\t1\n#define VCL_RET_HASH\t\t2"); + vsb_cat(sb, "\n#define VCL_RET_PIPE\t\t3\n#define VCL_RET_PASS\t\t4"); + vsb_cat(sb, "\n#define VCL_RET_FETCH\t\t5\n#define VCL_RET_DELIVER\t"); + vsb_cat(sb, "\t6\n#define VCL_RET_DISCARD\t\t7\n"); + vsb_cat(sb, "#define VCL_RET_KEEP\t\t8\n#define VCL_RET_RESTART\t\t"); + vsb_cat(sb, "9\n\n#define VCL_RET_MAX\t\t10\n"); + vsb_cat(sb, "\nstruct VCL_conf {\n\tunsigned\tmagic;\n"); vsb_cat(sb, "#define VCL_CONF_MAGIC\t0x7406c509\t/* from /dev/rando"); vsb_cat(sb, "m */\n\n\tstruct director\t**director;\n"); vsb_cat(sb, "\tunsigned\tndirector;\n\tstruct vrt_ref\t*ref;\n"); diff --git a/varnish-cache/lib/libvcl/vcc_xref.c b/varnish-cache/lib/libvcl/vcc_xref.c index 5e3d1046..cd78baca 100644 --- a/varnish-cache/lib/libvcl/vcc_xref.c +++ b/varnish-cache/lib/libvcl/vcc_xref.c @@ -68,7 +68,7 @@ struct proc { VTAILQ_HEAD(,proccall) calls; VTAILQ_HEAD(,procuse) uses; struct token *name; - unsigned returns; + unsigned ret_bitmap; unsigned exists; unsigned called; unsigned active; @@ -242,14 +242,15 @@ void vcc_ProcAction(struct proc *p, unsigned returns, struct token *t) { - p->returns |= (1U << returns); + assert(returns < VCL_RET_MAX); + p->ret_bitmap |= (1U << returns); /* Record the first instance of this return */ if (p->return_tok[returns] == NULL) p->return_tok[returns] = t; } static int -vcc_CheckActionRecurse(struct tokenlist *tl, struct proc *p, unsigned returns) +vcc_CheckActionRecurse(struct tokenlist *tl, struct proc *p, unsigned bitmap) { unsigned u; struct proccall *pc; @@ -264,13 +265,13 @@ vcc_CheckActionRecurse(struct tokenlist *tl, struct proc *p, unsigned returns) vcc_ErrWhere(tl, p->name); return (1); } - u = p->returns & ~returns; + u = p->ret_bitmap & ~bitmap; if (u) { /*lint -save -e525 -e539 */ -#define VCL_RET_MAC(a, b, c, d) \ - if (u & VCL_RET_##b) { \ - vsb_printf(tl->sb, "Invalid return \"%s\"\n", #a); \ - vcc_ErrWhere(tl, p->return_tok[d]); \ +#define VCL_RET_MAC(l, U) \ + if (u & (1 << (VCL_RET_##U))) { \ + vsb_printf(tl->sb, "Invalid return \"" #l "\"\n");\ + vcc_ErrWhere(tl, p->return_tok[VCL_RET_##U]); \ } #include "vcl_returns.h" #undef VCL_RET_MAC @@ -281,7 +282,7 @@ vcc_CheckActionRecurse(struct tokenlist *tl, struct proc *p, unsigned returns) } p->active = 1; VTAILQ_FOREACH(pc, &p->calls, list) { - if (vcc_CheckActionRecurse(tl, pc->p, returns)) { + if (vcc_CheckActionRecurse(tl, pc->p, bitmap)) { vsb_printf(tl->sb, "\n...called from \"%.*s\"\n", PF(p->name)); vcc_ErrWhere(tl, pc->t); @@ -305,19 +306,17 @@ vcc_CheckAction(struct tokenlist *tl) if (i < 0) continue; m = method_tab + i; - if (vcc_CheckActionRecurse(tl, p, m->returns)) { + if (vcc_CheckActionRecurse(tl, p, m->ret_bitmap)) { vsb_printf(tl->sb, "\n...which is the \"%s\" method\n", m->name); vsb_printf(tl->sb, "Legal returns are:"); -#define VCL_RET_MAC(a, b, c, d) \ - if (m->returns & c) \ - vsb_printf(tl->sb, " \"%s\"", #a); -#define VCL_RET_MAC_E(a, b, c, d) VCL_RET_MAC(a, b, c, d) +#define VCL_RET_MAC(l, U) \ + if (m->ret_bitmap & ((1 << VCL_RET_##U))) \ + vsb_printf(tl->sb, " \"%s\"", #l); /*lint -save -e525 -e539 */ #include "vcl_returns.h" /*lint +e525 */ #undef VCL_RET_MAC -#undef VCL_RET_MAC_E /*lint -restore */ vsb_printf(tl->sb, "\n"); return (1); -- 2.39.5