Mailing List Archive

[6.0] 382f84e2b cache: Move the txt declaration to vdef.h
commit 382f84e2bc0635fb3097a83fe3570a3425c719e0
Author: Dridi Boukelmoune <dridi.boukelmoune@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.

Conflicts:
bin/varnishd/cache/cache.h
bin/varnishtest/vtc_http.c

diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index f5329aafd..21682ec3b 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -105,13 +105,6 @@ struct listen_sock;

/*--------------------------------------------------------------------*/

-typedef struct {
- const char *b;
- const char *e;
-} txt;
-
-/*--------------------------------------------------------------------*/
-
enum req_step {
R_STP_NONE = 0,
#define REQ_STEP(l, u, arg) R_STP_##u,
@@ -799,24 +792,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 *);

-#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/bin/varnishtest/vtc_http.c b/bin/varnishtest/vtc_http.c
index 828492b6b..99c5f2770 100644
--- a/bin/varnishtest/vtc_http.c
+++ b/bin/varnishtest/vtc_http.c
@@ -795,7 +795,7 @@ cmd_http_gunzip(CMD_ARGS)
*/

static void
-gzip_body(const struct http *hp, const char *txt, char **body, int *bodylen)
+gzip_body(const struct http *hp, const char *text, char **body, int *bodylen)
{
int l;
z_stream vz;
@@ -805,11 +805,11 @@ gzip_body(const struct http *hp, const char *txt, char **body, int *bodylen)

memset(&vz, 0, sizeof vz);

- l = strlen(txt);
+ l = strlen(text);
*body = calloc(1, l + OVERHEAD);
AN(*body);

- vz.next_in = TRUST_ME(txt);
+ vz.next_in = TRUST_ME(text);
vz.avail_in = l;

vz.next_out = TRUST_ME(*body);
diff --git a/include/vas.h b/include/vas.h
index ccbbbec32..4633d64a2 100644
--- a/include/vas.h
+++ b/include/vas.h
@@ -97,6 +97,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 128f44148..20ce9a63f 100644
--- a/include/vdef.h
+++ b/include/vdef.h
@@ -229,3 +229,15 @@
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))
_______________________________________________
varnish-commit mailing list
varnish-commit@varnish-cache.org
https://www.varnish-cache.org/lists/mailman/listinfo/varnish-commit