[master] 9357447 Change VCL::INT from C::int to C::long to gain more range on 64bit architectures.

Poul-Henning Kamp phk at varnish-cache.org
Wed Oct 10 09:54:16 CEST 2012


commit 935744727402361ee69133a84e880fff939ad2a4
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Wed Oct 10 07:52:32 2012 +0000

    Change VCL::INT from C::int to C::long to gain more range on 64bit
    architectures.
    
    NB:  VMOD writers need to review/revise use of the INT type.
    
    Fixes #1204

diff --git a/bin/varnishd/cache/cache_vrt.c b/bin/varnishd/cache/cache_vrt.c
index 477d337..a2dd8cd 100644
--- a/bin/varnishd/cache/cache_vrt.c
+++ b/bin/varnishd/cache/cache_vrt.c
@@ -315,20 +315,20 @@ VRT_IP_string(const struct req *req, const struct sockaddr_storage *sa)
 }
 
 char *
-VRT_int_string(const struct req *req, int num)
+VRT_INT_string(const struct req *req, long num)
 {
 	char *p;
 	int size;
 
 	CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
-	size = snprintf(NULL, 0, "%d", num) + 1;
+	size = snprintf(NULL, 0, "%ld", num) + 1;
 	AN(p = WS_Alloc(req->http->ws, size));
-	assert(snprintf(p, size, "%d", num) < size);
+	assert(snprintf(p, size, "%ld", num) < size);
 	return (p);
 }
 
 char *
-VRT_double_string(const struct req *req, double num)
+VRT_REAL_string(const struct req *req, double num)
 {
 	char *p;
 	int size;
@@ -341,7 +341,7 @@ VRT_double_string(const struct req *req, double num)
 }
 
 char *
-VRT_time_string(const struct req *req, double t)
+VRT_TIME_string(const struct req *req, double t)
 {
 	char *p;
 
@@ -353,7 +353,7 @@ VRT_time_string(const struct req *req, double t)
 }
 
 const char *
-VRT_backend_string(const struct req *req, const struct director *d)
+VRT_BACKEND_string(const struct req *req, const struct director *d)
 {
 	CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
 	if (d == NULL)
@@ -364,7 +364,7 @@ VRT_backend_string(const struct req *req, const struct director *d)
 }
 
 const char *
-VRT_bool_string(const struct req *req, unsigned val)
+VRT_BOOL_string(const struct req *req, unsigned val)
 {
 
 	CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
diff --git a/bin/varnishd/cache/cache_vrt_var.c b/bin/varnishd/cache/cache_vrt_var.c
index 61000a1..535e5ee 100644
--- a/bin/varnishd/cache/cache_vrt_var.c
+++ b/bin/varnishd/cache/cache_vrt_var.c
@@ -98,7 +98,7 @@ VRT_DO_HDR(beresp,  response,	req->busyobj->beresp,	HTTP_HDR_RESPONSE)
 
 #define VRT_DO_STATUS(obj, http)				\
 void								\
-VRT_l_##obj##_status(const struct req *req, int num)		\
+VRT_l_##obj##_status(const struct req *req, long num)	\
 {								\
 								\
 	CHECK_OBJ_NOTNULL(req, REQ_MAGIC);			\
@@ -106,7 +106,7 @@ VRT_l_##obj##_status(const struct req *req, int num)		\
 	http->status = (uint16_t)num;				\
 }								\
 								\
-int								\
+long								\
 VRT_r_##obj##_status(const struct req *req)			\
 {								\
 								\
@@ -271,7 +271,7 @@ VRT_r_beresp_backend_ip(const struct req *req)
 	return(req->busyobj->vbc->addr);
 }
 
-int
+long
 VRT_r_beresp_backend_port(const struct req *req)
 {
 
@@ -342,7 +342,7 @@ VRT_r_req_esi(const struct req *req)
 	return (!req->disable_esi);
 }
 
-int
+long
 VRT_r_req_esi_level(const struct req *req)
 {
 
@@ -363,7 +363,7 @@ VRT_r_req_can_gzip(const struct req *req)
 
 /*--------------------------------------------------------------------*/
 
-int
+long
 VRT_r_req_restarts(const struct req *req)
 {
 
@@ -517,7 +517,7 @@ VRT_r_server_hostname(const struct req *req)
  * XXX: This is pessimistically silly
  */
 
-int
+long
 VRT_r_server_port(const struct req *req)
 {
 	int i;
@@ -533,7 +533,7 @@ VRT_r_server_port(const struct req *req)
 
 /*--------------------------------------------------------------------*/
 
-int
+long
 VRT_r_obj_hits(const struct req *req)
 {
 
diff --git a/bin/varnishd/flint.lnt b/bin/varnishd/flint.lnt
index 2a15a34..f0dfd9a 100644
--- a/bin/varnishd/flint.lnt
+++ b/bin/varnishd/flint.lnt
@@ -113,6 +113,9 @@
 -emacro(436, SLTM)
 
 //////////////
++libh netinet/tcp.h
+-elib(46)
+//////////////
 
 +libh mgt_event.h
 
diff --git a/include/vrt.h b/include/vrt.h
index 20545fc..2029f7a 100644
--- a/include/vrt.h
+++ b/include/vrt.h
@@ -208,11 +208,11 @@ 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 *, int);
-char *VRT_double_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_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);
 
 #define VRT_done(req, hand)			\
 	do {					\
diff --git a/lib/libvcl/generate.py b/lib/libvcl/generate.py
index 3a1daa1..ecc3a14 100755
--- a/lib/libvcl/generate.py
+++ b/lib/libvcl/generate.py
@@ -482,7 +482,7 @@ vcltypes = {
 	'TIME':		"double",
 	'DURATION':	"double",
 	'BYTES':	"double",
-	'INT':		"int",
+	'INT':		"long",
 	'HEADER':	"const char *",
 }
 
diff --git a/lib/libvcl/vcc_expr.c b/lib/libvcl/vcc_expr.c
index 8fbaa04..72c26a9 100644
--- a/lib/libvcl/vcc_expr.c
+++ b/lib/libvcl/vcc_expr.c
@@ -423,15 +423,15 @@ 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_double_string(req, \v1)"; break;
+	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;
 			 /* XXX: should DURATION insist on "s" suffix ? */
-	case INT:	p = "VRT_int_string(req, \v1)"; break;
+	case INT:	p = "VRT_INT_string(req, \v1)"; break;
 	case IP:	p = "VRT_IP_string(req, \v1)"; break;
-	case BYTES:	p = "VRT_double_string(req, \v1)"; break; /* XXX */
-	case REAL:	p = "VRT_double_string(req, \v1)"; break;
-	case TIME:	p = "VRT_time_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;
 	default:	break;
 	}
 	if (p != NULL) {
diff --git a/lib/libvcl/vmodtool.py b/lib/libvcl/vmodtool.py
index d32eb4a..e7edbde 100755
--- a/lib/libvcl/vmodtool.py
+++ b/lib/libvcl/vmodtool.py
@@ -55,7 +55,7 @@ ctypes = {
 	'TIME':		"double",
 	'REAL':		"double",
 	'DURATION':	"double",
-	'INT':		"int",
+	'INT':		"long",
 	'HEADER':	"enum gethdr_e, const char *",
 	'PRIV_VCL':	"struct vmod_priv *",
 	'PRIV_CALL':	"struct vmod_priv *",
diff --git a/lib/libvmod_std/vmod_std.c b/lib/libvmod_std/vmod_std.c
index 037ffdd..e31b0c8 100644
--- a/lib/libvmod_std/vmod_std.c
+++ b/lib/libvmod_std/vmod_std.c
@@ -46,12 +46,13 @@
 #include "vcc_if.h"
 
 void __match_proto__(td_std_set_ip_tos)
-vmod_set_ip_tos(struct req *req, int tos)
+vmod_set_ip_tos(struct req *req, long tos)
 {
+	int itos = tos;
 
 	CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
 	VTCP_Assert(setsockopt(req->sp->fd,
-	    IPPROTO_IP, IP_TOS, &tos, sizeof(tos)));
+	    IPPROTO_IP, IP_TOS, &itos, sizeof(itos)));
 }
 
 static const char *
@@ -150,7 +151,7 @@ vmod_log(struct req *req, const char *fmt, ...)
 }
 
 void __match_proto__(td_std_syslog)
-vmod_syslog(struct req *req, int fac, const char *fmt, ...)
+vmod_syslog(struct req *req, long fac, const char *fmt, ...)
 {
 	char *p;
 	unsigned u;
@@ -163,7 +164,7 @@ vmod_syslog(struct req *req, int fac, const char *fmt, ...)
 	p = VRT_StringList(p, u, fmt, ap);
 	va_end(ap);
 	if (p != NULL)
-		syslog(fac, "%s", p);
+		syslog((int)fac, "%s", p);
 	WS_Release(req->ws, 0);
 }
 
diff --git a/lib/libvmod_std/vmod_std_conversions.c b/lib/libvmod_std/vmod_std_conversions.c
index 45cc7a1..e728611 100644
--- a/lib/libvmod_std/vmod_std_conversions.c
+++ b/lib/libvmod_std/vmod_std_conversions.c
@@ -88,11 +88,11 @@ vmod_duration(struct req *req, const char *p, double d)
 	return (r);
 }
 
-int __match_proto__()
-vmod_integer(struct req *req, const char *p, int i)
+long __match_proto__()
+vmod_integer(struct req *req, const char *p, long i)
 {
 	char *e;
-	int r;
+	long r;
 
 	CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
 



More information about the varnish-commit mailing list