[master] 5341e6770 Polish vcc_act_call()
Nils Goroll
nils.goroll at uplex.de
Wed Feb 17 16:18:09 UTC 2021
commit 5341e67700d1f2e50454a226da3a0f8989a6334f
Author: Nils Goroll <nils.goroll at uplex.de>
Date: Wed Feb 17 17:15:08 2021 +0100
Polish vcc_act_call()
Diff best viewed with -b option
- avoid the second call to VCC_SymbolGet(), unless necessary
- reorder from simple to complex
Ref 7ec28f1ae91bd39e6e89beb7dffd4248c5054414
diff --git a/bin/varnishtest/tests/v00020.vtc b/bin/varnishtest/tests/v00020.vtc
index 9f93b241d..68570d106 100644
--- a/bin/varnishtest/tests/v00020.vtc
+++ b/bin/varnishtest/tests/v00020.vtc
@@ -37,6 +37,11 @@ varnish v1 -errvcl {Symbol 'vcl_recv' type (sub) can not be used in expression.}
}
}
+varnish v1 -errvcl {Symbol 'acl' type (reserved) can not be used in expression.} {
+ import std;
+ sub vcl_recv { call acl; }
+}
+
varnish v1 -errvcl {Operator * not possible on type STRING.} {
sub vcl_recv {
set req.http.foo = "bla" * "foo";
@@ -378,9 +383,9 @@ varnish v1 -errvcl {'||' must be preceeded by BOOL, found REAL.} {
sub vcl_recv { if (std.random(0,1) || 0) { } }
}
-varnish v1 -errvcl {Symbol 'acl' has wrong type (reserved), expected sub:} {
+varnish v1 -errvcl {Symbol 'acl' has wrong type (reserved), expected acl:} {
import std;
- sub vcl_recv { call acl; }
+ sub vcl_recv { if (client.ip ~ acl) {} }
}
server s1 {
diff --git a/lib/libvcc/vcc_action.c b/lib/libvcc/vcc_action.c
index cc99c8537..71c9b91db 100644
--- a/lib/libvcc/vcc_action.c
+++ b/lib/libvcc/vcc_action.c
@@ -50,41 +50,45 @@ vcc_act_call(struct vcc *tl, struct token *t, struct symbol *sym)
(void)t;
ExpectErr(tl, ID);
t0 = tl->t;
- sym = VCC_SymbolGet(tl, SYM_MAIN, SYM_NONE, SYMTAB_NOERR, XREF_NONE);
- tl->t = t0;
- // only functions/methods may evaluate to SUB
- if (sym != NULL && (sym->kind == SYM_FUNC || sym->kind == SYM_METHOD)) {
- u = tl->unique++;
-
- Fb(tl, 1, "{\n");
- tl->indent += INDENT;
- Fb(tl, 2, "VCL_SUB call_%u =\n", u);
- tl->indent += INDENT;
- vcc_Expr(tl, SUB);
- Fb(tl, 2, ";\n\n");
- SkipToken(tl, ';');
- tl->indent -= INDENT;
- Fb(tl, 2, "if (call_%u == NULL) {\n", u);
- Fb(tl, 2, " VRT_fail(ctx, \"Tried to call NULL SUB near"
- " source %%u line %%u\",\n");
- Fb(tl, 2, " VGC_ref[%u].source,\n", tl->cnt);
- Fb(tl, 2, " VGC_ref[%u].line);\n", tl->cnt);
- Fb(tl, 2, " END_;\n");
- Fb(tl, 2, "}\n");
- Fb(tl, 2, "call_%u->func(ctx, VSUB_STATIC, NULL);\n", u);
- tl->indent -= INDENT;
- Fb(tl, 1, "}\n");
+ sym = VCC_SymbolGet(tl, SYM_MAIN, SYM_NONE, SYMTAB_NOERR, XREF_REF);
+
+ if (sym == NULL)
+ sym = VCC_SymbolGet(tl, SYM_MAIN, SYM_SUB, SYMTAB_CREATE,
+ XREF_REF);
+
+ if (sym == NULL)
return;
- }
- sym = VCC_SymbolGet(tl, SYM_MAIN, SYM_SUB, SYMTAB_CREATE, XREF_REF);
- if (sym != NULL) {
+ if (sym->kind == SYM_SUB) {
vcc_AddCall(tl, t0, sym);
VCC_GlobalSymbol(sym, SUB, "VGC_function");
Fb(tl, 1, "%s(ctx, VSUB_STATIC, NULL);\n", sym->lname);
SkipToken(tl, ';');
+ return;
}
+
+ tl->t = t0;
+ u = tl->unique++;
+
+ Fb(tl, 1, "{\n");
+ tl->indent += INDENT;
+ Fb(tl, 2, "VCL_SUB call_%u =\n", u);
+ tl->indent += INDENT;
+ vcc_Expr(tl, SUB);
+ Fb(tl, 2, ";\n\n");
+ SkipToken(tl, ';');
+ tl->indent -= INDENT;
+ Fb(tl, 2, "if (call_%u == NULL) {\n", u);
+ Fb(tl, 2, " VRT_fail(ctx, \"Tried to call NULL SUB near"
+ " source %%u line %%u\",\n");
+ Fb(tl, 2, " VGC_ref[%u].source,\n", tl->cnt);
+ Fb(tl, 2, " VGC_ref[%u].line);\n", tl->cnt);
+ Fb(tl, 2, " END_;\n");
+ Fb(tl, 2, "}\n");
+ Fb(tl, 2, "call_%u->func(ctx, VSUB_STATIC, NULL);\n", u);
+ tl->indent -= INDENT;
+ Fb(tl, 1, "}\n");
}
/*--------------------------------------------------------------------*/
More information about the varnish-commit
mailing list