r4660 - trunk/varnish-cache/bin/varnishd
phk at varnish-cache.org
phk at varnish-cache.org
Tue Apr 13 23:07:39 CEST 2010
Author: phk
Date: 2010-04-13 23:07:39 +0200 (Tue, 13 Apr 2010)
New Revision: 4660
Modified:
trunk/varnish-cache/bin/varnishd/cache_ws.c
Log:
Align all workspace allocations on pointer boundaries.
Add plenty of asserts until we see that the world don't end.
Modified: trunk/varnish-cache/bin/varnishd/cache_ws.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_ws.c 2010-04-13 21:07:01 UTC (rev 4659)
+++ trunk/varnish-cache/bin/varnishd/cache_ws.c 2010-04-13 21:07:39 UTC (rev 4660)
@@ -57,13 +57,17 @@
ws->r == NULL ? 0 : pdiff(ws->f, ws->r),
pdiff(ws->s, ws->e));
assert(ws->s != NULL);
+ // assert(PAOK(ws->s));
assert(ws->e != NULL);
+ // assert(PAOK(ws->e));
assert(ws->s < ws->e);
assert(ws->f >= ws->s);
assert(ws->f <= ws->e);
+ // assert(PAOK(ws->f));
if (ws->r) {
assert(ws->r > ws->s);
assert(ws->r <= ws->e);
+ // assert(PAOK(ws->r));
}
}
@@ -77,7 +81,9 @@
memset(ws, 0, sizeof *ws);
ws->magic = WS_MAGIC;
ws->s = space;
+ assert(PAOK(space));
ws->e = ws->s + len;
+ assert(PAOK(len));
ws->f = ws->s;
ws->id = id;
WS_Assert(ws);
@@ -101,6 +107,7 @@
assert(p < ws->e);
ws->f = p;
}
+ WS_Assert(ws);
}
char *
@@ -109,14 +116,18 @@
char *r;
WS_Assert(ws);
+ bytes = PRNDUP(bytes);
+
assert(ws->r == NULL);
if (ws->f + bytes > ws->e) {
ws->overflow++;
+ WS_Assert(ws);
return(NULL);
}
r = ws->f;
ws->f += bytes;
DSL(0x02, SLT_Debug, 0, "WS_Alloc(%p, %u) = %p", ws, bytes, r);
+ WS_Assert(ws);
return (r);
}
@@ -126,11 +137,13 @@
unsigned l;
char *p;
+ WS_Assert(ws);
l = strlen(s) + 1;
p = WS_Alloc(ws, l);
if (p != NULL)
memcpy(p, s, l);
DSL(0x02, SLT_Debug, 0, "WS_Dup(%p, \"%s\") = %p", ws, s, p);
+ WS_Assert(ws);
return (p);
}
@@ -155,16 +168,20 @@
unsigned
WS_Reserve(struct ws *ws, unsigned bytes)
{
- unsigned b2 = bytes;
+ unsigned b2;
WS_Assert(ws);
assert(ws->r == NULL);
if (bytes == 0)
b2 = ws->e - ws->f;
+ else
+ b2 = bytes;
+ // b2 = PRNDND(b2);
xxxassert(ws->f + b2 <= ws->e);
ws->r = ws->f + b2;
DSL(0x02, SLT_Debug, 0, "WS_Reserve(%p, %u/%u) = %u",
ws, b2, bytes, pdiff(ws->f, ws->r));
+ WS_Assert(ws);
return (pdiff(ws->f, ws->r));
}
@@ -172,12 +189,14 @@
WS_Release(struct ws *ws, unsigned bytes)
{
WS_Assert(ws);
+ // bytes = PRNDUP(bytes);
assert(bytes <= ws->e - ws->f);
DSL(0x02, SLT_Debug, 0, "WS_Release(%p, %u)", ws, bytes);
assert(ws->r != NULL);
assert(ws->f + bytes <= ws->r);
ws->f += bytes;
ws->r = NULL;
+ WS_Assert(ws);
}
void
@@ -188,8 +207,10 @@
assert(ws->r != NULL);
assert(ptr >= ws->f);
assert(ptr <= ws->r);
- ws->f = ptr;
+ // ws->f += PRNDUP(ptr - ws->f);
+ ws->f += (ptr - ws->f);
ws->r = NULL;
+ WS_Assert(ws);
}
#if 0
More information about the varnish-commit
mailing list