git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Jonathan Tan <jonathantanmy@google.com>
Cc: git@vger.kernel.org, git@jeffhostetler.com
Subject: Re: [RFC PATCH v2] usage: add trace2 entry upon warning()
Date: Mon, 23 Nov 2020 14:30:12 -0800	[thread overview]
Message-ID: <xmqqblfnn1u3.fsf@gitster.c.googlers.com> (raw)
In-Reply-To: <20201123204522.675836-1-jonathantanmy@google.com> (Jonathan Tan's message of "Mon, 23 Nov 2020 12:45:22 -0800")

Jonathan Tan <jonathantanmy@google.com> writes:

> diff --git a/usage.c b/usage.c
> index 06665823a2..1868a24f7a 100644
> --- a/usage.c
> +++ b/usage.c
> @@ -81,6 +81,12 @@ static void error_builtin(const char *err, va_list params)
>  
>  static void warn_builtin(const char *warn, va_list params)
>  {
> +	/*
> +	 * We call this trace2 function first and expect it to va_copy 'params'
> +	 * before using it (because an 'ap' can only be walked once).
> +	 */
> +	trace2_cmd_error_va(warn, params);
> +
>  	vreportf("warning: ", warn, params);

Without the comment, this would have been a huge red sign.  Given
what the trace2 function does, I think cmd_error_va() has to do the
va_copy()/va_end() dance somewhere in it, so from the caller's point
of view, not having to va_copy()/va_end() is convenient and nice,
but perhaps we can eventually (not today---we have the same issue
with die_builtin() and error_builtin()) move the comment to the
callee so that other people who are writing more callers do not have
to rediscover what to do with "can va_lsit be used more than once?"
issue.  Perhaps like (I am not demonstrating the removal of dups):

 trace2.h | 5 +++++
 1 file changed, 5 insertions(+)

diff --git c/trace2.h w/trace2.h
index b18bc5529c..10ba231122 100644
--- c/trace2.h
+++ w/trace2.h
@@ -116,6 +116,11 @@ int trace2_cmd_exit_fl(const char *file, int line, int code);
  * Emit an 'error' event.
  *
  * Write an error message to the TRACE2 targets.
+ *
+ * Note that the "va_list ap" the caller has is not touched, because
+ * it is fed to each of the TRACE2 targets, which must use va_copy()
+ * and use va_end() on the copy.  The caller can still use ap it uses
+ * to call this funciton and and call va_end() on it when it is done.
  */
 void trace2_cmd_error_va_fl(const char *file, int line, const char *fmt,
 			    va_list ap);

  reply	other threads:[~2020-11-23 22:40 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-23 19:04 [RFC PATCH] usage: add trace2 entry upon warning() Jonathan Tan
2020-11-23 20:45 ` [RFC PATCH v2] " Jonathan Tan
2020-11-23 22:30   ` Junio C Hamano [this message]
2020-11-24 20:05 ` [PATCH v3] " Jonathan Tan
2020-11-24 22:15   ` Junio C Hamano
2020-11-30 16:16 ` [RFC PATCH] " Jeff Hostetler

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: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqqblfnn1u3.fsf@gitster.c.googlers.com \
    --to=gitster@pobox.com \
    --cc=git@jeffhostetler.com \
    --cc=git@vger.kernel.org \
    --cc=jonathantanmy@google.com \
    /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://80x24.org/mirrors/git.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).