Mailing List Archive

[master] b8856a121 Add PAN_dump_oneline()
commit b8856a12125767d16362f23b38de32dd181b0c81
Author: Nils Goroll <nils.goroll@uplex.de>
Date: Sat Jan 23 14:38:38 2021 +0100

Add PAN_dump_oneline()

adds a variant of PAN_dump_struct() which does not start another
indentation level on a new line.

diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index c7825f8fa..a6bf831be 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -848,9 +848,12 @@ Tlen(const txt t)
*/
#define W_TIM_real(w) ((w)->lastused = VTIM_real())

-int PAN_dump_struct2(struct vsb *vsb, const void *ptr,
+int PAN_dump_struct2(struct vsb *vsb, int block, const void *ptr,
const char *smagic, unsigned magic, const char *fmt, ...)
- v_printflike_(5,6);
+ v_printflike_(6,7);

-#define PAN_dump_struct(vsb, ptr, magic, ...) \
- PAN_dump_struct2(vsb, ptr, #magic, magic, __VA_ARGS__)
+#define PAN_dump_struct(vsb, ptr, magic, ...) \
+ PAN_dump_struct2(vsb, 1, ptr, #magic, magic, __VA_ARGS__)
+
+#define PAN_dump_oneline(vsb, ptr, magic, ...) \
+ PAN_dump_struct2(vsb, 0, ptr, #magic, magic, __VA_ARGS__)
diff --git a/bin/varnishd/cache/cache_panic.c b/bin/varnishd/cache/cache_panic.c
index 954d2949b..8331d5f23 100644
--- a/bin/varnishd/cache/cache_panic.c
+++ b/bin/varnishd/cache/cache_panic.c
@@ -110,7 +110,7 @@ static const void *already_list[N_ALREADY];
static int already_idx;

int
-PAN_dump_struct2(struct vsb *vsb, const void *ptr,
+PAN_dump_struct2(struct vsb *vsb, int block, const void *ptr,
const char *smagic, unsigned magic, const char *fmt, ...)
{
va_list ap;
@@ -125,10 +125,14 @@ PAN_dump_struct2(struct vsb *vsb, const void *ptr,
VSB_printf(vsb, " = NULL\n");
return (-1);
}
- VSB_printf(vsb, " = %p {\n", ptr);
+ VSB_printf(vsb, " = %p {", ptr);
+ if (block)
+ VSB_putc(vsb, '\n');
for (i = 0; i < already_idx; i++) {
if (already_list[i] == ptr) {
- VSB_cat(vsb, " [Already dumped, see above]\n");
+ VSB_cat(vsb, " [Already dumped, see above]");
+ if (block)
+ VSB_putc(vsb, '\n');
VSB_cat(vsb, "},\n");
return (-2);
}
@@ -138,11 +142,14 @@ PAN_dump_struct2(struct vsb *vsb, const void *ptr,
uptr = ptr;
if (*uptr != magic) {
VSB_printf(vsb, " .magic = 0x%08x", *uptr);
- VSB_printf(vsb, " EXPECTED: %s=0x%08x\n", smagic, magic);
+ VSB_printf(vsb, " EXPECTED: %s=0x%08x", smagic, magic);
+ if (block)
+ VSB_putc(vsb, '\n');
VSB_printf(vsb, "}\n");
return (-3);
}
- VSB_indent(vsb, 2);
+ if (block)
+ VSB_indent(vsb, 2);
return (0);
}

diff --git a/bin/varnishd/cache/cache_vrt_priv.c b/bin/varnishd/cache/cache_vrt_priv.c
index 1cd4898c3..3aa166514 100644
--- a/bin/varnishd/cache/cache_vrt_priv.c
+++ b/bin/varnishd/cache/cache_vrt_priv.c
@@ -71,25 +71,23 @@ pan_privs(struct vsb *vsb, const struct vrt_privs *privs)
VSB_printf(vsb, "privs = %p {\n", privs);
VSB_indent(vsb, 2);
VRBT_FOREACH(vp, vrt_privs, privs) {
- if (PAN_dump_struct(vsb, vp, VRT_PRIV_MAGIC, "priv"))
+ if (PAN_dump_oneline(vsb, vp, VRT_PRIV_MAGIC, "priv"))
continue;
p = vp->priv;
//lint -e{774}
if (p == NULL) {
// should never happen
- VSB_printf(vsb, "NULL vmod %jx\n",
+ VSB_printf(vsb, "NULL vmod %jx},\n",
(uintmax_t)vp->vmod_id);
- } else {
- m = p->methods;
- VSB_printf(vsb,
- "{p %p l %ld m %p t \"%s\"} vmod %jx\n",
- p->priv, p->len, m,
- m != NULL ? m->type : "",
- (uintmax_t)vp->vmod_id
- );
+ continue;
}
- VSB_indent(vsb, -2);
- VSB_cat(vsb, "},\n");
+ m = p->methods;
+ VSB_printf(vsb,
+ "{p %p l %ld m %p t \"%s\"} vmod %jx},\n",
+ p->priv, p->len, m,
+ m != NULL ? m->type : "",
+ (uintmax_t)vp->vmod_id
+ );
}
VSB_indent(vsb, -2);
VSB_cat(vsb, "},\n");
_______________________________________________
varnish-commit mailing list
varnish-commit@varnish-cache.org
https://www.varnish-cache.org/lists/mailman/listinfo/varnish-commit