Permalink
Browse files

Introduce WS_ReserveLumps() to allocate an array of something.

  • Loading branch information...
1 parent 4e0004e commit 64407985441e1732cd9ee99f4300b872de71f3a0 @bsdphk bsdphk committed Feb 15, 2017
@@ -1058,6 +1058,7 @@ void WRK_BgThread(pthread_t *thr, const char *name, bgthread_t *func,
void WS_Init(struct ws *ws, const char *id, void *space, unsigned len);
unsigned WS_Reserve(struct ws *ws, unsigned bytes);
+unsigned WS_ReserveLumps(struct ws *ws, size_t sz);
void WS_MarkOverflow(struct ws *ws);
void WS_Release(struct ws *ws, unsigned bytes);
void WS_ReleaseP(struct ws *ws, char *ptr);
@@ -241,6 +241,16 @@ WS_Reserve(struct ws *ws, unsigned bytes)
return (pdiff(ws->f, ws->r));
}
+unsigned
+WS_ReserveLumps(struct ws *ws, size_t sz)
+{
+ unsigned u;
+
+ u = WS_Reserve(ws, 0);
+ u /= sz;
+ return (u);
+}
+
void
WS_Release(struct ws *ws, unsigned bytes)
{
@@ -88,16 +88,15 @@ V1L_Reserve(struct worker *wrk, struct ws *ws, int *fd, struct vsl_log *vsl,
v1l->ws = ws;
v1l->res = res;
- u = WS_Reserve(ws, 0);
- u = PRNDDN(u);
- u /= sizeof(struct iovec);
+ u = WS_ReserveLumps(ws, sizeof(struct iovec));
if (u == 0) {
WS_Release(ws, 0);
WS_MarkOverflow(ws);
return;
- } else if (u > IOV_MAX)
+ }
+ if (u > IOV_MAX)
u = IOV_MAX;
- v1l->iov = (void*)PRNDUP(ws->f);
+ v1l->iov = (void*)ws->f;
v1l->siov = u;
v1l->ciov = u;
v1l->werr = 0;
@@ -56,6 +56,7 @@ vmod_querysort(VRT_CTX, VCL_STRING url)
char *p, *r;
const char **pp;
const char **pe;
+ unsigned u;
int np;
int i;
@@ -78,16 +79,14 @@ vmod_querysort(VRT_CTX, VCL_STRING url)
if (r == NULL)
return (url);
- (void)WS_Reserve(ctx->ws, 0);
- /* We trust cache_ws.c to align sensibly */
+ u = WS_ReserveLumps(ctx->ws, sizeof(const char **));
pp = (const char**)(void*)(ctx->ws->f);
- pe = (const char**)(void*)(ctx->ws->e);
-
- if (pp + 4 > pe) {
+ if (u < 4) {
WS_Release(ctx->ws, 0);
WS_MarkOverflow(ctx->ws);
return (url);
}
+ pe = pp + u;
/* Collect params as pointer pairs */
np = 0;

0 comments on commit 6440798

Please sign in to comment.