Subject: Re: [PATCH v8 1/4] usage: make error functions a stack

From: Junio C Hamano <[email-masked]>
Date: Tue, 15 Jul 2014 15:47:47 -0700

Jacob Keller <[email-masked]> writes:

>  extern void set_error_routine(void (*routine)(const char *err, va_list params));
> +extern void pop_error_routine(void);

pop that undoes set smells somewhat weird.  Perhaps we should rename
set to push?  That would allow us catch possible topics that add new
calls to set_error_routine() as well by forcing the system not to
link when they are merged without necessary fixes.

> +/* push error routine onto the error function stack */
>  void set_error_routine(void (*routine)(const char *err, va_list params))
>  {
> -	error_routine = routine;
> +	struct error_func_list *efl = xmalloc(sizeof(*efl));
> +	efl->func = routine;
> +	efl->next = error_funcs;
> +	error_funcs = efl;
> +}
> +
> +/* pop a single error routine off of the error function stack, thus reverting
> + * to previous error. Should always be paired with a set_error_routine */
> +void pop_error_routine(void)
> +{
> +	assert(error_funcs != &default_error_func);
> +
> +	struct error_func_list *efl = error_funcs;

decl-after-stmt.  Can be fixed easily by flipping the above two
lines.

> +	if (efl->next) {
> +		error_funcs = efl->next;
> +		free(efl);
> +	}
>  }
>  
>  void set_die_is_recursing_routine(int (*routine)(void))
> @@ -144,7 +167,7 @@ int error(const char *err, ...)
>  	va_list params;
>  
>  	va_start(params, err);
> -	error_routine(err, params);
> +	error_funcs->func(err, params);
>  	va_end(params);
>  	return -1;
>  }