[master] 76f72a395 cache: Move the txt declaration to vdef.h

Dridi Boukelmoune dridi.boukelmoune at gmail.com
Mon Aug 30 12:25:07 UTC 2021


commit 76f72a395521c71f38dbfca4b9b60da4d82e5da3
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date:   Tue Aug 3 10:06:48 2021 +0200

    cache: Move the txt declaration to vdef.h
    
    There are other components than the cache process that could benefit
    from it, in particular libvcc. The relationship with vas.h is somewhat
    unfortunate but that also centralize the Tcheck() logic in pdiff() and
    doesn't actually require vas.h unless the macros are used, in which
    case it's almost guaranteed that the calling code already included
    vas.h in the first place.
    
    The benefits should outweigh the drawbacks.

diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index b9e4022cb..35000cf6d 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -112,13 +112,6 @@ struct worker_priv;
 
 /*--------------------------------------------------------------------*/
 
-typedef struct {
-	const char		*b;
-	const char		*e;
-} txt;
-
-/*--------------------------------------------------------------------*/
-
 struct lock { void *priv; };	// Opaque
 
 /*--------------------------------------------------------------------
@@ -833,24 +826,6 @@ int RFC2616_Do_Cond(const struct req *sp);
 void RFC2616_Weaken_Etag(struct http *hp);
 void RFC2616_Vary_AE(struct http *hp);
 
-#define Tcheck(t) do {						\
-		AN((t).b);					\
-		AN((t).e);					\
-		assert((t).b <= (t).e);				\
-	} while(0)
-
-/*
- * unsigned length of a txt
- */
-
-static inline unsigned
-Tlen(const txt t)
-{
-
-	Tcheck(t);
-	return ((unsigned)(t.e - t.b));
-}
-
 /*
  * We want to cache the most recent timestamp in wrk->lastused to avoid
  * extra timestamps in cache_pool.c.  Hide this detail with a macro
diff --git a/include/vas.h b/include/vas.h
index 302170ae2..534737483 100644
--- a/include/vas.h
+++ b/include/vas.h
@@ -127,6 +127,8 @@ static inline size_t
 pdiff(const void *b, const void *e)
 {
 
+	AN(b);
+	AN(e);
 	assert(b <= e);
 	return ((size_t)((const char *)e - (const char *)b));
 }
diff --git a/include/vdef.h b/include/vdef.h
index ae072a2c3..c4004611f 100644
--- a/include/vdef.h
+++ b/include/vdef.h
@@ -197,3 +197,15 @@ int __llvm_gcov_flush(void);
 typedef double vtim_mono;
 typedef double vtim_real;
 typedef double vtim_dur;
+
+/**********************************************************************
+ * txt (vas.h needed for the macros)
+ */
+
+typedef struct {
+	const char		*b;
+	const char		*e;
+} txt;
+
+#define Tcheck(t)	do { (void)pdiff((t).b, (t).e); } while (0)
+#define Tlen(t)		(pdiff((t).b, (t).e))


More information about the varnish-commit mailing list