[6.0] 7388d4c13 Implement stringifcation of STRANDS via a workspace allocation.
Dridi Boukelmoune
dridi.boukelmoune at gmail.com
Wed Jul 3 14:40:11 UTC 2019
commit 7388d4c1322b34ac71db812fe9666b7e8b4dcd74
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Wed Jan 9 10:44:55 2019 +0000
Implement stringifcation of STRANDS via a workspace allocation.
When a VMOD returns a STRANDS, it is a requirement that the storage
be stable, but that is not really different from any other type of
return value.
Completes #2873
diff --git a/bin/varnishtest/tests/m00000.vtc b/bin/varnishtest/tests/m00000.vtc
index e7f1d4ad1..355bb3c56 100644
--- a/bin/varnishtest/tests/m00000.vtc
+++ b/bin/varnishtest/tests/m00000.vtc
@@ -120,10 +120,3 @@ varnish v1 -errvcl {Expression has type STRING, expected REAL} {
set resp.http.who = std.random("foo", "bar");
}
}
-
-varnish v1 -errvcl {Cannot convert type STRING(STRANDS) to STRING(STRING_LIST)} {
- import debug;
- sub vcl_deliver {
- set resp.http.who = debug.return_strands(req.url + "bar");
- }
-}
diff --git a/bin/varnishtest/tests/v00058.vtc b/bin/varnishtest/tests/v00058.vtc
index d76e3d397..1a3f9cbd8 100644
--- a/bin/varnishtest/tests/v00058.vtc
+++ b/bin/varnishtest/tests/v00058.vtc
@@ -78,6 +78,13 @@ varnish v1 -arg "-i foobar" -vcl {
req.http.Foo + req.http.Unset + req.http.Bar);
debug.sethdr(resp.http.Hdr-6, req.http.Foo);
debug.sethdr(resp.http.Hdr-7, req.http.Unset);
+
+ set resp.http.Hdr-8 =
+ debug.return_strands(
+ debug.return_strands(
+ req.url + "<-->" + req.url
+ )
+ );
}
} -start
@@ -108,6 +115,7 @@ client c1 {
expect resp.http.Hdr-5 == "foobar"
expect resp.http.Hdr-6 == "foo"
expect resp.http.Hdr-7 == ""
+ expect resp.http.Hdr-8 == "/<-->/"
} -run
# out of workspace
@@ -141,8 +149,7 @@ varnish v1 -vcl+backend {
= debug.concatenate(req.http.Foo + req.http.Bar
+ req.http.Baz
+ req.http.Quux);
- }
- elsif (req.url == "/2") {
+ } elsif (req.url == "/2") {
# VRT_CollectStrands() invokes VCL failure.
set req.http.Result
= debug.collect(req.http.Foo + req.http.Bar
diff --git a/lib/libvcc/vcc_expr.c b/lib/libvcc/vcc_expr.c
index 61dca8e19..00b6ca700 100644
--- a/lib/libvcc/vcc_expr.c
+++ b/lib/libvcc/vcc_expr.c
@@ -186,8 +186,8 @@ vcc_expr_edit(struct vcc *tl, vcc_type_t fmt, const char *p, struct expr *e1,
" const char * strs_%u_s[%d];\n",
tl->unique, tl->unique, e3->nstr);
VSB_printf(e->vsb,
- "\v+\nVRT_BundleStrands(%d, &strs_%u_a, strs_%u_s,"
- "\v+\n%s,\nvrt_magic_string_end)\v-\v-",
+ "VRT_BundleStrands(%d, &strs_%u_a, strs_%u_s,"
+ "\v+\n%s,\nvrt_magic_string_end\v-\n)",
e3->nstr, tl->unique, tl->unique,
VSB_data(e3->vsb));
tl->unique++;
@@ -1313,6 +1313,12 @@ vcc_expr0(struct vcc *tl, struct expr **e, vcc_type_t fmt)
vcc_expr_cor(tl, e, fmt);
ERRCHK(tl);
+ if ((*e)->fmt == fmt)
+ return;
+
+ if ((*e)->fmt != STRINGS && fmt->stringform)
+ vcc_expr_tostring(tl, e, STRINGS);
+
if ((*e)->fmt->stringform) {
VSB_printf(tl->sb, "Cannot convert type %s(%s) to %s(%s)\n",
vcc_utype((*e)->fmt), (*e)->fmt->name,
@@ -1321,9 +1327,6 @@ vcc_expr0(struct vcc *tl, struct expr **e, vcc_type_t fmt)
return;
}
- if ((*e)->fmt != STRINGS && fmt->stringform)
- vcc_expr_tostring(tl, e, STRINGS);
-
if ((*e)->fmt == STRINGS && fmt->stringform) {
if (fmt == STRING_LIST)
(*e)->fmt = STRING_LIST;
diff --git a/lib/libvcc/vcc_types.c b/lib/libvcc/vcc_types.c
index 2e5660994..2d9208c64 100644
--- a/lib/libvcc/vcc_types.c
+++ b/lib/libvcc/vcc_types.c
@@ -138,6 +138,7 @@ const struct type STRANDS[1] = {{
.magic = TYPE_MAGIC,
.name = "STRANDS",
.stringform = 1,
+ .tostring = "VRT_CollectStrands(ctx,\v+\n\v1\v-\n)",
}};
const struct type STRINGS[1] = {{
More information about the varnish-commit
mailing list