From: Tomi Ollila <tomi.ollila@iki.fi>
To: David Bremner <david@tethera.net>, notmuch@notmuchmail.org
Subject: Re: [PATCH 01/15] util: add DEBUG_PRINTF, rename error_util.h -> debug_print.h
Date: Sat, 01 Sep 2018 20:06:30 +0300 [thread overview]
Message-ID: <m2ftytqh9l.fsf@guru.guru-group.fi> (raw)
In-Reply-To: <20180830112915.11761-2-david@tethera.net>
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 => debug_print.c} | 16 +++++++++++-----
> util/{error_util.h => 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 => debug_print.c} (81%)
> rename util/{error_util.h => 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 <assert.h>
> #include <string.h>
> #include <stdio.h>
> -#include "error_util.h"
> +#include "debug_print.h"
> #include "command-line-arguments.h"
>
> 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"
>
> #include "xutil.h"
> -#include "error_util.h"
> +#include "debug_print.h"
> #include "string-util.h"
> #include "crypto.h"
>
> 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 := util
> extra_cflags += -I$(srcdir)/$(dir)
>
> -libnotmuch_util_c_srcs := $(dir)/xutil.c $(dir)/error_util.c $(dir)/hex-escape.c \
> +libnotmuch_util_c_srcs := $(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
>
> libnotmuch_util_modules := $(libnotmuch_util_c_srcs:.c=.o)
>
> 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 © 2009 Carl Worth
> + * Copyright © 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 <cworth@cworth.org>
> */
>
> -#include <stdlib.h>
> -#include <stdarg.h>
> -#include <stdio.h>
> +#include "debug_print.h"
>
> -#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);
> +}
>
> 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 © 2009 Carl Worth
> + * Copyright © 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 <cworth@cworth.org>
> */
>
> -#ifndef ERROR_UTIL_H
> -#define ERROR_UTIL_H
> +#ifndef DEBUG_PRINT_H
> +#define DEBUG_PRINT_H
>
> #include <talloc.h>
> -
> #include "function-attributes.h"
>
> +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
#include <stdio.h>
#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 <string.h>
> #include <talloc.h>
> #include <ctype.h>
> -#include "error_util.h"
> +#include "debug_print.h"
> #include "hex-escape.h"
>
> static const char *output_charset =
> 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 <string.h>
> #include <errno.h>
>
> 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 <string.h>
>
> #include "xutil.h"
> -#include "error_util.h"
> +#include "debug_print.h"
>
> void *
> xcalloc (size_t nmemb, size_t size)
> --
> 2.18.0
>
> _______________________________________________
> notmuch mailing list
> notmuch@notmuchmail.org
> https://notmuchmail.org/mailman/listinfo/notmuch
next prev parent reply other threads:[~2018-09-01 17:12 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-08-30 11:29 threading replies fixes v3 David Bremner
2018-08-30 11:29 ` [PATCH 01/15] util: add DEBUG_PRINTF, rename error_util.h -> debug_print.h David Bremner
2018-09-01 17:06 ` Tomi Ollila [this message]
2018-09-03 11:54 ` David Bremner
2018-08-30 11:29 ` [PATCH 02/15] test: start threading test corpus David Bremner
2018-08-30 11:29 ` [PATCH 03/15] test: add known broken tests for "ghost roots" David Bremner
2018-08-30 11:29 ` [PATCH 04/15] lib/thread: sort sibling messages by date David Bremner
2018-09-01 17:11 ` Tomi Ollila
2018-09-03 15:18 ` David Bremner
2018-08-30 11:29 ` [PATCH 05/15] lib: read reference terms into message struct David Bremner
2018-08-30 11:29 ` [PATCH 06/15] lib/thread: refactor in_reply_to test David Bremner
2018-09-01 20:02 ` Tomi Ollila
2018-08-30 11:29 ` [PATCH 07/15] lib/thread: initial use of references as for fallback parenting David Bremner
2018-08-30 11:29 ` [PATCH 08/15] lib: calculate message depth in thread David Bremner
2018-08-30 11:29 ` [PATCH 09/15] lib/thread: rewrite _parent_or_toplevel to use depths David Bremner
2018-08-30 11:29 ` [PATCH 10/15] lib/thread: change _resolve_thread_relationships " David Bremner
2018-08-30 11:29 ` [PATCH 11/15] test: add known broken test for good In-Reply-To / bad References David Bremner
2018-08-30 11:29 ` [PATCH 12/15] test/thread-replies: mangle In-Reply-To's David Bremner
2018-08-30 11:29 ` [PATCH 13/15] util/string-util: export skip_space David Bremner
2018-08-30 11:29 ` [PATCH 14/15] lib: add _notmuch_message_id_parse_strict David Bremner
2018-09-01 20:27 ` Tomi Ollila
2018-08-30 11:29 ` [PATCH 15/15] lib: change parent strategy to use In-Reply-To if it looks sane David Bremner
2018-09-01 20:29 ` Tomi Ollila
-- strict thread matches above, loose matches on Subject: below --
2018-07-30 22:45 Threading patches v2 David Bremner
2018-07-30 22:45 ` [PATCH 01/15] util: add DEBUG_PRINTF, rename error_util.h -> debug_print.h David Bremner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://notmuchmail.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m2ftytqh9l.fsf@guru.guru-group.fi \
--to=tomi.ollila@iki.fi \
--cc=david@tethera.net \
--cc=notmuch@notmuchmail.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).