[master] efa582f5e Add VRT_Strands2Bool() so we dont reassemble a multi-part string on the workspace to check if any element of it is non-NULL.

Poul-Henning Kamp phk at FreeBSD.org
Thu Jun 20 15:25:09 UTC 2019


commit efa582f5e8073fdc95e15d450bf7e112071febff
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Thu Jun 20 15:22:21 2019 +0000

    Add VRT_Strands2Bool() so we dont reassemble a multi-part string
    on the workspace to check if any element of it is non-NULL.

diff --git a/bin/varnishd/cache/cache_vrt.c b/bin/varnishd/cache/cache_vrt.c
index 348344846..fee4b8567 100644
--- a/bin/varnishd/cache/cache_vrt.c
+++ b/bin/varnishd/cache/cache_vrt.c
@@ -232,6 +232,22 @@ VRT_CompareStrands(VCL_STRANDS a, VCL_STRANDS b)
 	}
 }
 
+/*--------------------------------------------------------------------
+ * STRANDS to BOOL
+ */
+
+VCL_BOOL
+VRT_Strands2Bool(VCL_STRANDS s)
+{
+	int i;
+
+	AN(s);
+	for (i = 0; i < s->n; i++)
+		if (s->p[i] != NULL)
+			return (1);
+	return (0);
+}
+
 /*--------------------------------------------------------------------
  * Collapse a STRING_LIST in the space provided, or return NULL
  */
diff --git a/include/vrt.h b/include/vrt.h
index 92f3e71fa..0f022a3b2 100644
--- a/include/vrt.h
+++ b/include/vrt.h
@@ -52,6 +52,7 @@
  * binary/load-time compatible, increment MAJOR version
  *
  * unreleased (planned for 2019-09-15)
+ *	VCL_BOOL VRT_Strands2Bool(VCL_STRANDS) added.
  *	VRT_BundleStrands() moved to vcc_interface.h
  *	VRT_VCL_{Busy|Unbusy} changed to VRT_VCL_{Prevent|Allow}_Cold
  *	VRT_re[fl]_vcl changed to VRT_VCL_{Prevent|Allow}_Discard
@@ -530,6 +531,7 @@ VCL_STEVEDORE VRT_stevedore(const char *nm);
 /* Convert things to string */
 
 int VRT_CompareStrands(VCL_STRANDS a, VCL_STRANDS b);
+VCL_BOOL VRT_Strands2Bool(VCL_STRANDS);
 char *VRT_Strands(char *, size_t, VCL_STRANDS);
 VCL_STRING VRT_StrandsWS(struct ws *, const char *, VCL_STRANDS);
 VCL_STRING VRT_CollectStrands(VRT_CTX, VCL_STRANDS);
diff --git a/lib/libvcc/vcc_expr.c b/lib/libvcc/vcc_expr.c
index a23f61f35..6776a3f86 100644
--- a/lib/libvcc/vcc_expr.c
+++ b/lib/libvcc/vcc_expr.c
@@ -261,7 +261,7 @@ vcc_expr_tobool(struct vcc *tl, struct expr **e)
 	else if ((*e)->fmt == DURATION)
 		*e = vcc_expr_edit(tl, BOOL, "(\v1 > 0)", *e, NULL);
 	else if ((*e)->fmt == STRINGS)
-		*e = vcc_expr_edit(tl, BOOL, "(\vS != 0)", *e, NULL);
+		*e = vcc_expr_edit(tl, BOOL, "VRT_Strands2Bool(\vT)", *e, NULL);
 	/*
 	 * We do not provide automatic folding from REAL to BOOL
 	 * because comparing to zero is seldom an exact science


More information about the varnish-commit mailing list