[master] f178da1 More code polishing

Poul-Henning Kamp phk at varnish-cache.org
Tue Dec 6 09:40:02 CET 2011


commit f178da155efe9d4b7a1f65bcca2557032b94f42b
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Tue Dec 6 08:39:44 2011 +0000

    More code polishing
    
    Revert two lines that got last in previous commit.

diff --git a/bin/varnishd/cache/cache_esi_fetch.c b/bin/varnishd/cache/cache_esi_fetch.c
index aea28ed..d2f4c01 100644
--- a/bin/varnishd/cache/cache_esi_fetch.c
+++ b/bin/varnishd/cache/cache_esi_fetch.c
@@ -44,7 +44,7 @@
  */
 
 static ssize_t
-vef_read(struct worker *w, struct http_conn *htc, void *buf, ssize_t buflen,
+vef_read(struct worker *wrk, struct http_conn *htc, void *buf, ssize_t buflen,
     ssize_t bytes)
 {
 	ssize_t d;
@@ -56,7 +56,7 @@ vef_read(struct worker *w, struct http_conn *htc, void *buf, ssize_t buflen,
 		if (d < bytes)
 			bytes = d;
 	}
-	return (HTC_Read(w, htc, buf, bytes));
+	return (HTC_Read(wrk, htc, buf, bytes));
 }
 
 /*---------------------------------------------------------------------
@@ -64,24 +64,24 @@ vef_read(struct worker *w, struct http_conn *htc, void *buf, ssize_t buflen,
  */
 
 static int
-vfp_esi_bytes_uu(struct worker *w, struct http_conn *htc, ssize_t bytes)
+vfp_esi_bytes_uu(struct worker *wrk, struct http_conn *htc, ssize_t bytes)
 {
 	ssize_t wl;
 	struct storage *st;
 
-	CHECK_OBJ_NOTNULL(w, WORKER_MAGIC);
+	CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
 
 	while (bytes > 0) {
-		st = FetchStorage(w, 0);
+		st = FetchStorage(wrk, 0);
 		if (st == NULL)
 			return (-1);
-		wl = vef_read(w, htc,
+		wl = vef_read(wrk, htc,
 		    st->ptr + st->len, st->space - st->len, bytes);
 		if (wl <= 0)
 			return (wl);
-		VEP_Parse(w, (const char *)st->ptr + st->len, wl);
+		VEP_Parse(wrk, (const char *)st->ptr + st->len, wl);
 		st->len += wl;
-		w->busyobj->fetch_obj->len += wl;
+		wrk->busyobj->fetch_obj->len += wl;
 		bytes -= wl;
 	}
 	return (1);
@@ -92,7 +92,7 @@ vfp_esi_bytes_uu(struct worker *w, struct http_conn *htc, ssize_t bytes)
  */
 
 static int
-vfp_esi_bytes_gu(struct worker *w, struct http_conn *htc, ssize_t bytes)
+vfp_esi_bytes_gu(struct worker *wrk, struct http_conn *htc, ssize_t bytes)
 {
 	struct vgz *vg;
 	ssize_t wl;
@@ -101,23 +101,23 @@ vfp_esi_bytes_gu(struct worker *w, struct http_conn *htc, ssize_t bytes)
 	size_t dl;
 	const void *dp;
 
-	CHECK_OBJ_NOTNULL(w, WORKER_MAGIC);
-	vg = w->busyobj->vgz_rx;
+	CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
+	vg = wrk->busyobj->vgz_rx;
 
 	while (bytes > 0) {
 		if (VGZ_IbufEmpty(vg) && bytes > 0) {
-			wl = vef_read(w, htc, ibuf, sizeof ibuf, bytes);
+			wl = vef_read(wrk, htc, ibuf, sizeof ibuf, bytes);
 			if (wl <= 0)
 				return (wl);
 			VGZ_Ibuf(vg, ibuf, wl);
 			bytes -= wl;
 		}
-		if (VGZ_ObufStorage(w, vg))
+		if (VGZ_ObufStorage(wrk, vg))
 			return(-1);
 		i = VGZ_Gunzip(vg, &dp, &dl);
 		xxxassert(i == VGZ_OK || i == VGZ_END);
-		VEP_Parse(w, dp, dl);
-		w->busyobj->fetch_obj->len += dl;
+		VEP_Parse(wrk, dp, dl);
+		wrk->busyobj->fetch_obj->len += dl;
 	}
 	return (1);
 }
@@ -142,16 +142,16 @@ struct vef_priv {
  */
 
 static ssize_t
-vfp_vep_callback(struct worker *w, ssize_t l, enum vgz_flag flg)
+vfp_vep_callback(struct worker *wrk, ssize_t l, enum vgz_flag flg)
 {
 	struct vef_priv *vef;
 	size_t dl, px;
 	const void *dp;
 	int i;
 
-	CHECK_OBJ_NOTNULL(w, WORKER_MAGIC);
-	CHECK_OBJ_NOTNULL(w->busyobj, BUSYOBJ_MAGIC);
-	vef = w->busyobj->vef_priv;
+	CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
+	CHECK_OBJ_NOTNULL(wrk->busyobj, BUSYOBJ_MAGIC);
+	vef = wrk->busyobj->vef_priv;
 	CHECK_OBJ_NOTNULL(vef, VEF_MAGIC);
 	assert(l >= 0);
 
@@ -181,14 +181,14 @@ vfp_vep_callback(struct worker *w, ssize_t l, enum vgz_flag flg)
 			l = 0;
 		}
 		do {
-			if (VGZ_ObufStorage(w, vef->vgz)) {
+			if (VGZ_ObufStorage(wrk, vef->vgz)) {
 				vef->error = ENOMEM;
 				vef->tot += l;
 				return (vef->tot);
 			}
 			i = VGZ_Gzip(vef->vgz, &dp, &dl, flg);
 			vef->tot += dl;
-			w->busyobj->fetch_obj->len += dl;
+			wrk->busyobj->fetch_obj->len += dl;
 		} while (!VGZ_IbufEmpty(vef->vgz) ||
 		    (flg != VGZ_NORMAL && VGZ_ObufFull(vef->vgz)));
 		if (px != 0) {
@@ -205,24 +205,24 @@ vfp_vep_callback(struct worker *w, ssize_t l, enum vgz_flag flg)
 }
 
 static int
-vfp_esi_bytes_ug(struct worker *w, struct http_conn *htc, ssize_t bytes)
+vfp_esi_bytes_ug(struct worker *wrk, struct http_conn *htc, ssize_t bytes)
 {
 	ssize_t wl;
 	char ibuf[cache_param->gzip_stack_buffer];
 	struct vef_priv *vef;
 
-	CHECK_OBJ_NOTNULL(w, WORKER_MAGIC);
-	CHECK_OBJ_NOTNULL(w->busyobj, BUSYOBJ_MAGIC);
-	vef = w->busyobj->vef_priv;
+	CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
+	CHECK_OBJ_NOTNULL(wrk->busyobj, BUSYOBJ_MAGIC);
+	vef = wrk->busyobj->vef_priv;
 	CHECK_OBJ_NOTNULL(vef, VEF_MAGIC);
 
 	while (bytes > 0) {
-		wl = vef_read(w, htc, ibuf, sizeof ibuf, bytes);
+		wl = vef_read(wrk, htc, ibuf, sizeof ibuf, bytes);
 		if (wl <= 0)
 			return (wl);
 		bytes -= wl;
 		vef->bufp = ibuf;
-		VEP_Parse(w, ibuf, wl);
+		VEP_Parse(wrk, ibuf, wl);
 		assert(vef->bufp >= ibuf && vef->bufp <= ibuf + wl);
 		if (vef->error) {
 			errno = vef->error;
@@ -243,7 +243,7 @@ vfp_esi_bytes_ug(struct worker *w, struct http_conn *htc, ssize_t bytes)
  */
 
 static int
-vfp_esi_bytes_gg(struct worker *w, struct http_conn *htc, size_t bytes)
+vfp_esi_bytes_gg(struct worker *wrk, struct http_conn *htc, size_t bytes)
 {
 	ssize_t wl;
 	char ibuf[cache_param->gzip_stack_buffer];
@@ -253,29 +253,29 @@ vfp_esi_bytes_gg(struct worker *w, struct http_conn *htc, size_t bytes)
 	const void *dp;
 	int i;
 
-	CHECK_OBJ_NOTNULL(w, WORKER_MAGIC);
-	CHECK_OBJ_NOTNULL(w->busyobj, BUSYOBJ_MAGIC);
-	vef = w->busyobj->vef_priv;
+	CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
+	CHECK_OBJ_NOTNULL(wrk->busyobj, BUSYOBJ_MAGIC);
+	vef = wrk->busyobj->vef_priv;
 	CHECK_OBJ_NOTNULL(vef, VEF_MAGIC);
 	assert(sizeof ibuf >= 1024);
 	ibuf2[0] = 0; /* For Flexelint */
 
 	while (bytes > 0) {
-		wl = vef_read(w, htc, ibuf, sizeof ibuf, bytes);
+		wl = vef_read(wrk, htc, ibuf, sizeof ibuf, bytes);
 		if (wl <= 0)
 			return (wl);
 		bytes -= wl;
 
 		vef->bufp = ibuf;
-		VGZ_Ibuf(w->busyobj->vgz_rx, ibuf, wl);
+		VGZ_Ibuf(wrk->busyobj->vgz_rx, ibuf, wl);
 		do {
-			VGZ_Obuf(w->busyobj->vgz_rx, ibuf2, sizeof ibuf2);
-			i = VGZ_Gunzip(w->busyobj->vgz_rx, &dp, &dl);
+			VGZ_Obuf(wrk->busyobj->vgz_rx, ibuf2, sizeof ibuf2);
+			i = VGZ_Gunzip(wrk->busyobj->vgz_rx, &dp, &dl);
 			/* XXX: check i */
 			assert(i >= VGZ_OK);
 			vef->bufp = ibuf2;
 			if (dl > 0)
-				VEP_Parse(w, ibuf2, dl);
+				VEP_Parse(wrk, ibuf2, dl);
 			if (vef->error) {
 				errno = vef->error;
 				return (-1);
@@ -287,7 +287,7 @@ vfp_esi_bytes_gg(struct worker *w, struct http_conn *htc, size_t bytes)
 				    vef->bufp, dl);
 				vef->npend += dl;
 			}
-		} while (!VGZ_IbufEmpty(w->busyobj->vgz_rx));
+		} while (!VGZ_IbufEmpty(wrk->busyobj->vgz_rx));
 	}
 	return (1);
 }
@@ -296,108 +296,114 @@ vfp_esi_bytes_gg(struct worker *w, struct http_conn *htc, size_t bytes)
 /*---------------------------------------------------------------------*/
 
 static void __match_proto__()
-vfp_esi_begin(struct worker *w, size_t estimate)
+vfp_esi_begin(struct worker *wrk, size_t estimate)
 {
+	struct busyobj *bo;
 	struct vef_priv *vef;
 
-	CHECK_OBJ_NOTNULL(w, WORKER_MAGIC);
-	CHECK_OBJ_NOTNULL(w->busyobj, BUSYOBJ_MAGIC);
-
-	AZ(w->busyobj->vgz_rx);
-	if (w->busyobj->is_gzip && w->busyobj->do_gunzip) {
-		w->busyobj->vgz_rx = VGZ_NewUngzip(w, "U F E");
-		VEP_Init(w, NULL);
-	} else if (w->busyobj->is_gunzip && w->busyobj->do_gzip) {
+	(void)estimate;
+	CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
+	bo = wrk->busyobj;
+	CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);
+
+	AZ(bo->vgz_rx);
+	if (bo->is_gzip && bo->do_gunzip) {
+		bo->vgz_rx = VGZ_NewUngzip(wrk, "U F E");
+		VEP_Init(wrk, NULL);
+	} else if (bo->is_gunzip && bo->do_gzip) {
 		ALLOC_OBJ(vef, VEF_MAGIC);
 		AN(vef);
-		vef->vgz = VGZ_NewGzip(w, "G F E");
-		AZ(w->busyobj->vef_priv);
-		w->busyobj->vef_priv = vef;
-		VEP_Init(w, vfp_vep_callback);
-	} else if (w->busyobj->is_gzip) {
-		w->busyobj->vgz_rx = VGZ_NewUngzip(w, "U F E");
+		vef->vgz = VGZ_NewGzip(wrk, "G F E");
+		AZ(bo->vef_priv);
+		bo->vef_priv = vef;
+		VEP_Init(wrk, vfp_vep_callback);
+	} else if (bo->is_gzip) {
+		bo->vgz_rx = VGZ_NewUngzip(wrk, "U F E");
 		ALLOC_OBJ(vef, VEF_MAGIC);
 		AN(vef);
-		vef->vgz = VGZ_NewGzip(w, "G F E");
-		AZ(w->busyobj->vef_priv);
-		w->busyobj->vef_priv = vef;
-		VEP_Init(w, vfp_vep_callback);
+		vef->vgz = VGZ_NewGzip(wrk, "G F E");
+		AZ(bo->vef_priv);
+		bo->vef_priv = vef;
+		VEP_Init(wrk, vfp_vep_callback);
 	} else {
-		AZ(w->busyobj->vef_priv);
-		VEP_Init(w, NULL);
+		AZ(bo->vef_priv);
+		VEP_Init(wrk, NULL);
 	}
 
-	(void)estimate;
-	AN(w->busyobj->vep);
+	AN(bo->vep);
 }
 
 static int __match_proto__()
-vfp_esi_bytes(struct worker *w, struct http_conn *htc, ssize_t bytes)
+vfp_esi_bytes(struct worker *wrk, struct http_conn *htc, ssize_t bytes)
 {
+	struct busyobj *bo;
 	int i;
 
-	CHECK_OBJ_NOTNULL(w, WORKER_MAGIC);
-	AZ(w->busyobj->fetch_failed);
-	AN(w->busyobj->vep);
-	assert(&w->busyobj->htc == htc);
-	if (w->busyobj->is_gzip && w->busyobj->do_gunzip)
-		i = vfp_esi_bytes_gu(w, htc, bytes);
-	else if (w->busyobj->is_gunzip && w->busyobj->do_gzip)
-		i = vfp_esi_bytes_ug(w, htc, bytes);
-	else if (w->busyobj->is_gzip)
-		i = vfp_esi_bytes_gg(w, htc, bytes);
+	CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
+	bo = wrk->busyobj;
+	CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);
+
+	AZ(bo->fetch_failed);
+	AN(bo->vep);
+	assert(&bo->htc == htc);
+	if (bo->is_gzip && bo->do_gunzip)
+		i = vfp_esi_bytes_gu(wrk, htc, bytes);
+	else if (bo->is_gunzip && bo->do_gzip)
+		i = vfp_esi_bytes_ug(wrk, htc, bytes);
+	else if (bo->is_gzip)
+		i = vfp_esi_bytes_gg(wrk, htc, bytes);
 	else
-		i = vfp_esi_bytes_uu(w, htc, bytes);
-	AN(w->busyobj->vep);
+		i = vfp_esi_bytes_uu(wrk, htc, bytes);
+	AN(bo->vep);
 	return (i);
 }
 
 static int __match_proto__()
-vfp_esi_end(struct worker *w)
+vfp_esi_end(struct worker *wrk)
 {
 	struct vsb *vsb;
 	struct vef_priv *vef;
+	struct busyobj *bo;
 	ssize_t l;
 	int retval;
 
-	CHECK_OBJ_NOTNULL(w, WORKER_MAGIC);
-	CHECK_OBJ_NOTNULL(w->busyobj, BUSYOBJ_MAGIC);
-	AN(w->busyobj->vep);
+	CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
+	bo = wrk->busyobj;
+	CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);
+	AN(bo->vep);
 
-	retval = w->busyobj->fetch_failed;
+	retval = bo->fetch_failed;
 
-	if (w->busyobj->vgz_rx != NULL &&
-	     VGZ_Destroy(&w->busyobj->vgz_rx, -1) != VGZ_END)
-		retval = FetchError(w,
-		    "Gunzip+ESI Failed at the very end");
+	if (bo->vgz_rx != NULL && VGZ_Destroy(&bo->vgz_rx, -1) != VGZ_END)
+		retval = FetchError(wrk, "Gunzip+ESI Failed at the very end");
 
-	vsb = VEP_Finish(w);
+	vsb = VEP_Finish(wrk);
 
 	if (vsb != NULL) {
 		if (!retval) {
 			l = VSB_len(vsb);
 			assert(l > 0);
 			/* XXX: This is a huge waste of storage... */
-			w->busyobj->fetch_obj->esidata = STV_alloc(w, l);
-			if (w->busyobj->fetch_obj->esidata != NULL) {
-				memcpy(w->busyobj->fetch_obj->esidata->ptr,
+			bo->fetch_obj->esidata = STV_alloc(wrk, l);
+			if (bo->fetch_obj->esidata != NULL) {
+				memcpy(bo->fetch_obj->esidata->ptr,
 				    VSB_data(vsb), l);
-				w->busyobj->fetch_obj->esidata->len = l;
+				bo->fetch_obj->esidata->len = l;
 			} else {
-				retval = FetchError(w,
+				retval = FetchError(wrk,
 				    "Could not allocate storage for esidata");
 			}
 		}
 		VSB_delete(vsb);
 	}
 
-	vef = w->busyobj->vef_priv;
+	vef = bo->vef_priv;
 	if (vef != NULL) {
 		CHECK_OBJ_NOTNULL(vef, VEF_MAGIC);
-		w->busyobj->vef_priv = NULL;
-		VGZ_UpdateObj(vef->vgz, w->busyobj->fetch_obj);
+		bo->vef_priv = NULL;
+		VGZ_UpdateObj(vef->vgz, bo->fetch_obj);
 		if (VGZ_Destroy(&vef->vgz,  -1) != VGZ_END)
-			retval = FetchError(w,
+			retval = FetchError(wrk,
 			    "ESI+Gzip Failed at the very end");
 		FREE_OBJ(vef);
 	}
diff --git a/bin/varnishd/cache/cache_esi_parse.c b/bin/varnishd/cache/cache_esi_parse.c
index 41992ab..e431a8d 100644
--- a/bin/varnishd/cache/cache_esi_parse.c
+++ b/bin/varnishd/cache/cache_esi_parse.c
@@ -1007,6 +1007,8 @@ VEP_Init(struct worker *wrk, vep_callback_t *cb)
 	vep = (void*)WS_Alloc(wrk->ws, sizeof *vep);
 	AN(vep);
 
+	memset(vep, 0, sizeof *vep);
+	vep->magic = VEP_MAGIC;
 	vep->wrk = wrk;
 	vep->vsb = VSB_new_auto();
 	AN(vep->vsb);



More information about the varnish-commit mailing list