[6.0] 9b64ca3d8 Align handling of STRINGS derived types.

Dridi Boukelmoune dridi.boukelmoune at gmail.com
Wed Oct 31 13:08:05 UTC 2018


commit 9b64ca3d8e2f9850ddd4635981633ca0a435e05b
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Wed Aug 22 06:52:48 2018 +0000

    Align handling of STRINGS derived types.
    
    Fixes:  #2745
    
    Conflicts:
            bin/varnishtest/tests/v00020.vtc

diff --git a/lib/libvcc/vcc_compile.h b/lib/libvcc/vcc_compile.h
index 3a6860abe..01f2d92c0 100644
--- a/lib/libvcc/vcc_compile.h
+++ b/lib/libvcc/vcc_compile.h
@@ -103,6 +103,7 @@ struct type {
 	const char		*name;
 	const char		*tostring;
 	vcc_type_t		multype;
+	int			stringform;
 };
 
 #define VCC_TYPE(foo)		extern const struct type foo[1];
diff --git a/lib/libvcc/vcc_expr.c b/lib/libvcc/vcc_expr.c
index b420dedf8..4bc8ea5d9 100644
--- a/lib/libvcc/vcc_expr.c
+++ b/lib/libvcc/vcc_expr.c
@@ -73,7 +73,7 @@ vcc_islit(const struct expr *e)
 static const char *
 vcc_utype(vcc_type_t t)
 {
-	if (t == STRINGS || t == STRING_LIST)
+	if (t == STRINGS || t->stringform)
 		t = STRING;
 	return (t->name);
 }
@@ -278,7 +278,7 @@ vcc_expr_tostring(struct vcc *tl, struct expr **e, vcc_type_t fmt)
 	uint8_t	constant = EXPR_VAR;
 
 	CHECK_OBJ_NOTNULL(*e, EXPR_MAGIC);
-	assert(fmt == STRINGS || fmt == STRING_LIST || fmt == STRING);
+	assert(fmt == STRINGS || fmt->stringform);
 	assert(fmt != (*e)->fmt);
 
 	p = (*e)->fmt->tostring;
@@ -361,6 +361,7 @@ vcc_Eval_Handle(struct vcc *tl, struct expr **e, struct token *t,
 	(void)t;
 	(void)tl;
 	AN(sym->rname);
+	AZ(type->stringform);
 
 	if (sym->type != STRING && type == STRINGS) {
 		*e = vcc_mk_expr(STRINGS, "\"%s\"", sym->name);
@@ -1274,22 +1275,26 @@ vcc_expr0(struct vcc *tl, struct expr **e, vcc_type_t fmt)
 	assert(fmt != STRINGS);
 	*e = NULL;
 	t1 = tl->t;
-	if (fmt == STRING_LIST || fmt == STRING)
+	if (fmt->stringform)
 		vcc_expr_cor(tl, e, STRINGS);
 	else
 		vcc_expr_cor(tl, e, fmt);
 	ERRCHK(tl);
-	assert((*e)->fmt != STRING_LIST && (*e)->fmt != STRING);
-
-	if ((*e)->fmt == STRINGS && fmt == STRING_LIST)
-		(*e)->fmt = STRING_LIST;
-	else if ((*e)->fmt == STRINGS && fmt == STRING)
-		*e = vcc_expr_edit(tl, STRING, "\vS", *e, NULL);
-	else if ((*e)->fmt == STRINGS && fmt == STRANDS) {
-		*e = vcc_expr_edit(tl, STRANDS, "\vT", (*e), NULL);
-	} else if ((*e)->fmt != STRINGS &&
-	    (fmt == STRING || fmt == STRING_LIST))
-		vcc_expr_tostring(tl, e, fmt);
+	assert(!(*e)->fmt->stringform);
+
+	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;
+		else if (fmt == STRING)
+			*e = vcc_expr_edit(tl, STRING, "\vS", *e, NULL);
+		else if (fmt == STRANDS)
+			*e = vcc_expr_edit(tl, STRANDS, "\vT", (*e), NULL);
+		else
+			WRONG("Unhandled stringform");
+	}
 
 	if ((*e)->fmt == STRING_LIST)
 		*e = vcc_expr_edit(tl, STRING_LIST,
diff --git a/lib/libvcc/vcc_types.c b/lib/libvcc/vcc_types.c
index dbeaacb09..2e5660994 100644
--- a/lib/libvcc/vcc_types.c
+++ b/lib/libvcc/vcc_types.c
@@ -131,11 +131,13 @@ const struct type STEVEDORE[1] = {{
 const struct type STRING[1] = {{
 	.magic =		TYPE_MAGIC,
 	.name =			"STRING",
+	.stringform =		1,
 }};
 
 const struct type STRANDS[1] = {{
 	.magic =		TYPE_MAGIC,
 	.name =			"STRANDS",
+	.stringform =		1,
 }};
 
 const struct type STRINGS[1] = {{
@@ -147,6 +149,7 @@ const struct type STRINGS[1] = {{
 const struct type STRING_LIST[1] = {{
 	.magic =		TYPE_MAGIC,
 	.name =			"STRING_LIST",
+	.stringform =		1,
 }};
 
 const struct type SUB[1] = {{


More information about the varnish-commit mailing list