Mailing List Archive

[6.0] 61f6a3774 cache: Move the pdiff() function to vas.h
commit 61f6a377487b6f830f863c34c0cc7d930e1293d1
Author: Dridi Boukelmoune <dridi.boukelmoune@gmail.com>
Date: Wed Nov 25 17:22:42 2020 +0100

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.

Conflicts:
include/vas.h

diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index b26a2e73a..f5329aafd 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -799,20 +799,6 @@ void RFC2616_Weaken_Etag(struct http *hp);
void RFC2616_Vary_AE(struct http *hp);
void RFC2616_Response_Body(const struct worker *, const struct busyobj *);

-/*
- * 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); \
diff --git a/bin/varnishd/cache/cache_ws.c b/bin/varnishd/cache/cache_ws.c
index 5de7a6830..a691860c4 100644
--- a/bin/varnishd/cache/cache_ws.c
+++ b/bin/varnishd/cache/cache_ws.c
@@ -39,7 +39,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));
@@ -268,7 +268,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));
@@ -294,7 +294,7 @@ WS_Reserve(struct ws *ws, unsigned bytes)
return (0);
}
ws->r = ws->f + b2;
- DSL(DBG_WORKSPACE, 0, "WS_Reserve(%p, %u/%u) = %u",
+ DSL(DBG_WORKSPACE, 0, "WS_Reserve(%p, %u/%u) = %zu",
ws, b2, bytes, pdiff(ws->f, ws->r));
WS_Assert(ws);
return (pdiff(ws->f, ws->r));
diff --git a/include/vas.h b/include/vas.h
index 11c00692d..ccbbbec32 100644
--- a/include/vas.h
+++ b/include/vas.h
@@ -88,4 +88,17 @@ do { \
"", VAS_INCOMPLETE); \
} while (0)

+/*
+ * 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
_______________________________________________
varnish-commit mailing list
varnish-commit@varnish-cache.org
https://www.varnish-cache.org/lists/mailman/listinfo/varnish-commit