[master] 5922eb7 Add a WS_Copy() function and use it a couple of places.
Poul-Henning Kamp
phk at varnish-cache.org
Mon Sep 3 11:03:52 CEST 2012
commit 5922eb7519b734b45c1d2086b415ab432d53bfce
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Mon Sep 3 08:57:00 2012 +0000
Add a WS_Copy() function and use it a couple of places.
diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index 94db4b6..c92a2d0 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -1034,6 +1034,7 @@ void WS_ReleaseP(struct ws *ws, char *ptr);
void WS_Assert(const struct ws *ws);
void WS_Reset(struct ws *ws, char *p);
char *WS_Alloc(struct ws *ws, unsigned bytes);
+char *WS_Copy(struct ws *ws, const char *str, int len);
char *WS_Snapshot(struct ws *ws);
/* rfc2616.c */
diff --git a/bin/varnishd/cache/cache_http.c b/bin/varnishd/cache/cache_http.c
index ad29899..73fb7fc 100644
--- a/bin/varnishd/cache/cache_http.c
+++ b/bin/varnishd/cache/cache_http.c
@@ -888,10 +888,9 @@ http_CopyHome(const struct http *hp)
continue;
}
l = Tlen(hp->hd[u]);
- p = WS_Alloc(hp->ws, l + 1);
+ p = WS_Copy(hp->ws, hp->hd[u].b, l + 1L);
if (p != NULL) {
http_VSLH(hp, u);
- memcpy(p, hp->hd[u].b, l + 1L);
hp->hd[u].b = p;
hp->hd[u].e = p + l;
} else {
diff --git a/bin/varnishd/cache/cache_req_fsm.c b/bin/varnishd/cache/cache_req_fsm.c
index 9ff1308..18ca2e3 100644
--- a/bin/varnishd/cache/cache_req_fsm.c
+++ b/bin/varnishd/cache/cache_req_fsm.c
@@ -617,9 +617,9 @@ cnt_fetchbody(struct worker *wrk, struct req *req)
req->obj->gziped = 1;
if (vary != NULL) {
- req->obj->vary = (void *)WS_Alloc(req->obj->http->ws, varyl);
+ req->obj->vary = (void *)WS_Copy(req->obj->http->ws,
+ VSB_data(vary), varyl);
AN(req->obj->vary);
- memcpy(req->obj->vary, VSB_data(vary), varyl);
VRY_Validate(req->obj->vary);
VSB_delete(vary);
}
diff --git a/bin/varnishd/cache/cache_ws.c b/bin/varnishd/cache/cache_ws.c
index a5251ff..6c08422 100644
--- a/bin/varnishd/cache/cache_ws.c
+++ b/bin/varnishd/cache/cache_ws.c
@@ -117,6 +117,33 @@ WS_Alloc(struct ws *ws, unsigned bytes)
}
char *
+WS_Copy(struct ws *ws, const char *str, int len)
+{
+ char *r;
+ unsigned bytes;
+
+ WS_Assert(ws);
+ assert(ws->r == NULL);
+
+ if (len == -1)
+ len = strlen(str) + 1;
+ assert(len >= 0);
+
+ bytes = PRNDUP((unsigned)len);
+ if (ws->f + bytes > ws->e) {
+ ws->overflow++;
+ WS_Assert(ws);
+ return(NULL);
+ }
+ r = ws->f;
+ ws->f += bytes;
+ memcpy(r, str, len);
+ DSL(DBG_WORKSPACE, 0, "WS_Copy(%p, %d) = %p", ws, len, r);
+ WS_Assert(ws);
+ return (r);
+}
+
+char *
WS_Snapshot(struct ws *ws)
{
@@ -174,15 +201,3 @@ WS_ReleaseP(struct ws *ws, char *ptr)
ws->r = NULL;
WS_Assert(ws);
}
-
-#if 0
-/* XXX: not used anywhere (yet) */
-void
-WS_Return(struct ws *ws, char *s, char *e)
-{
-
- WS_Assert(ws);
- if (e == ws->f)
- ws->f = s;
-}
-#endif
More information about the varnish-commit
mailing list