]> err.no Git - varnish/commitdiff
Adjust to VCL_RET_* being enum instead of bitmap.
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Sun, 21 Dec 2008 17:03:37 +0000 (17:03 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Sun, 21 Dec 2008 17:03:37 +0000 (17:03 +0000)
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
varnish-cache/bin/varnishd/cache_vcl.c
varnish-cache/bin/varnishd/cache_vrt.c
varnish-cache/include/vcl.h
varnish-cache/include/vcl_returns.h
varnish-cache/lib/libvcl/vcc_action.c
varnish-cache/lib/libvcl/vcc_compile.c
varnish-cache/lib/libvcl/vcc_compile.h
varnish-cache/lib/libvcl/vcc_fixed_token.c
varnish-cache/lib/libvcl/vcc_xref.c

index d78ae2bdb674fc113bc22ec7505ba70b17f84eb2..f4d68cd4a806a91f0c421a5f8bff11f9d90492c9 100644 (file)
@@ -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 */
 
index fed75a20de783464ec4a99a43913657869abc14c..fb65a2aef018441cc79f6b0e6e43c27f2cf612dc 100644 (file)
@@ -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
 
 /*--------------------------------------------------------------------*/
 
index 7bf5b286bd1f35d14799ff1648c75a2715cb97ee..70c1f75edb927cf86926596de91fecc4ff60f2a7 100644 (file)
@@ -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;
 }
 
index 6b29fa1bad695cf54f6c0857ad53c4909219ee76..9bd7ae6f9c9c6559c14b1493d29e40332b27664d 100644 (file)
@@ -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
 
index c64bbc64bd8e7204d5953fb6c9c1e485017438e4..18fbc84f33c598d973e2a7b0ec42be430a3e9ef4 100644 (file)
@@ -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
index 253fe4b75a4066bb0047bfc532f984f59c52cf24..0a452a62c181d162d62f24f476c4ac870c521150 100644 (file)
@@ -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
 
index e1de28d2fe60596829e42f88152f790548072b67..a658acb4306072ab3572634202dc44bc579f4c26 100644 (file)
 #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 ("<none>");
-#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);
index b27daa03f087e5567a171f0ffa76207c7ec10164..41db37154faa6bb90571af998c5db86cf7437868 100644 (file)
@@ -142,7 +142,7 @@ struct var {
 
 struct method {
        const char              *name;
-       unsigned                returns;
+       unsigned                ret_bitmap;
        unsigned                bitval;
 };
 
index 1d0fa6ffdd3177e850ff02f1222b38dc2f58cda6..d2ed3db1684114ff13cb3cae05327826f167812d 100644 (file)
@@ -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");
index 5e3d1046b681a296ac1f6a4b92db113ead167fa2..cd78baca0c085253af66c5f041b1d50d19c926b9 100644 (file)
@@ -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);