[master] 8b67e5bb8 Coccinelle: patch v{min,max}_t -> v{min,max}

Nils Goroll nils.goroll at uplex.de
Tue Jul 11 19:29:08 UTC 2023


commit 8b67e5bb86888d28409ea313e32937aa3522c5bb
Author: Nils Goroll <nils.goroll at uplex.de>
Date:   Tue Jul 11 21:27:37 2023 +0200

    Coccinelle: patch v{min,max}_t -> v{min,max}

diff --git a/bin/varnishd/cache/cache_shmlog.c b/bin/varnishd/cache/cache_shmlog.c
index e1ae6e286..971c65ae6 100644
--- a/bin/varnishd/cache/cache_shmlog.c
+++ b/bin/varnishd/cache/cache_shmlog.c
@@ -304,7 +304,7 @@ VSLv(enum VSL_tag_e tag, vxid_t vxid, const char *fmt, va_list ap)
 		vslr(tag, vxid, fmt, strlen(fmt) + 1);
 	} else {
 		n = vsnprintf(buf, mlen, fmt, ap);
-		n = vmin_t(unsigned, n, mlen - 1);
+		n = vmin(n, mlen - 1);
 		buf[n++] = '\0'; /* NUL-terminated */
 		vslr(tag, vxid, buf, n);
 	}
diff --git a/bin/varnishd/http2/cache_http2_send.c b/bin/varnishd/http2/cache_http2_send.c
index be3d6fd67..f989d001c 100644
--- a/bin/varnishd/http2/cache_http2_send.c
+++ b/bin/varnishd/http2/cache_http2_send.c
@@ -272,7 +272,7 @@ h2_do_window(struct worker *wrk, struct h2_req *r2,
 			(void)h2_cond_wait(h2->winupd_cond, h2, r2);
 
 		if (h2_errcheck(r2, h2) == 0) {
-			w = vmin_t(int64_t, h2_win_limit(r2, h2), wanted);
+			w = vmin(h2_win_limit(r2, h2), wanted);
 			h2_win_charge(r2, h2, w);
 			assert (w > 0);
 		}
diff --git a/bin/varnishd/storage/stevedore_utils.c b/bin/varnishd/storage/stevedore_utils.c
index 4d8abe18a..427392873 100644
--- a/bin/varnishd/storage/stevedore_utils.c
+++ b/bin/varnishd/storage/stevedore_utils.c
@@ -157,7 +157,7 @@ STV_FileSize(int fd, const char *size, unsigned *granularity, const char *ctx)
 
 	AZ(VFIL_fsinfo(fd, &bs, &fssize, NULL));
 	/* Increase granularity if it is lower than the filesystem block size */
-	*granularity = vmax_t(unsigned, *granularity, bs);
+	*granularity = vmax(*granularity, bs);
 
 	if ((size == NULL || *size == '\0') && st.st_size != 0) {
 		/*
diff --git a/lib/libvcc/vcc_acl.c b/lib/libvcc/vcc_acl.c
index 818693670..85baac4ca 100644
--- a/lib/libvcc/vcc_acl.c
+++ b/lib/libvcc/vcc_acl.c
@@ -105,7 +105,7 @@ vcl_acl_cmp(const struct acl_e *ae1, const struct acl_e *ae2)
 
 	p1 = ae1->data;
 	p2 = ae2->data;
-	m = vmin_t(unsigned, ae1->mask, ae2->mask);
+	m = vmin(ae1->mask, ae2->mask);
 	for (; m >= 8; m -= 8) {
 		CMP(*p1, *p2);
 		p1++;
diff --git a/tools/coccinelle/vminmax.cocci b/tools/coccinelle/vminmax.cocci
new file mode 100644
index 000000000..b3ebe292c
--- /dev/null
+++ b/tools/coccinelle/vminmax.cocci
@@ -0,0 +1,16 @@
+/*
+ * This patch refactors v{min,max}_t to v{min,max} where types agree
+ *
+ * Note: Has false positives on pointer types, tolerated for clarity
+ */
+using "varnish.iso"
+
+@@ type T; T e1, e2; @@
+
+- vmin_t(T, e1, e2)
++ vmin(e1, e2)
+
+@@ type T; T e1, e2; @@
+
+- vmax_t(T, e1, e2)
++ vmax(e1, e2)
diff --git a/vmod/vmod_directors_shard_cfg.c b/vmod/vmod_directors_shard_cfg.c
index aec4a0901..f03a96361 100644
--- a/vmod/vmod_directors_shard_cfg.c
+++ b/vmod/vmod_directors_shard_cfg.c
@@ -275,7 +275,7 @@ shardcfg_hashcircle(struct sharddir *shardd)
 	rmax = (UINT32_MAX - 1) / shardd->n_backend;
 	for (b = backends; b < backends + shardd->n_backend; b++) {
 		CHECK_OBJ_NOTNULL(b->backend, DIRECTOR_MAGIC);
-		n_points += vmin_t(uint32_t, b->replicas, rmax);
+		n_points += vmin(b->replicas, rmax);
 	}
 
 	assert(n_points < UINT32_MAX);
@@ -291,7 +291,7 @@ shardcfg_hashcircle(struct sharddir *shardd)
 		AN(ident);
 		assert(ident[0] != '\0');
 
-		r = vmin_t(uint32_t, b->replicas, rmax);
+		r = vmin(b->replicas, rmax);
 
 		for (j = 0; j < r; j++) {
 			assert(snprintf(s, len, "%d", j) < len);


More information about the varnish-commit mailing list