# [PATCH] usage.[ch] API users: use report_fn, not hardcoded prototype

2 messages from 2022-02-21 to 2022-02-21. Participants: Ævar Arnfjörð Bjarmason, Taylor Blau.
Thread: https://gitlist.dev/t/57452

## Ævar Arnfjörð Bjarmason, 2022-02-21 16:09

Subject: [PATCH] usage.[ch] API users: use report_fn, not hardcoded prototype
Message-ID: <patch-1.1-7551daf131b-20220221T160719Z-avarab@gmail.com>
URL: https://gitlist.dev/e/patch-1.1-7551daf131b-20220221T160719Z-avarab%40gmail.com

```
Change a couple of users of "report_fn" that hardcoded a definition of
it to use the definition of report_fn instead.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---

I'll eventually want to depend on this for a larger topic I plan to
re-roll[1], but in the meantime this trivial fix can hopefully cook &
graduate.

1. https://lore.kernel.org/git/RFC-cover-00.21-00000000000-20211115T220831Z-avarab@gmail.com/

 apply.h       | 4 ++--
 run-command.c | 3 +--
 2 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/apply.h b/apply.h
index 4052da50c06..3ddc8be9c71 100644
--- a/apply.h
+++ b/apply.h
@@ -103,8 +103,8 @@ struct apply_state {
 	 * set_error_routine() or set_warn_routine() to install muting
 	 * routines when in verbosity_silent mode.
 	 */
-	void (*saved_error_routine)(const char *err, va_list params);
-	void (*saved_warn_routine)(const char *warn, va_list params);
+	report_fn saved_error_routine;
+	report_fn saved_warn_routine;
 
 	/* These control whitespace errors */
 	enum apply_ws_error_action ws_error_action;
diff --git a/run-command.c b/run-command.c
index a8501e38ceb..3d854c498aa 100644
--- a/run-command.c
+++ b/run-command.c
@@ -362,10 +362,9 @@ static void NORETURN child_die_fn(const char *err, va_list params)
 /* this runs in the parent process */
 static void child_err_spew(struct child_process *cmd, struct child_err *cerr)
 {
-	static void (*old_errfn)(const char *err, va_list params);
+	report_fn old_errfn = get_error_routine();
 	report_fn die_message_routine = get_die_message_routine();
 
-	old_errfn = get_error_routine();
 	set_error_routine(die_message_routine);
 	errno = cerr->syserr;
 
-- 
2.35.1.1132.ga1fe46f8690


```

## Taylor Blau, 2022-02-21 18:21

Subject: Re: [PATCH] usage.[ch] API users: use report_fn, not hardcoded prototype
Message-ID: <YhPYGDfzdMElklX7@nand.local>
URL: https://gitlist.dev/e/YhPYGDfzdMElklX7%40nand.local
In-Reply-To: <patch-1.1-7551daf131b-20220221T160719Z-avarab@gmail.com>

```
On Mon, Feb 21, 2022 at 05:09:18PM +0100, Ævar Arnfjörð Bjarmason wrote:
> Change a couple of users of "report_fn" that hardcoded a definition of
> it to use the definition of report_fn instead.
>
> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
> ---
>
> I'll eventually want to depend on this for a larger topic I plan to
> re-roll[1], but in the meantime this trivial fix can hopefully cook &
> graduate.

This looks good to me, thanks.

> diff --git a/run-command.c b/run-command.c
> index a8501e38ceb..3d854c498aa 100644
> --- a/run-command.c
> +++ b/run-command.c
> @@ -362,10 +362,9 @@ static void NORETURN child_die_fn(const char *err, va_list params)
>  /* this runs in the parent process */
>  static void child_err_spew(struct child_process *cmd, struct child_err *cerr)
>  {
> -	static void (*old_errfn)(const char *err, va_list params);
> +	report_fn old_errfn = get_error_routine();
>  	report_fn die_message_routine = get_die_message_routine();

Perhaps as part of the larger series you alluded to earlier, but we
could get rid of the die_message_routine variable here altogether. It
only exists to pass as the argument to set_error_routine(), and isn't
used anywhere else in the function.

So you could do something like this on top:

--- >8 ---
diff --git a/run-command.c b/run-command.c
index 3d854c498a..4afa01db9a 100644
--- a/run-command.c
+++ b/run-command.c
@@ -363,9 +363,8 @@ static void NORETURN child_die_fn(const char *err, va_list params)
 static void child_err_spew(struct child_process *cmd, struct child_err *cerr)
 {
 	report_fn old_errfn = get_error_routine();
-	report_fn die_message_routine = get_die_message_routine();

-	set_error_routine(die_message_routine);
+	set_error_routine(get_die_message_routine());
 	errno = cerr->syserr;

 	switch (cerr->err) {
--- 8< ---

But it doesn't need to happen here, just an idle thought I had while
reading.

Thanks,
Taylor

```
