Commit 8a2cde41 authored by Dridi Boukelmoune's avatar Dridi Boukelmoune

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.
parent d3d39f56
......@@ -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 */
......
......@@ -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;
......
......@@ -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')
......
......@@ -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);
......
......@@ -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
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment