[master] 8756d0dcf Try to work around compilers which insist asserts must hold risk.

Poul-Henning Kamp phk at FreeBSD.org
Mon Nov 11 10:17:06 UTC 2019


commit 8756d0dcfd3ec65992b5bfc412599fb23c869b61
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Mon Nov 11 10:15:47 2019 +0000

    Try to work around compilers which insist asserts must hold risk.

diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index 3c3f1ba94..a8dcc0395 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -546,7 +546,6 @@ struct req {
 
 enum sess_attr {
 #define SESS_ATTR(UP, low, typ, len)	SA_##UP,
-	SA_TRANSPORT,
 #include "tbl/sess_attr.h"
 	SA_LAST
 };
diff --git a/bin/varnishd/cache/cache_session.c b/bin/varnishd/cache/cache_session.c
index 3548d6c57..548674bec 100644
--- a/bin/varnishd/cache/cache_session.c
+++ b/bin/varnishd/cache/cache_session.c
@@ -49,6 +49,13 @@
 #include "vtim.h"
 #include "waiter/waiter.h"
 
+static const struct {
+	const char		*type;
+} sess_attr[SA_LAST] = {
+#define SESS_ATTR(UC, lc, typ, len) [SA_##UC] = { #typ },
+#include "tbl/sess_attr.h"
+};
+
 /*--------------------------------------------------------------------*/
 
 void
@@ -151,15 +158,9 @@ SES_Set_String_Attr(struct sess *sp, enum sess_attr a, const char *src)
 	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
 	AN(src);
 
-	/*lint -save -e506 -e774 */
-	switch (a) {
-#define SESS_ATTR(UP, low, typ, len) \
-		case SA_##UP: if (len > 0) WRONG("wrong: " #UP); break;
-#include "tbl/sess_attr.h"
-		default:
-			WRONG("wrong sess_attr");
-	}
-	/*lint -restore */
+	assert (a >= SA_TRANSPORT && a <  SA_LAST);
+	if (strcmp(sess_attr[a].type, "char"))
+		WRONG("wrong sess_attr: not char");
 
 	ses_reserve_attr(sp, a, &q, strlen(src) + 1);
 	strcpy(q, src);
@@ -172,15 +173,9 @@ SES_Get_String_Attr(const struct sess *sp, enum sess_attr a)
 
 	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
 
-	/*lint -save -e506 -e774 */
-	switch (a) {
-#define SESS_ATTR(UP, low, typ, len) \
-		case SA_##UP: if (len > 0) WRONG("wrong: " #UP); break;
-#include "tbl/sess_attr.h"
-		default:
-			WRONG("wrong sess_attr");
-	}
-	/*lint -restore */
+	assert (a >= SA_TRANSPORT && a <  SA_LAST);
+	if (strcmp(sess_attr[a].type, "char"))
+		WRONG("wrong sess_attr: not char");
 
 	if (ses_get_attr(sp, a, &q) < 0)
 		return (NULL);
diff --git a/include/tbl/sess_attr.h b/include/tbl/sess_attr.h
index 5276a1861..f4f4de0b0 100644
--- a/include/tbl/sess_attr.h
+++ b/include/tbl/sess_attr.h
@@ -33,6 +33,7 @@
 /*lint -save -e525 -e539 */
 
 //        upper           lower         type		    len
+SESS_ATTR(TRANSPORT,	  transport,	void,    	    0)
 SESS_ATTR(REMOTE_ADDR,	  remote_addr,	struct suckaddr,    vsa_suckaddr_len)
 SESS_ATTR(LOCAL_ADDR,	  local_addr,	struct suckaddr,    vsa_suckaddr_len)
 SESS_ATTR(CLIENT_ADDR,	  client_addr,	struct suckaddr,    vsa_suckaddr_len)


More information about the varnish-commit mailing list