[6.0] f7d8112ca varnishtest: New macro_isdef() function

Dridi Boukelmoune dridi.boukelmoune at gmail.com
Thu Apr 4 14:33:08 UTC 2024


commit f7d8112ca77f6d424faa1fc6dbf4087d581cdb1c
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date:   Fri Apr 14 15:22:30 2023 +0200

    varnishtest: New macro_isdef() function

diff --git a/bin/varnishtest/vtc.c b/bin/varnishtest/vtc.c
index 4b1d415ff..a1e1c9c44 100644
--- a/bin/varnishtest/vtc.c
+++ b/bin/varnishtest/vtc.c
@@ -201,6 +201,26 @@ macro_undef(struct vtclog *vl, const char *instance, const char *name)
 	AZ(pthread_mutex_unlock(&macro_mtx));
 }
 
+unsigned
+macro_isdef(const char *instance, const char *name)
+{
+	char buf1[256];
+	struct macro *m;
+
+	if (instance != NULL) {
+		bprintf(buf1, "%s_%s", instance, name);
+		name = buf1;
+	}
+
+	AZ(pthread_mutex_lock(&macro_mtx));
+	VTAILQ_FOREACH(m, &macro_list, list)
+		if (!strcmp(name, m->name))
+			break;
+	AZ(pthread_mutex_unlock(&macro_mtx));
+
+	return (m != NULL);
+}
+
 void
 macro_cat(struct vtclog *vl, struct vsb *vsb, const char *b, const char *e)
 {
diff --git a/bin/varnishtest/vtc.h b/bin/varnishtest/vtc.h
index 868fe6884..80319d8a9 100644
--- a/bin/varnishtest/vtc.h
+++ b/bin/varnishtest/vtc.h
@@ -114,8 +114,8 @@ int exec_file(const char *fn, const char *script, const char *tmpdir,
 
 void macro_undef(struct vtclog *vl, const char *instance, const char *name);
 void macro_def(struct vtclog *vl, const char *instance, const char *name,
-    const char *fmt, ...)
-    v_printflike_(4, 5);
+    const char *fmt, ...) v_printflike_(4, 5);
+unsigned macro_isdef(const char *instance, const char *name);
 void macro_cat(struct vtclog *, struct vsb *, const char *, const char *);
 struct vsb *macro_expand(struct vtclog *vl, const char *text);
 struct vsb *macro_expandf(struct vtclog *vl, const char *, ...)


More information about the varnish-commit mailing list