All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Use __VA_ARGS__ for all of error's arguments
@ 2013-02-07 20:00 Matt Kraai
  2013-02-07 21:05 ` Junio C Hamano
  0 siblings, 1 reply; 9+ messages in thread
From: Matt Kraai @ 2013-02-07 20:00 UTC (permalink / raw)
  To: git, Max Horn, Jeff King, Junio C Hamano; +Cc: Matt Kraai

From: Matt Kraai <matt.kraai@amo.abbott.com>

QNX 6.3.2 uses GCC 2.95.3 by default, and GCC 2.95.3 doesn't remove the
comma if the error macro's variable argument is left out.

Instead of testing for a sufficiently recent version of GCC, make
__VA_ARGS__ match all of the arguments.  Since this should work on any
C99-compliant compiler, also remove the tests around the macro definition.

Signed-off-by: Matt Kraai <matt.kraai@amo.abbott.com>
---
 git-compat-util.h | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/git-compat-util.h b/git-compat-util.h
index cc2abee..df1681f 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -305,14 +305,9 @@ extern void warning(const char *err, ...) __attribute__((format (printf, 1, 2)))
 
 /*
  * Let callers be aware of the constant return value; this can help
- * gcc with -Wuninitialized analysis. We have to restrict this trick to
- * gcc, though, because of the variadic macro and the magic ## comma pasting
- * behavior. But since we're only trying to help gcc, anyway, it's OK; other
- * compilers will fall back to using the function as usual.
+ * gcc with -Wuninitialized analysis.
  */
-#if defined(__GNUC__) && ! defined(__clang__)
-#define error(fmt, ...) (error((fmt), ##__VA_ARGS__), -1)
-#endif
+#define error(...) (error(__VA_ARGS__), -1)
 
 extern void set_die_routine(NORETURN_PTR void (*routine)(const char *err, va_list params));
 extern void set_error_routine(void (*routine)(const char *err, va_list params));
-- 
1.8.1.GIT

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH] Use __VA_ARGS__ for all of error's arguments
  2013-02-07 20:00 [PATCH] Use __VA_ARGS__ for all of error's arguments Matt Kraai
@ 2013-02-07 21:05 ` Junio C Hamano
  2013-02-07 21:14   ` John Keeping
  2013-02-07 21:24   ` Matt Kraai
  0 siblings, 2 replies; 9+ messages in thread
From: Junio C Hamano @ 2013-02-07 21:05 UTC (permalink / raw)
  To: Matt Kraai; +Cc: git, Max Horn, Jeff King, Matt Kraai

Matt Kraai <kraai@ftbfs.org> writes:

> -#if defined(__GNUC__) && ! defined(__clang__)
> -#define error(fmt, ...) (error((fmt), ##__VA_ARGS__), -1)
> -#endif
> +#define error(...) (error(__VA_ARGS__), -1)

Before your change, we only define error() macro for GCC variants,
but with your patch that no longer is the case.  Does every compiler
that compiles Git correctly today support this style of varargs
macros?

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] Use __VA_ARGS__ for all of error's arguments
  2013-02-07 21:05 ` Junio C Hamano
@ 2013-02-07 21:14   ` John Keeping
  2013-02-07 21:24   ` Matt Kraai
  1 sibling, 0 replies; 9+ messages in thread
From: John Keeping @ 2013-02-07 21:14 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Matt Kraai, git, Max Horn, Jeff King, Matt Kraai

On Thu, Feb 07, 2013 at 01:05:19PM -0800, Junio C Hamano wrote:
> Matt Kraai <kraai@ftbfs.org> writes:
> 
> > -#if defined(__GNUC__) && ! defined(__clang__)
> > -#define error(fmt, ...) (error((fmt), ##__VA_ARGS__), -1)
> > -#endif
> > +#define error(...) (error(__VA_ARGS__), -1)
> 
> Before your change, we only define error() macro for GCC variants,
> but with your patch that no longer is the case.  Does every compiler
> that compiles Git correctly today support this style of varargs
> macros?

At the very least the "! defined(__clang__)" was only recently added
[1], although it shouldn't be needed once Clang 3.3 is released.

[1] http://article.gmane.org/gmane.comp.version-control.git/213787


John

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] Use __VA_ARGS__ for all of error's arguments
  2013-02-07 21:05 ` Junio C Hamano
  2013-02-07 21:14   ` John Keeping
@ 2013-02-07 21:24   ` Matt Kraai
  2013-02-07 21:30     ` Matt Kraai
  1 sibling, 1 reply; 9+ messages in thread
From: Matt Kraai @ 2013-02-07 21:24 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git, Max Horn, Jeff King, Matt Kraai

On Thu, Feb 07, 2013 at 01:05:19PM -0800, Junio C Hamano wrote:
> Matt Kraai <kraai@ftbfs.org> writes:
> 
> > -#if defined(__GNUC__) && ! defined(__clang__)
> > -#define error(fmt, ...) (error((fmt), ##__VA_ARGS__), -1)
> > -#endif
> > +#define error(...) (error(__VA_ARGS__), -1)
> 
> Before your change, we only define error() macro for GCC variants,
> but with your patch that no longer is the case.  Does every compiler
> that compiles Git correctly today support this style of varargs
> macros?

I don't know and I don't think it's likely I can confirm this.  I'll
submit a new patch that just changes the definition, since I don't
know of any problems other than mine with the current situation.

-- 
Matt

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH] Use __VA_ARGS__ for all of error's arguments
  2013-02-07 21:24   ` Matt Kraai
@ 2013-02-07 21:30     ` Matt Kraai
  2013-02-08  4:24       ` Jeff King
  0 siblings, 1 reply; 9+ messages in thread
From: Matt Kraai @ 2013-02-07 21:30 UTC (permalink / raw)
  To: git, Max Horn, Junio C Hamano, Jeff King; +Cc: Matt Kraai

From: Matt Kraai <matt.kraai@amo.abbott.com>

QNX 6.3.2 uses GCC 2.95.3 by default, and GCC 2.95.3 doesn't remove the
comma if the error macro's variable argument is left out.

Instead of testing for a sufficiently recent version of GCC, make
__VA_ARGS__ match all of the arguments.

Signed-off-by: Matt Kraai <matt.kraai@amo.abbott.com>
---
 git-compat-util.h | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/git-compat-util.h b/git-compat-util.h
index cc2abee..2e960a9 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -305,13 +305,10 @@ extern void warning(const char *err, ...) __attribute__((format (printf, 1, 2)))
 
 /*
  * Let callers be aware of the constant return value; this can help
- * gcc with -Wuninitialized analysis. We have to restrict this trick to
- * gcc, though, because of the variadic macro and the magic ## comma pasting
- * behavior. But since we're only trying to help gcc, anyway, it's OK; other
- * compilers will fall back to using the function as usual.
+ * gcc with -Wuninitialized analysis.
  */
 #if defined(__GNUC__) && ! defined(__clang__)
-#define error(fmt, ...) (error((fmt), ##__VA_ARGS__), -1)
+#define error(...) (error(__VA_ARGS__), -1)
 #endif
 
 extern void set_die_routine(NORETURN_PTR void (*routine)(const char *err, va_list params));
-- 
1.8.1.2.546.gfc9f004

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH] Use __VA_ARGS__ for all of error's arguments
  2013-02-07 21:30     ` Matt Kraai
@ 2013-02-08  4:24       ` Jeff King
  2013-02-08  4:39         ` Matt Kraai
  0 siblings, 1 reply; 9+ messages in thread
From: Jeff King @ 2013-02-08  4:24 UTC (permalink / raw)
  To: Matt Kraai; +Cc: git, Max Horn, Junio C Hamano, Matt Kraai

On Thu, Feb 07, 2013 at 01:30:32PM -0800, Matt Kraai wrote:

> From: Matt Kraai <matt.kraai@amo.abbott.com>
> 
> QNX 6.3.2 uses GCC 2.95.3 by default, and GCC 2.95.3 doesn't remove the
> comma if the error macro's variable argument is left out.
> 
> Instead of testing for a sufficiently recent version of GCC, make
> __VA_ARGS__ match all of the arguments.

Thanks, this looks better than the original (we do not assume a C99
compiler, so just doing this unconditionally would probably break some
other older systems which do not use gcc).

>  /*
>   * Let callers be aware of the constant return value; this can help
> - * gcc with -Wuninitialized analysis. We have to restrict this trick to
> - * gcc, though, because of the variadic macro and the magic ## comma pasting
> - * behavior. But since we're only trying to help gcc, anyway, it's OK; other
> - * compilers will fall back to using the function as usual.
> + * gcc with -Wuninitialized analysis.
>   */
>  #if defined(__GNUC__) && ! defined(__clang__)
> -#define error(fmt, ...) (error((fmt), ##__VA_ARGS__), -1)
> +#define error(...) (error(__VA_ARGS__), -1)

Should you be dropping most of the comment like this? I would expect it
to be more like:

  We have to restrict this trick to gcc, though, because we do not
  assume all compilers support variadic macros. But since...

Other than that, I think it is OK. The compiler will still catch
"error()" with no arguments and generate the appropriate diagnostic (in
fact, it is better, because the error is now passing too few args to a
function, not to the macro).

-Peff

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] Use __VA_ARGS__ for all of error's arguments
  2013-02-08  4:24       ` Jeff King
@ 2013-02-08  4:39         ` Matt Kraai
  2013-02-08 15:09           ` Matt Kraai
  0 siblings, 1 reply; 9+ messages in thread
From: Matt Kraai @ 2013-02-08  4:39 UTC (permalink / raw)
  To: Jeff King; +Cc: git, Max Horn, Junio C Hamano, Matt Kraai

On Thu, Feb 07, 2013 at 11:24:28PM -0500, Jeff King wrote:
> Should you be dropping most of the comment like this? I would expect it
> to be more like:
> 
>   We have to restrict this trick to gcc, though, because we do not
>   assume all compilers support variadic macros. But since...

I'll submit a new patch with this change tomorrow.

> Other than that, I think it is OK. The compiler will still catch
> "error()" with no arguments and generate the appropriate diagnostic (in
> fact, it is better, because the error is now passing too few args to a
> function, not to the macro).

Great, thanks for the review.

-- 
Matt

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH] Use __VA_ARGS__ for all of error's arguments
  2013-02-08  4:39         ` Matt Kraai
@ 2013-02-08 15:09           ` Matt Kraai
  2013-02-08 15:54             ` Jeff King
  0 siblings, 1 reply; 9+ messages in thread
From: Matt Kraai @ 2013-02-08 15:09 UTC (permalink / raw)
  To: git, Max Horn, Jeff King, Junio C Hamano; +Cc: Matt Kraai

From: Matt Kraai <matt.kraai@amo.abbott.com>

QNX 6.3.2 uses GCC 2.95.3 by default, and GCC 2.95.3 doesn't remove the
comma if the error macro's variable argument is left out.

Instead of testing for a sufficiently recent version of GCC, make
__VA_ARGS__ match all of the arguments.

Signed-off-by: Matt Kraai <matt.kraai@amo.abbott.com>
---
 git-compat-util.h | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/git-compat-util.h b/git-compat-util.h
index cc2abee..b7eaaa9 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -305,13 +305,13 @@ extern void warning(const char *err, ...) __attribute__((format (printf, 1, 2)))
 
 /*
  * Let callers be aware of the constant return value; this can help
- * gcc with -Wuninitialized analysis. We have to restrict this trick to
- * gcc, though, because of the variadic macro and the magic ## comma pasting
- * behavior. But since we're only trying to help gcc, anyway, it's OK; other
- * compilers will fall back to using the function as usual.
+ * gcc with -Wuninitialized analysis. We restrict this trick to gcc, though,
+ * because some compilers may not support variadic macros. Since we're only
+ * trying to help gcc, anyway, it's OK; other compilers will fall back to
+ * using the function as usual.
  */
 #if defined(__GNUC__) && ! defined(__clang__)
-#define error(fmt, ...) (error((fmt), ##__VA_ARGS__), -1)
+#define error(...) (error(__VA_ARGS__), -1)
 #endif
 
 extern void set_die_routine(NORETURN_PTR void (*routine)(const char *err, va_list params));
-- 
1.8.1.2.546.g90a97a4

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH] Use __VA_ARGS__ for all of error's arguments
  2013-02-08 15:09           ` Matt Kraai
@ 2013-02-08 15:54             ` Jeff King
  0 siblings, 0 replies; 9+ messages in thread
From: Jeff King @ 2013-02-08 15:54 UTC (permalink / raw)
  To: Matt Kraai; +Cc: git, Max Horn, Junio C Hamano, Matt Kraai

On Fri, Feb 08, 2013 at 07:09:28AM -0800, Matt Kraai wrote:

> From: Matt Kraai <matt.kraai@amo.abbott.com>
> 
> QNX 6.3.2 uses GCC 2.95.3 by default, and GCC 2.95.3 doesn't remove the
> comma if the error macro's variable argument is left out.
> 
> Instead of testing for a sufficiently recent version of GCC, make
> __VA_ARGS__ match all of the arguments.
>
> [...]
>
>  /*
>   * Let callers be aware of the constant return value; this can help
> - * gcc with -Wuninitialized analysis. We have to restrict this trick to
> - * gcc, though, because of the variadic macro and the magic ## comma pasting
> - * behavior. But since we're only trying to help gcc, anyway, it's OK; other
> - * compilers will fall back to using the function as usual.
> + * gcc with -Wuninitialized analysis. We restrict this trick to gcc, though,
> + * because some compilers may not support variadic macros. Since we're only
> + * trying to help gcc, anyway, it's OK; other compilers will fall back to
> + * using the function as usual.
>   */
>  #if defined(__GNUC__) && ! defined(__clang__)
> -#define error(fmt, ...) (error((fmt), ##__VA_ARGS__), -1)
> +#define error(...) (error(__VA_ARGS__), -1)

Acked-by: Jeff King <peff@peff.net>

Thanks.

-Peff

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2013-02-08 15:54 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-02-07 20:00 [PATCH] Use __VA_ARGS__ for all of error's arguments Matt Kraai
2013-02-07 21:05 ` Junio C Hamano
2013-02-07 21:14   ` John Keeping
2013-02-07 21:24   ` Matt Kraai
2013-02-07 21:30     ` Matt Kraai
2013-02-08  4:24       ` Jeff King
2013-02-08  4:39         ` Matt Kraai
2013-02-08 15:09           ` Matt Kraai
2013-02-08 15:54             ` Jeff King

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.