[master] 3ffe8e1 Eliminate the distinction between SYM_FUNC and SYM_PROC and allow people to throw return values away if the want to, but not to use VOID in expressions.
Poul-Henning Kamp
phk at FreeBSD.org
Wed May 18 23:08:06 CEST 2016
commit 3ffe8e1e3435c89110b1dce23b55c8ba56ec50da
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Wed May 18 21:06:29 2016 +0000
Eliminate the distinction between SYM_FUNC and SYM_PROC and allow
people to throw return values away if the want to, but not to
use VOID in expressions.
diff --git a/bin/varnishtest/tests/v00020.vtc b/bin/varnishtest/tests/v00020.vtc
index ff178f6..540a560 100644
--- a/bin/varnishtest/tests/v00020.vtc
+++ b/bin/varnishtest/tests/v00020.vtc
@@ -275,6 +275,14 @@ varnish v1 -errvcl {VCL sub's named 'vcl*' are reserved names.} {
}
}
+varnish v1 -errvcl {Function returns VOID} {
+ import debug;
+ backend b { .host = "127.0.0.1"; }
+ sub vcl_recv {
+ set req.http.foo = debug.sleep(1m);
+ }
+}
+
varnish v1 -errvcl {Names of VCL acl's cannot contain '-'} {
backend b { .host = "127.0.0.1"; }
acl foo-bar {
diff --git a/include/tbl/symbol_kind.h b/include/tbl/symbol_kind.h
index 36f19e5..497f400 100644
--- a/include/tbl/symbol_kind.h
+++ b/include/tbl/symbol_kind.h
@@ -30,8 +30,7 @@
/*lint -save -e525 -e539 */
VCC_SYMB(NONE, none)
VCC_SYMB(VAR, var)
-VCC_SYMB(FUNC, func) /* VMOD function */
-VCC_SYMB(PROC, proc) /* VMOD procedure */
+VCC_SYMB(FUNC, func) /* VMOD function/procedure */
VCC_SYMB(VMOD, vmod)
VCC_SYMB(ACL, acl)
VCC_SYMB(SUB, sub) /* VCL subroutine */
diff --git a/lib/libvcc/vcc_action.c b/lib/libvcc/vcc_action.c
index 516f628..8e62d2d 100644
--- a/lib/libvcc/vcc_action.c
+++ b/lib/libvcc/vcc_action.c
@@ -240,10 +240,6 @@ parse_new(struct vcc *tl)
sy3->cfunc = p;
p += strlen(p) + 1;
- /* Functions which return VOID are procedures */
- if (!memcmp(p, "VOID\0", 5))
- sy3->kind = SYM_PROC;
-
sy3->args = p;
sy3->extra = TlDup(tl, buf1);
while (p[0] != '\0' || p[1] != '\0') {
@@ -435,7 +431,7 @@ vcc_ParseAction(struct vcc *tl)
}
}
sym = VCC_FindSymbol(tl, tl->t, SYM_NONE);
- if (sym != NULL && sym->kind == SYM_PROC) {
+ if (sym != NULL && sym->kind == SYM_FUNC) {
vcc_Expr_Call(tl, sym);
return (1);
}
diff --git a/lib/libvcc/vcc_compile.h b/lib/libvcc/vcc_compile.h
index 20bc18c..31f87e1 100644
--- a/lib/libvcc/vcc_compile.h
+++ b/lib/libvcc/vcc_compile.h
@@ -131,7 +131,7 @@ struct symbol {
struct proc *proc;
unsigned nref, ndef;
- /* SYM_PROC, SYM_FUNC */
+ /* SYM_FUNC */
const char *cfunc;
const char *extra;
const char *args;
@@ -289,6 +289,7 @@ void vcc_Eval_Func(struct vcc *tl, const char *cfunc, const char *extra,
sym_expr_t vcc_Eval_Acl;
sym_expr_t vcc_Eval_Backend;
sym_expr_t vcc_Eval_Probe;
+enum var_type VCC_arg_type(const char **p);
/* vcc_obj.c */
extern const struct var vcc_vars[];
diff --git a/lib/libvcc/vcc_expr.c b/lib/libvcc/vcc_expr.c
index 62fbd0e..e371fb9 100644
--- a/lib/libvcc/vcc_expr.c
+++ b/lib/libvcc/vcc_expr.c
@@ -381,8 +381,8 @@ vcc_expr_fmt(struct vsb *d, int ind, const struct expr *e1)
/*--------------------------------------------------------------------
*/
-static enum var_type
-vcc_arg_type(const char **p)
+enum var_type
+VCC_arg_type(const char **p)
{
#define VCC_TYPE(a) if (!strcmp(#a, *p)) { *p += strlen(#a) + 1; return (a);}
@@ -674,13 +674,13 @@ vcc_func(struct vcc *tl, struct expr **e, const char *cfunc,
p = args;
if (extra == NULL)
extra = "";
- rfmt = vcc_arg_type(&p);
+ rfmt = VCC_arg_type(&p);
VTAILQ_INIT(&head);
while (*p != '\0') {
fa = calloc(sizeof *fa, 1);
AN(fa);
VTAILQ_INSERT_TAIL(&head, fa, list);
- fa->type = vcc_arg_type(&p);
+ fa->type = VCC_arg_type(&p);
if (fa->type == VOID && !memcmp(p, "PRIV_", 5)) {
fa->result = vcc_priv_arg(tl, p, name);
fa->name = "";
@@ -796,7 +796,8 @@ void
vcc_Eval_SymFunc(struct vcc *tl, struct expr **e, const struct symbol *sym)
{
- assert(sym->kind == SYM_FUNC || sym->kind == SYM_PROC);
+ assert(sym->kind == SYM_FUNC);
+ /* XXX */
AN(sym->cfunc);
AN(sym->name);
AN(sym->args);
@@ -862,6 +863,11 @@ vcc_expr4(struct vcc *tl, struct expr **e, enum var_type fmt)
return;
}
AN(sym);
+ if (sym->kind == SYM_FUNC && sym->fmt == VOID) {
+ VSB_printf(tl->sb, "Function returns VOID:\n");
+ vcc_ErrWhere(tl, tl->t);
+ return;
+ }
switch(sym->kind) {
case SYM_VAR:
case SYM_FUNC:
@@ -871,6 +877,7 @@ vcc_expr4(struct vcc *tl, struct expr **e, enum var_type fmt)
AN(sym->eval);
AZ(*e);
sym->eval(tl, e, sym);
+ ERRCHK(tl);
/* Unless asked for a HEADER, fold to string here */
if (*e && fmt != HEADER && (*e)->fmt == HEADER) {
vcc_expr_tostring(tl, e, STRING);
@@ -961,6 +968,7 @@ vcc_expr_mul(struct vcc *tl, struct expr **e, enum var_type fmt)
*e = NULL;
vcc_expr4(tl, e, fmt);
ERRCHK(tl);
+ AN(*e);
f3 = f2 = (*e)->fmt;
switch(f2) {
diff --git a/lib/libvcc/vcc_vmod.c b/lib/libvcc/vcc_vmod.c
index 38515b2..aca8890 100644
--- a/lib/libvcc/vcc_vmod.c
+++ b/lib/libvcc/vcc_vmod.c
@@ -244,10 +244,7 @@ vcc_ParseImport(struct vcc *tl)
sym->cfunc = p;
p += strlen(p) + 1;
sym->args = p;
-
- /* Functions which return VOID are procedures */
- if (!memcmp(p, "VOID\0", 5))
- sym->kind = SYM_PROC;
+ sym->fmt = VCC_arg_type(&p);
}
}
More information about the varnish-commit
mailing list