From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by arlo.cworth.org (Postfix) with ESMTP id 5325C6DE0355 for ; Sat, 1 Sep 2018 10:12:10 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: 0.471 X-Spam-Level: X-Spam-Status: No, score=0.471 tagged_above=-999 required=5 tests=[AWL=-0.181, SPF_NEUTRAL=0.652] autolearn=disabled Received: from arlo.cworth.org ([127.0.0.1]) by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id JrhtXaF4ybMs for ; Sat, 1 Sep 2018 10:12:09 -0700 (PDT) Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34]) by arlo.cworth.org (Postfix) with ESMTP id 482EE6DE0318 for ; Sat, 1 Sep 2018 10:12:09 -0700 (PDT) Received: from guru.guru-group.fi (localhost [IPv6:::1]) by guru.guru-group.fi (Postfix) with ESMTP id 647341000AF; Sat, 1 Sep 2018 20:06:32 +0300 (EEST) From: Tomi Ollila To: David Bremner , notmuch@notmuchmail.org Subject: Re: [PATCH 01/15] util: add DEBUG_PRINTF, rename error_util.h -> debug_print.h In-Reply-To: <20180830112915.11761-2-david@tethera.net> References: <20180830112915.11761-1-david@tethera.net> <20180830112915.11761-2-david@tethera.net> User-Agent: Notmuch/0.27+14~ge594ae3 (https://notmuchmail.org) Emacs/25.2.1 (x86_64-unknown-linux-gnu) X-Face: HhBM'cA~ MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 01 Sep 2018 17:12:10 -0000 On Thu, Aug 30 2018, David Bremner wrote: > It seemed silly to have two headers that were almost copies. > The new macro is intended for debugging, and probably should not be > left in released code. > --- > command-line-arguments.c | 2 +- > lib/notmuch-private.h | 2 +- > util/Makefile.local | 4 ++-- > util/{error_util.c =3D> debug_print.c} | 16 +++++++++++----- > util/{error_util.h =3D> debug_print.h} | 22 ++++++++++++++++++---- > util/hex-escape.c | 2 +- > util/util.c | 2 +- > util/xutil.c | 2 +- > 8 files changed, 36 insertions(+), 16 deletions(-) > rename util/{error_util.c =3D> debug_print.c} (81%) > rename util/{error_util.h =3D> debug_print.h} (75%) > > diff --git a/command-line-arguments.c b/command-line-arguments.c > index d64aa85b..90d69453 100644 > --- a/command-line-arguments.c > +++ b/command-line-arguments.c > @@ -1,7 +1,7 @@ > #include > #include > #include > -#include "error_util.h" > +#include "debug_print.h" > #include "command-line-arguments.h" >=20=20 > typedef enum { > diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h > index 3764a6a9..499d73d4 100644 > --- a/lib/notmuch-private.h > +++ b/lib/notmuch-private.h > @@ -50,7 +50,7 @@ NOTMUCH_BEGIN_DECLS > #include "gmime-extra.h" >=20=20 > #include "xutil.h" > -#include "error_util.h" > +#include "debug_print.h" > #include "string-util.h" > #include "crypto.h" >=20=20 > diff --git a/util/Makefile.local b/util/Makefile.local > index ba03230e..ccf1bd79 100644 > --- a/util/Makefile.local > +++ b/util/Makefile.local > @@ -3,9 +3,9 @@ > dir :=3D util > extra_cflags +=3D -I$(srcdir)/$(dir) >=20=20 > -libnotmuch_util_c_srcs :=3D $(dir)/xutil.c $(dir)/error_util.c $(dir)/he= x-escape.c \ > +libnotmuch_util_c_srcs :=3D $(dir)/xutil.c $(dir)/hex-escape.c \ > $(dir)/string-util.c $(dir)/talloc-extra.c $(dir)/zlib-extra.c \ > - $(dir)/util.c $(dir)/gmime-extra.c $(dir)/crypto.c > + $(dir)/util.c $(dir)/gmime-extra.c $(dir)/crypto.c $(dir)/debug_print.c >=20=20 > libnotmuch_util_modules :=3D $(libnotmuch_util_c_srcs:.c=3D.o) >=20=20 > diff --git a/util/error_util.c b/util/debug_print.c > similarity index 81% > rename from util/error_util.c > rename to util/debug_print.c > index e64162c7..8b4bc73d 100644 > --- a/util/error_util.c > +++ b/util/debug_print.c > @@ -1,6 +1,7 @@ > /* error_util.c - internal error utilities for notmuch. > * > * Copyright =C2=A9 2009 Carl Worth > + * Copyright =C2=A9 2018 David Bremner > * > * This program is free software: you can redistribute it and/or modify > * it under the terms of the GNU General Public License as published by > @@ -18,11 +19,17 @@ > * Author: Carl Worth > */ >=20=20 > -#include > -#include > -#include > +#include "debug_print.h" >=20=20 > -#include "error_util.h" > +void > +_debug_printf (const char *format, ...) > +{ > + va_list va_args; > + > + va_start (va_args, format); > + vfprintf (stderr, format, va_args); > + va_end (va_args); > +} >=20=20 > void > _internal_error (const char *format, ...) > @@ -37,4 +44,3 @@ _internal_error (const char *format, ...) > va_end (va_args); > exit (1); > } > - > diff --git a/util/error_util.h b/util/debug_print.h > similarity index 75% > rename from util/error_util.h > rename to util/debug_print.h > index 4bb338a2..4a096945 100644 > --- a/util/error_util.h > +++ b/util/debug_print.h > @@ -1,6 +1,7 @@ > -/* error_util.h - Provide the INTERNAL_ERROR macro > +/* debug_print.h - Provide the INTERNAL_ERROR and DEBUG_PRINTF macros > * > * Copyright =C2=A9 2009 Carl Worth > + * Copyright =C2=A9 2018 David Bremner > * > * This program is free software: you can redistribute it and/or modify > * it under the terms of the GNU General Public License as published by > @@ -18,13 +19,26 @@ > * Author: Carl Worth > */ >=20=20 > -#ifndef ERROR_UTIL_H > -#define ERROR_UTIL_H > +#ifndef DEBUG_PRINT_H > +#define DEBUG_PRINT_H >=20=20 > #include > - > #include "function-attributes.h" >=20=20 > +void > +_debug_printf (const char *format, ...) PRINTF_ATTRIBUTE (1, 2); > + > +/* > + * Provide a quick way to silence debugging output. > + */ > + > +#ifdef DEBUG_PRINT > +#define DEBUG_PRINTF(format, ...) _debug_printf(format " (%s).\n", \ > + ##__VA_ARGS__, __location__) To me, YAGNI says that we could drop the whole _debug_printf() and have=20 #include #define DEBUG_PRINTF(format, ...) fprintf(stderr, format " (%s).\n", \ ##__VA_ARGS__, __location__) (but if there is need, then perhaps the lib code inside #ifdef DEBUG_PRINT ... hmm, but, outside of this context, would this also move _internal_error() to debug_print ;O )? > +#else > +#define DEBUG_PRINTF(format, ...) /* ignored */ perhaps: #define DEBUG_PRINTF(format, ...) do {} while (0) /* ignored */ > +#endif > + > /* There's no point in continuing when we've detected that we've done > * something wrong internally (as opposed to the user passing in a > * bogus value). > diff --git a/util/hex-escape.c b/util/hex-escape.c > index 8883ff90..ff20c702 100644 > --- a/util/hex-escape.c > +++ b/util/hex-escape.c > @@ -22,7 +22,7 @@ > #include > #include > #include > -#include "error_util.h" > +#include "debug_print.h" > #include "hex-escape.h" >=20=20 > static const char *output_charset =3D > diff --git a/util/util.c b/util/util.c > index 06659b35..75df0ead 100644 > --- a/util/util.c > +++ b/util/util.c > @@ -1,5 +1,5 @@ > #include "util.h" > -#include "error_util.h" > +#include "debug_print.h" > #include > #include >=20=20 > diff --git a/util/xutil.c b/util/xutil.c > index f211eaaa..11042c9e 100644 > --- a/util/xutil.c > +++ b/util/xutil.c > @@ -22,7 +22,7 @@ > #include >=20=20 > #include "xutil.h" > -#include "error_util.h" > +#include "debug_print.h" >=20=20 > void * > xcalloc (size_t nmemb, size_t size) > --=20 > 2.18.0 > > _______________________________________________ > notmuch mailing list > notmuch@notmuchmail.org > https://notmuchmail.org/mailman/listinfo/notmuch