Commit 001485e6 authored by Dridi Boukelmoune's avatar Dridi Boukelmoune

cache: Move the pdiff() function to vas.h

This way it can be used almost anywhere in the code base and out of tree,
not just in the cache process. The function was slightly polished after
prior discussions with phk and slink.
parent 184736fa
......@@ -824,20 +824,6 @@ int RFC2616_Do_Cond(const struct req *sp);
void RFC2616_Weaken_Etag(struct http *hp);
void RFC2616_Vary_AE(struct http *hp);
/*
* A normal pointer difference is signed, but we never want a negative value
* so this little tool will make sure we don't get that.
*/
static inline unsigned
pdiff(const void *b, const void *e)
{
assert(b <= e);
return
((unsigned)((const unsigned char *)e - (const unsigned char *)b));
}
#define Tcheck(t) do { \
AN((t).b); \
AN((t).e); \
......
......@@ -45,7 +45,7 @@ WS_Assert(const struct ws *ws)
{
CHECK_OBJ_NOTNULL(ws, WS_MAGIC);
DSL(DBG_WORKSPACE, 0, "WS(%p) = (%s, %p %u %u %u)",
DSL(DBG_WORKSPACE, 0, "WS(%p) = (%s, %p %zu %zu %zu)",
ws, ws->id, ws->s, pdiff(ws->s, ws->f),
ws->r == NULL ? 0 : pdiff(ws->f, ws->r),
pdiff(ws->s, ws->e));
......@@ -312,7 +312,7 @@ WS_ReserveSize(struct ws *ws, unsigned bytes)
return (0);
}
ws->r = ws->f + b2;
DSL(DBG_WORKSPACE, 0, "WS_ReserveSize(%p, %u/%u) = %u",
DSL(DBG_WORKSPACE, 0, "WS_ReserveSize(%p, %u/%u) = %zu",
ws, b2, bytes, pdiff(ws->f, ws->r));
WS_Assert(ws);
return (pdiff(ws->f, ws->r));
......
......@@ -117,4 +117,17 @@ do { \
typedef char __vassert_## y[(x) ? 1 : -1] v_unused_
#endif
/*
* A normal pointer difference is signed, but when we don't want a negative
* value this little tool will make sure we don't get that.
*/
static inline size_t
pdiff(const void *b, const void *e)
{
assert(b <= e);
return ((size_t)((const char *)e - (const char *)b));
}
#endif
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