[master] 8a2cde419 ws: Replace WS_Front() with WS_Reservation()
Dridi Boukelmoune
dridi.boukelmoune at gmail.com
Mon Aug 31 18:41:10 UTC 2020
commit 8a2cde419e6484617838fb32bb1cbcdc5f57950f
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date: Wed May 6 11:57:36 2020 +0200
ws: Replace WS_Front() with WS_Reservation()
And add a companion function WS_ReservationSize(). This makes it explicit
that accessing the workspace front pointer is only valid for reservations,
and also informs you whether you are in the middle of a reservation, which
would be helpful for assertions.
diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index 4d2a7c00e..fb8e11f0b 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -797,12 +797,20 @@ void WS_Assert_Allocated(const struct ws *ws, const void *ptr, ssize_t len);
void WS_VSB_new(struct vsb *, struct ws *);
char *WS_VSB_finish(struct vsb *, struct ws *, size_t *);
-static inline char*
-WS_Front(const struct ws *ws)
+static inline void *
+WS_Reservation(const struct ws *ws)
+{
+
+ WS_Assert(ws);
+ return (ws->r != NULL ? ws->f : NULL);
+}
+
+static inline unsigned
+WS_ReservationSize(const struct ws *ws)
{
AN(ws->r);
- return ws->f;
+ return (ws->r - ws->f);
}
/* cache_rfc2616.c */
diff --git a/bin/varnishd/cache/cache_session.c b/bin/varnishd/cache/cache_session.c
index 2dd248558..1b13badae 100644
--- a/bin/varnishd/cache/cache_session.c
+++ b/bin/varnishd/cache/cache_session.c
@@ -482,7 +482,7 @@ SES_Wait(struct sess *sp, const struct transport *xp)
return;
}
- wp = (void*)WS_Front(sp->ws);
+ wp = WS_Reservation(sp->ws);
INIT_OBJ(wp, WAITED_MAGIC);
wp->fd = sp->fd;
wp->priv1 = sp;
diff --git a/bin/varnishd/cache/cache_vrt.c b/bin/varnishd/cache/cache_vrt.c
index 7da0734ab..bdc50c6ec 100644
--- a/bin/varnishd/cache/cache_vrt.c
+++ b/bin/varnishd/cache/cache_vrt.c
@@ -554,7 +554,7 @@ VRT_UpperLowerStrands(VRT_CTX, VCL_STRANDS s, int up)
CHECK_OBJ_NOTNULL(ctx->ws, WS_MAGIC);
AN(s);
u = WS_ReserveAll(ctx->ws);
- r = b = WS_Front(ctx->ws);
+ r = b = WS_Reservation(ctx->ws);
e = b + u;
for (i = 0; i < s->n; i++) {
if (s->p[i] == NULL || s->p[i][0] == '\0')
diff --git a/bin/varnishd/cache/cache_ws.c b/bin/varnishd/cache/cache_ws.c
index 8e2127c1f..64defc78b 100644
--- a/bin/varnishd/cache/cache_ws.c
+++ b/bin/varnishd/cache/cache_ws.c
@@ -377,7 +377,7 @@ WS_VSB_new(struct vsb *vsb, struct ws *ws)
if (WS_Overflowed(ws) || u < 2)
AN(VSB_init(vsb, bogus, sizeof bogus));
else
- AN(VSB_init(vsb, WS_Front(ws), u));
+ AN(VSB_init(vsb, WS_Reservation(ws), u));
}
char *
@@ -389,7 +389,7 @@ WS_VSB_finish(struct vsb *vsb, struct ws *ws, size_t *szp)
WS_Assert(ws);
if (!VSB_finish(vsb)) {
p = VSB_data(vsb);
- if (p == WS_Front(ws)) {
+ if (p == WS_Reservation(ws)) {
WS_Release(ws, VSB_len(vsb) + 1);
if (szp != NULL)
*szp = VSB_len(vsb);
diff --git a/include/vrt.h b/include/vrt.h
index 2177a45a7..a99798c95 100644
--- a/include/vrt.h
+++ b/include/vrt.h
@@ -57,6 +57,8 @@
* Added VCL_STRING VRT_BLOB_string(VRT_CTX, VCL_BLOB)
* [cache.h] WS_Reserve() removed
* [cache.h] WS_Printf() changed
+ * [cache.h] WS_ReservationSize() added
+ * [cache.h] WS_Front() replaced by WS_Reservation()
* 11.0 (2020-03-16)
* Changed type of vsa_suckaddr_len from int to size_t
* New prefix_{ptr|len} fields in vrt_backend
diff --git a/lib/libvmod_blob/vmod_blob.c b/lib/libvmod_blob/vmod_blob.c
index 0881798a3..c9c3dac2e 100644
--- a/lib/libvmod_blob/vmod_blob.c
+++ b/lib/libvmod_blob/vmod_blob.c
@@ -341,7 +341,7 @@ vmod_decode(VRT_CTX, VCL_ENUM decs, VCL_INT length, VCL_STRANDS strings)
CHECK_OBJ_NOTNULL(ctx->ws, WS_MAGIC);
space = WS_ReserveAll(ctx->ws);
- buf = WS_Front(ctx->ws);
+ buf = WS_Reservation(ctx->ws);
if (length <= 0)
length = -1;
@@ -378,7 +378,7 @@ encode(VRT_CTX, enum encoding enc, enum case_e kase, VCL_BLOB b)
CHECK_OBJ_NOTNULL(ctx->ws, WS_MAGIC);
space = WS_ReserveAll(ctx->ws);
- buf = WS_Front(ctx->ws);
+ buf = WS_Reservation(ctx->ws);
len = func[enc].encode(enc, kase, buf, space, b->blob, b->len);
More information about the varnish-commit
mailing list