[master] 8641ba8 Remove the req argument from the VCL foo-to-string conversion functions, all they need is a workspace. Some of them don't even need that.

Poul-Henning Kamp phk at varnish-cache.org
Tue Apr 16 11:27:25 CEST 2013


commit 8641ba85c8a7ac73bddcab2329158e57d24af01d
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Tue Apr 16 09:26:50 2013 +0000

    Remove the req argument from the VCL foo-to-string conversion functions,
    all they need is a workspace.  Some of them don't even need that.

diff --git a/bin/varnishd/cache/cache_vrt.c b/bin/varnishd/cache/cache_vrt.c
index d6dfef0..1551790 100644
--- a/bin/varnishd/cache/cache_vrt.c
+++ b/bin/varnishd/cache/cache_vrt.c
@@ -303,7 +303,7 @@ VRT_r_now(const struct req *req)
 /*--------------------------------------------------------------------*/
 
 char *
-VRT_IP_string(const struct req *req, const struct sockaddr_storage *sa)
+VRT_IP_string(struct ws *ws, const struct sockaddr_storage *sa)
 {
 	char *p;
 	const struct sockaddr_in *si4;
@@ -311,7 +311,7 @@ VRT_IP_string(const struct req *req, const struct sockaddr_storage *sa)
 	const void *addr;
 	int len;
 
-	CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
+	CHECK_OBJ_NOTNULL(ws, WS_MAGIC);
 	switch (sa->ss_family) {
 	case AF_INET:
 		len = INET_ADDRSTRLEN;
@@ -327,65 +327,62 @@ VRT_IP_string(const struct req *req, const struct sockaddr_storage *sa)
 		INCOMPL();
 	}
 	XXXAN(len);
-	AN(p = WS_Alloc(req->http->ws, len));
+	AN(p = WS_Alloc(ws, len));
 	AN(inet_ntop(sa->ss_family, addr, p, len));
 	return (p);
 }
 
 char *
-VRT_INT_string(const struct req *req, long num)
+VRT_INT_string(struct ws *ws, long num)
 {
 	char *p;
 	int size;
 
-	CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
+	CHECK_OBJ_NOTNULL(ws, WS_MAGIC);
 	size = snprintf(NULL, 0, "%ld", num) + 1;
-	AN(p = WS_Alloc(req->http->ws, size));
+	AN(p = WS_Alloc(ws, size));
 	assert(snprintf(p, size, "%ld", num) < size);
 	return (p);
 }
 
 char *
-VRT_REAL_string(const struct req *req, double num)
+VRT_REAL_string(struct ws *ws, double num)
 {
 	char *p;
 	int size;
 
-	CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
+	CHECK_OBJ_NOTNULL(ws, WS_MAGIC);
 	size = snprintf(NULL, 0, "%.3f", num) + 1;
-	AN(p = WS_Alloc(req->http->ws, size));
+	AN(p = WS_Alloc(ws, size));
 	assert(snprintf(p, size, "%.3f", num) < size);
 	return (p);
 }
 
 char *
-VRT_TIME_string(const struct req *req, double t)
+VRT_TIME_string(struct ws *ws, double t)
 {
 	char *p;
 
-	CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
-	p = WS_Alloc(req->http->ws, VTIM_FORMAT_SIZE);
+	CHECK_OBJ_NOTNULL(ws, WS_MAGIC);
+	p = WS_Alloc(ws, VTIM_FORMAT_SIZE);
 	if (p != NULL)
 		VTIM_format(t, p);
 	return (p);
 }
 
 const char *
-VRT_BACKEND_string(const struct req *req, const struct director *d)
+VRT_BACKEND_string(const struct director *d)
 {
-	CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
-	if (d == NULL)
-		d = req->director;
 	if (d == NULL)
 		return (NULL);
+	CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC);
 	return (d->vcl_name);
 }
 
 const char *
-VRT_BOOL_string(const struct req *req, unsigned val)
+VRT_BOOL_string(unsigned val)
 {
 
-	CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
 	return (val ? "true" : "false");
 }
 
diff --git a/include/vrt.h b/include/vrt.h
index 228781d..2c05a17 100644
--- a/include/vrt.h
+++ b/include/vrt.h
@@ -32,6 +32,7 @@
  */
 
 struct req;
+struct ws;
 struct vsb;
 struct cli;
 struct director;
@@ -224,12 +225,12 @@ int VRT_Stv(const char *nm);
 
 /* Convert things to string */
 
-char *VRT_IP_string(const struct req *, const struct sockaddr_storage *sa);
-char *VRT_INT_string(const struct req *, long);
-char *VRT_REAL_string(const struct req *, double);
-char *VRT_TIME_string(const struct req *, double);
-const char *VRT_BOOL_string(const struct req *, unsigned);
-const char *VRT_BACKEND_string(const struct req *, const struct director *d);
+char *VRT_IP_string(struct ws *, const struct sockaddr_storage *sa);
+char *VRT_INT_string(struct ws *, long);
+char *VRT_REAL_string(struct ws *, double);
+char *VRT_TIME_string(struct ws *, double);
+const char *VRT_BOOL_string(unsigned);
+const char *VRT_BACKEND_string(const struct director *d);
 
 #define VRT_done(req, hand)			\
 	do {					\
diff --git a/lib/libvcl/vcc_expr.c b/lib/libvcl/vcc_expr.c
index b6790aa..e2a2256 100644
--- a/lib/libvcl/vcc_expr.c
+++ b/lib/libvcl/vcc_expr.c
@@ -402,22 +402,22 @@ vcc_expr_tostring(struct expr **e, enum var_type fmt)
 
 	p = NULL;
 	switch((*e)->fmt) {
-	case BACKEND:	p = "VRT_BACKEND_string(req, \v1)"; break;
-	case BOOL:	p = "VRT_BOOL_string(req, \v1)"; break;
-	case DURATION:	p = "VRT_REAL_string(req, \v1)"; break;
+	case BACKEND:	p = "VRT_BACKEND_string(\v1)"; break;
+	case BOOL:	p = "VRT_BOOL_string(\v1)"; break;
+	case DURATION:	p = "VRT_REAL_string(ws, \v1)"; break;
 			 /* XXX: should DURATION insist on "s" suffix ? */
 	case INT:
 		if (vcc_isconst(*e)) {
 			p = "\"\v1\"";
 			constant = EXPR_CONST;
 		} else {
-			p = "VRT_INT_string(req, \v1)";
+			p = "VRT_INT_string(ws, \v1)";
 		}
 		break;
-	case IP:	p = "VRT_IP_string(req, \v1)"; break;
-	case BYTES:	p = "VRT_REAL_string(req, \v1)"; break; /* XXX */
-	case REAL:	p = "VRT_REAL_string(req, \v1)"; break;
-	case TIME:	p = "VRT_TIME_string(req, \v1)"; break;
+	case IP:	p = "VRT_IP_string(ws, \v1)"; break;
+	case BYTES:	p = "VRT_REAL_string(ws, \v1)"; break; /* XXX */
+	case REAL:	p = "VRT_REAL_string(ws, \v1)"; break;
+	case TIME:	p = "VRT_TIME_string(ws, \v1)"; break;
 	case HEADER:	p = "VRT_GetHdr(req, \v1)"; break;
 	case ENUM:
 	case STRING:



More information about the varnish-commit mailing list