[master] 001485e67 cache: Move the pdiff() function to vas.h

Dridi Boukelmoune dridi.boukelmoune at gmail.com
Wed Nov 25 16:37:06 UTC 2020


commit 001485e6705976bd1029279cb639a394c4dee59c
Author: Dridi Boukelmoune <dridi.boukelmoune at 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.

diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index e4c77ee07..10bd3079b 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -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);					\
diff --git a/bin/varnishd/cache/cache_ws.c b/bin/varnishd/cache/cache_ws.c
index 338eac7f8..36edfd68e 100644
--- a/bin/varnishd/cache/cache_ws.c
+++ b/bin/varnishd/cache/cache_ws.c
@@ -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));
diff --git a/include/vas.h b/include/vas.h
index 90fac3482..32a092241 100644
--- a/include/vas.h
+++ b/include/vas.h
@@ -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


More information about the varnish-commit mailing list