Commit 02916817 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

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
parent fb65f18f
......@@ -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");
}
}
......@@ -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
......@@ -140,8 +148,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
......
......@@ -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;
......
......@@ -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] = {{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment