r4459 - in trunk/varnish-cache: bin/varnishtest lib/libvcl

phk at projects.linpro.no phk at projects.linpro.no
Thu Jan 14 12:59:57 CET 2010


Author: phk
Date: 2010-01-14 12:59:57 +0100 (Thu, 14 Jan 2010)
New Revision: 4459

Modified:
   trunk/varnish-cache/bin/varnishtest/vtc.c
   trunk/varnish-cache/lib/libvcl/vcc_acl.c
   trunk/varnish-cache/lib/libvcl/vcc_var.c
Log:
Use the new bprintf() macros to avoid some (v)asprintf() calls.



Modified: trunk/varnish-cache/bin/varnishtest/vtc.c
===================================================================
--- trunk/varnish-cache/bin/varnishtest/vtc.c	2010-01-14 11:58:48 UTC (rev 4458)
+++ trunk/varnish-cache/bin/varnishtest/vtc.c	2010-01-14 11:59:57 UTC (rev 4459)
@@ -89,8 +89,7 @@
 	va_list ap;
 
 	if (instance != NULL) {
-		assert (snprintf(buf, sizeof buf, "%s_%s", instance, name)
-		    < sizeof buf);
+		bprintf(buf, "%s_%s", instance, name);
 		name = buf;
 	}
 
@@ -109,8 +108,9 @@
 		va_start(ap, fmt);
 		free(m->val);
 		m->val = NULL;
-		assert(vasprintf(&m->val, fmt, ap) >= 0);
+		vbprintf(buf, fmt, ap);
 		va_end(ap);
+		m->val = strdup(buf);
 		AN(m->val);
 		vtc_log(vl, 4, "macro def %s=%s", name, m->val);
 	} else if (m != NULL) {

Modified: trunk/varnish-cache/lib/libvcl/vcc_acl.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_acl.c	2010-01-14 11:58:48 UTC (rev 4458)
+++ trunk/varnish-cache/lib/libvcl/vcc_acl.c	2010-01-14 11:59:57 UTC (rev 4459)
@@ -47,7 +47,6 @@
 #include "vcc_priv.h"
 #include "vcc_compile.h"
 #include "libvarnish.h"
-#include "compat/vasprintf.h"
 
 struct acl_e {
 	VTAILQ_ENTRY(acl_e)	list;
@@ -456,7 +455,7 @@
 vcc_Cond_Ip(const struct var *vp, struct tokenlist *tl)
 {
 	unsigned tcond;
-	char *acln;
+	char acln[32];
 
 	switch (tl->t->tok) {
 	case '~':
@@ -473,13 +472,11 @@
 		VTAILQ_INIT(&tl->acl);
 		tcond = tl->t->tok;
 		vcc_NextToken(tl);
-		assert(asprintf(&acln, "%u", tl->cnt) > 0);
-		AN(acln);
+		bprintf(acln, "%u", tl->cnt);
 		vcc_acl_entry(tl);
 		vcc_acl_emit(tl, acln, 1);
 		Fb(tl, 1, "%smatch_acl_anon_%s(sp, %s)\n",
 		    (tcond == T_NEQ ? "!" : ""), acln, vp->rname);
-		free(acln);
 		break;
 	default:
 		vsb_printf(tl->sb, "Invalid condition ");
@@ -495,7 +492,7 @@
 vcc_Acl(struct tokenlist *tl)
 {
 	struct token *an;
-	char *acln;
+	char acln[1024];
 
 	vcc_NextToken(tl);
 	VTAILQ_INIT(&tl->acl);
@@ -505,8 +502,7 @@
 	vcc_NextToken(tl);
 
 	vcc_AddDef(tl, an, R_ACL);
-	assert(asprintf(&acln, "%.*s", PF(an)) > 0);
-	AN(acln);
+	bprintf(acln, "%.*s", PF(an));
 
 	ExpectErr(tl, '{');
 	vcc_NextToken(tl);
@@ -521,6 +517,4 @@
 	vcc_NextToken(tl);
 
 	vcc_acl_emit(tl, acln, 0);
-
-	free(acln);
 }

Modified: trunk/varnish-cache/lib/libvcl/vcc_var.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_var.c	2010-01-14 11:58:48 UTC (rev 4458)
+++ trunk/varnish-cache/lib/libvcl/vcc_var.c	2010-01-14 11:59:57 UTC (rev 4459)
@@ -40,7 +40,6 @@
 #include "vcc_priv.h"
 #include "vcc_compile.h"
 #include "libvarnish.h"
-#include "compat/vasprintf.h"
 
 /*--------------------------------------------------------------------*/
 
@@ -49,7 +48,8 @@
 {
 	char *p;
 	struct var *v;
-	int i;
+	int i, l;
+	char buf[258];
 
 	(void)tl;
 
@@ -65,16 +65,22 @@
 	v->fmt = STRING;
 	v->hdr = vh->hdr;
 	v->methods = vh->methods;
-	assert(asprintf(&p, "VRT_GetHdr(sp, %s, \"\\%03o%s:\")", v->hdr,
-	    (unsigned)(strlen(v->name + vh->len) + 1), v->name + vh->len) > 0);
-	AN(p);
-	TlFree(tl, p);
+	l = strlen(v->name + vh->len) + 1;
+
+	bprintf(buf, "VRT_GetHdr(sp, %s, \"\\%03o%s:\")",
+	    v->hdr, (unsigned)l, v->name + vh->len);
+	i = strlen(buf);
+	p = TlAlloc(tl, i + 1);
+	memcpy(p, buf, i + 1);
 	v->rname = p;
-	assert(asprintf(&p, "VRT_SetHdr(sp, %s, \"\\%03o%s:\", ", v->hdr,
-	    (unsigned)(strlen(v->name + vh->len) + 1), v->name + vh->len) > 0);
-	AN(p);
-	TlFree(tl, p);
+
+	bprintf(buf, "VRT_SetHdr(sp, %s, \"\\%03o%s:\", ",
+	    v->hdr, (unsigned)l, v->name + vh->len);
+	i = strlen(buf);
+	p =  TlAlloc(tl, i + 1);
+	memcpy(p, buf, i + 1);
 	v->lname = p;
+
 	return (v);
 }
 



More information about the varnish-commit mailing list