r4680 - in branches/2.1: . varnish-cache/bin/varnishd varnish-cache/bin/varnishtest/tests varnish-cache/include varnish-cache/lib/libvarnish varnish-cache/lib/libvcl
tfheen at varnish-cache.org
tfheen at varnish-cache.org
Mon Apr 19 13:28:51 CEST 2010
Author: tfheen
Date: 2010-04-19 13:28:51 +0200 (Mon, 19 Apr 2010)
New Revision: 4680
Modified:
branches/2.1/
branches/2.1/varnish-cache/bin/varnishd/cache_backend.h
branches/2.1/varnish-cache/bin/varnishd/cache_backend_cfg.c
branches/2.1/varnish-cache/bin/varnishd/vparam.h
branches/2.1/varnish-cache/bin/varnishtest/tests/c00019.vtc
branches/2.1/varnish-cache/bin/varnishtest/tests/r00325.vtc
branches/2.1/varnish-cache/bin/varnishtest/tests/r00416.vtc
branches/2.1/varnish-cache/bin/varnishtest/tests/v00011.vtc
branches/2.1/varnish-cache/include/vct.h
branches/2.1/varnish-cache/include/vev.h
branches/2.1/varnish-cache/lib/libvarnish/tcp.c
branches/2.1/varnish-cache/lib/libvarnish/vev.c
branches/2.1/varnish-cache/lib/libvcl/vcc_action.c
branches/2.1/varnish-cache/lib/libvcl/vcc_backend.c
branches/2.1/varnish-cache/lib/libvcl/vcc_compile.h
branches/2.1/varnish-cache/lib/libvcl/vcc_dir_random.c
branches/2.1/varnish-cache/lib/libvcl/vcc_parse.c
branches/2.1/varnish-cache/lib/libvcl/vcc_var.c
Log:
Merge r4655: Polish the variable/type system a little bit, to make
life easier for Kristian, and to eliminate some code duplication.
Property changes on: branches/2.1
___________________________________________________________________
Modified: svn:mergeinfo
- /trunk:4637,4640,4643-4645,4647-4650,4654
+ /trunk:4637,4640,4643-4645,4647-4650,4654-4655
Property changes on: branches/2.1/varnish-cache/bin/varnishd/cache_backend.h
___________________________________________________________________
Modified: svn:mergeinfo
- /trunk/varnish-cache/bin/varnishd/cache_backend.h:4637,4643-4645,4647-4650,4654
+ /trunk/varnish-cache/bin/varnishd/cache_backend.h:4637,4643-4645,4647-4650,4654-4655
Property changes on: branches/2.1/varnish-cache/bin/varnishd/cache_backend_cfg.c
___________________________________________________________________
Modified: svn:mergeinfo
- /trunk/varnish-cache/bin/varnishd/cache_backend_cfg.c:4637,4643-4645,4647-4650,4654
+ /trunk/varnish-cache/bin/varnishd/cache_backend_cfg.c:4637,4643-4645,4647-4650,4654-4655
Property changes on: branches/2.1/varnish-cache/bin/varnishd/vparam.h
___________________________________________________________________
Modified: svn:mergeinfo
- /trunk/varnish-cache/bin/varnishd/vparam.h:4637,4643-4645,4647-4650,4654
+ /trunk/varnish-cache/bin/varnishd/vparam.h:4637,4643-4645,4647-4650,4654-4655
Property changes on: branches/2.1/varnish-cache/bin/varnishtest/tests/c00019.vtc
___________________________________________________________________
Modified: svn:mergeinfo
- /trunk/varnish-cache/bin/varnishtest/tests/c00019.vtc:4637,4643-4645,4647-4650,4654
+ /trunk/varnish-cache/bin/varnishtest/tests/c00019.vtc:4637,4643-4645,4647-4650,4654-4655
Property changes on: branches/2.1/varnish-cache/bin/varnishtest/tests/r00325.vtc
___________________________________________________________________
Modified: svn:mergeinfo
- /trunk/varnish-cache/bin/varnishtest/tests/r00325.vtc:4637,4643-4645,4647-4650,4654
+ /trunk/varnish-cache/bin/varnishtest/tests/r00325.vtc:4637,4643-4645,4647-4650,4654-4655
Property changes on: branches/2.1/varnish-cache/bin/varnishtest/tests/r00416.vtc
___________________________________________________________________
Modified: svn:mergeinfo
- /trunk/varnish-cache/bin/varnishtest/tests/r00416.vtc:4637,4643-4645,4647-4650,4654
+ /trunk/varnish-cache/bin/varnishtest/tests/r00416.vtc:4637,4643-4645,4647-4650,4654-4655
Property changes on: branches/2.1/varnish-cache/bin/varnishtest/tests/v00011.vtc
___________________________________________________________________
Modified: svn:mergeinfo
- /trunk/varnish-cache/bin/varnishtest/tests/v00011.vtc:4637,4643-4645,4647-4650,4654
+ /trunk/varnish-cache/bin/varnishtest/tests/v00011.vtc:4637,4643-4645,4647-4650,4654-4655
Property changes on: branches/2.1/varnish-cache/include/vct.h
___________________________________________________________________
Modified: svn:mergeinfo
- /trunk/varnish-cache/include/vct.h:4637,4643-4645,4647-4650,4654
+ /trunk/varnish-cache/include/vct.h:4637,4643-4645,4647-4650,4654-4655
Property changes on: branches/2.1/varnish-cache/include/vev.h
___________________________________________________________________
Modified: svn:mergeinfo
- /trunk/varnish-cache/include/vev.h:4637,4643-4645,4647-4650,4654
+ /trunk/varnish-cache/include/vev.h:4637,4643-4645,4647-4650,4654-4655
Property changes on: branches/2.1/varnish-cache/lib/libvarnish/tcp.c
___________________________________________________________________
Modified: svn:mergeinfo
- /trunk/varnish-cache/lib/libvarnish/tcp.c:4637,4643-4645,4647-4650,4654
+ /trunk/varnish-cache/lib/libvarnish/tcp.c:4637,4643-4645,4647-4650,4654-4655
Property changes on: branches/2.1/varnish-cache/lib/libvarnish/vev.c
___________________________________________________________________
Modified: svn:mergeinfo
- /trunk/varnish-cache/lib/libvarnish/vev.c:4637,4643-4645,4647-4650,4654
+ /trunk/varnish-cache/lib/libvarnish/vev.c:4637,4643-4645,4647-4650,4654-4655
Modified: branches/2.1/varnish-cache/lib/libvcl/vcc_action.c
===================================================================
--- branches/2.1/varnish-cache/lib/libvcl/vcc_action.c 2010-04-19 11:24:21 UTC (rev 4679)
+++ branches/2.1/varnish-cache/lib/libvcl/vcc_action.c 2010-04-19 11:28:51 UTC (rev 4680)
@@ -177,23 +177,8 @@
case T_INCR:
case T_DECR:
case '=':
- if (vp->fmt == TIME)
- vcc_TimeVal(tl);
- else if (vp->fmt == RTIME)
- vcc_RTimeVal(tl);
- else if (vp->fmt == SIZE)
- vcc_SizeVal(tl);
- else if (vp->fmt == FLOAT)
- Fb(tl, 0, "%g", vcc_DoubleVal(tl));
- else if (vp->fmt == INT) {
- Fb(tl, 0, "%u", vcc_UintVal(tl));
- vcc_NextToken(tl);
- } else {
- vsb_printf(tl->sb,
- "Cannot assign this variable type.\n");
- vcc_ErrWhere(tl, vt);
- return;
- }
+ vcc_VarVal(tl, vp, vt);
+ ERRCHK(tl);
break;
default:
vsb_printf(tl->sb, "Invalid assignment operator.\n");
Modified: branches/2.1/varnish-cache/lib/libvcl/vcc_backend.c
===================================================================
--- branches/2.1/varnish-cache/lib/libvcl/vcc_backend.c 2010-04-19 11:24:21 UTC (rev 4679)
+++ branches/2.1/varnish-cache/lib/libvcl/vcc_backend.c 2010-04-19 11:28:51 UTC (rev 4680)
@@ -247,6 +247,7 @@
struct token *t_did = NULL, *t_window = NULL, *t_threshold = NULL;
struct token *t_initial = NULL;
unsigned window, threshold, initial, status;
+ double t;
fs = vcc_FldSpec(tl,
"?url",
@@ -292,14 +293,14 @@
Fb(tl, 0, "\t\t\t\"\\r\\n\",\n");
} else if (vcc_IdIs(t_field, "timeout")) {
Fb(tl, 0, "\t\t.timeout = ");
- vcc_TimeVal(tl);
+ vcc_TimeVal(tl, &t);
ERRCHK(tl);
- Fb(tl, 0, ",\n");
+ Fb(tl, 0, "%g,\n", t);
} else if (vcc_IdIs(t_field, "interval")) {
Fb(tl, 0, "\t\t.interval = ");
- vcc_TimeVal(tl);
+ vcc_TimeVal(tl, &t);
ERRCHK(tl);
- Fb(tl, 0, ",\n");
+ Fb(tl, 0, "%g,\n", t);
} else if (vcc_IdIs(t_field, "window")) {
t_window = tl->t;
window = vcc_UintVal(tl);
@@ -396,6 +397,7 @@
struct fld_spec *fs;
struct vsb *vsb;
unsigned u;
+ double t;
Fh(tl, 1, "\n#define VGC_backend_%s %d\n", vgcname, tl->ndirector);
@@ -462,21 +464,21 @@
SkipToken(tl, ';');
} else if (vcc_IdIs(t_field, "connect_timeout")) {
Fb(tl, 0, "\t.connect_timeout = ");
- vcc_TimeVal(tl);
+ vcc_TimeVal(tl, &t);
ERRCHK(tl);
- Fb(tl, 0, ",\n");
+ Fb(tl, 0, "%g,\n", t);
SkipToken(tl, ';');
} else if (vcc_IdIs(t_field, "first_byte_timeout")) {
Fb(tl, 0, "\t.first_byte_timeout = ");
- vcc_TimeVal(tl);
+ vcc_TimeVal(tl, &t);
ERRCHK(tl);
- Fb(tl, 0, ",\n");
+ Fb(tl, 0, "%g,\n", t);
SkipToken(tl, ';');
} else if (vcc_IdIs(t_field, "between_bytes_timeout")) {
Fb(tl, 0, "\t.between_bytes_timeout = ");
- vcc_TimeVal(tl);
+ vcc_TimeVal(tl, &t);
ERRCHK(tl);
- Fb(tl, 0, ",\n");
+ Fb(tl, 0, "%g,\n", t);
SkipToken(tl, ';');
} else if (vcc_IdIs(t_field, "max_connections")) {
u = vcc_UintVal(tl);
Modified: branches/2.1/varnish-cache/lib/libvcl/vcc_compile.h
===================================================================
--- branches/2.1/varnish-cache/lib/libvcl/vcc_compile.h 2010-04-19 11:24:21 UTC (rev 4679)
+++ branches/2.1/varnish-cache/lib/libvcl/vcc_compile.h 2010-04-19 11:28:51 UTC (rev 4680)
@@ -196,9 +196,9 @@
/* vcc_parse.c */
void vcc_Parse(struct tokenlist *tl);
-void vcc_RTimeVal(struct tokenlist *tl);
-void vcc_TimeVal(struct tokenlist *tl);
-void vcc_SizeVal(struct tokenlist *tl);
+void vcc_RTimeVal(struct tokenlist *tl, double *);
+void vcc_TimeVal(struct tokenlist *tl, double *);
+void vcc_SizeVal(struct tokenlist *tl, double *);
unsigned vcc_UintVal(struct tokenlist *tl);
double vcc_DoubleVal(struct tokenlist *tl);
@@ -226,6 +226,8 @@
/* vcc_var.c */
struct var *vcc_FindVar(struct tokenlist *tl, const struct token *t,
struct var *vl);
+void vcc_VarVal(struct tokenlist *tl, const struct var *vp,
+ const struct token *vt);
/* vcc_xref.c */
void vcc_AddDef(struct tokenlist *tl, struct token *t, enum ref_type type);
Property changes on: branches/2.1/varnish-cache/lib/libvcl/vcc_dir_random.c
___________________________________________________________________
Modified: svn:mergeinfo
- /trunk/varnish-cache/lib/libvcl/vcc_dir_random.c:4637,4643-4645,4647-4650,4654
+ /trunk/varnish-cache/lib/libvcl/vcc_dir_random.c:4637,4643-4645,4647-4650,4654-4655
Modified: branches/2.1/varnish-cache/lib/libvcl/vcc_parse.c
===================================================================
--- branches/2.1/varnish-cache/lib/libvcl/vcc_parse.c 2010-04-19 11:24:21 UTC (rev 4679)
+++ branches/2.1/varnish-cache/lib/libvcl/vcc_parse.c 2010-04-19 11:28:51 UTC (rev 4680)
@@ -123,6 +123,7 @@
/*--------------------------------------------------------------------
* Recognize and convert { CNUM } to unsigned value
+ * The tokenizer made sure we only get digits.
*/
unsigned
@@ -141,6 +142,7 @@
/*--------------------------------------------------------------------
* Recognize and convert { CNUM [ '.' [ CNUM ] ] } to double value
+ * The tokenizer made sure we only get digits and a '.'
*/
double
@@ -171,7 +173,7 @@
/*--------------------------------------------------------------------*/
void
-vcc_RTimeVal(struct tokenlist *tl)
+vcc_RTimeVal(struct tokenlist *tl, double *d)
{
double v, sc;
int sign = 1;
@@ -184,11 +186,13 @@
ERRCHK(tl);
ExpectErr(tl, ID);
sc = TimeUnit(tl);
- Fb(tl, 0, "(%d * %g * %g)", sign, v, sc);
+ *d = sign * v * sc;
}
+/*--------------------------------------------------------------------*/
+
void
-vcc_TimeVal(struct tokenlist *tl)
+vcc_TimeVal(struct tokenlist *tl, double *d)
{
double v, sc;
@@ -196,11 +200,13 @@
ERRCHK(tl);
ExpectErr(tl, ID);
sc = TimeUnit(tl);
- Fb(tl, 0, "(%g * %g)", v, sc);
+ *d = v * sc;
}
+/*--------------------------------------------------------------------*/
+
void
-vcc_SizeVal(struct tokenlist *tl)
+vcc_SizeVal(struct tokenlist *tl, double *d)
{
double v, sc;
@@ -208,7 +214,7 @@
ERRCHK(tl);
ExpectErr(tl, ID);
sc = SizeUnit(tl);
- Fb(tl, 0, "(%g * %g)", v, sc);
+ *d = v * sc;
}
/*--------------------------------------------------------------------*/
@@ -261,28 +267,8 @@
case '<':
Fb(tl, 0, "%.*s ", PF(tl->t));
vcc_NextToken(tl);
- switch(vp->fmt) {
- case TIME:
- vcc_TimeVal(tl);
- break;
- case RTIME:
- vcc_RTimeVal(tl);
- break;
- case INT:
- ExpectErr(tl, CNUM);
- Fb(tl, 0, "%.*s ", PF(tl->t));
- vcc_NextToken(tl);
- break;
- case SIZE:
- vcc_SizeVal(tl);
- break;
- default:
- vsb_printf(tl->sb,
- "No conditions available for variable '%s'\n",
- vp->name);
- vcc_ErrWhere(tl, tl->t);
- return;
- }
+ vcc_VarVal(tl, vp, NULL);
+ ERRCHK(tl);
Fb(tl, 0, "\n");
break;
default:
Modified: branches/2.1/varnish-cache/lib/libvcl/vcc_var.c
===================================================================
--- branches/2.1/varnish-cache/lib/libvcl/vcc_var.c 2010-04-19 11:24:21 UTC (rev 4679)
+++ branches/2.1/varnish-cache/lib/libvcl/vcc_var.c 2010-04-19 11:28:51 UTC (rev 4680)
@@ -110,3 +110,35 @@
return (NULL);
}
+/*--------------------------------------------------------------------*/
+
+void
+vcc_VarVal(struct tokenlist *tl, const struct var *vp, const struct token *vt)
+{
+ double d;
+
+ if (vp->fmt == TIME) {
+ vcc_TimeVal(tl, &d);
+ ERRCHK(tl);
+ Fb(tl, 0, "%g", d);
+ } else if (vp->fmt == RTIME) {
+ vcc_RTimeVal(tl, &d);
+ ERRCHK(tl);
+ Fb(tl, 0, "%g", d);
+ } else if (vp->fmt == SIZE) {
+ vcc_SizeVal(tl, &d);
+ ERRCHK(tl);
+ Fb(tl, 0, "%g", d);
+ } else if (vp->fmt == FLOAT) {
+ Fb(tl, 0, "%g", vcc_DoubleVal(tl));
+ } else if (vp->fmt == INT) {
+ Fb(tl, 0, "%u", vcc_UintVal(tl));
+ vcc_NextToken(tl);
+ } else {
+ AN(vt);
+ vsb_printf(tl->sb,
+ "Variable has incompatible type.\n");
+ vcc_ErrWhere(tl, vt);
+ return;
+ }
+}
More information about the varnish-commit
mailing list