Permalink
Browse files

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
  • Loading branch information...
bsdphk committed Jan 9, 2019
1 parent fb65f18 commit 02916817dff50fb50b02e042a0e975434499ff1b
Showing with 18 additions and 14 deletions.
  1. +0 −7 bin/varnishtest/tests/m00000.vtc
  2. +9 −2 bin/varnishtest/tests/v00058.vtc
  3. +8 −5 lib/libvcc/vcc_expr.c
  4. +1 −0 lib/libvcc/vcc_types.c
@@ -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] = {{

0 comments on commit 0291681

Please sign in to comment.