git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH] git-compat-util: always enable variadic macros
@ 2021-01-28  5:28 Jeff King
  2021-01-28  6:13 ` Junio C Hamano
  2021-01-29  2:11 ` brian m. carlson
  0 siblings, 2 replies; 3+ messages in thread
From: Jeff King @ 2021-01-28  5:28 UTC (permalink / raw)
  To: git

We allow variadic macros in the code base, but only if there is fallback
code for platforms that lack it. This leads to some annoyances:

  - the code is more complicated because of the fallbacks (e.g.,
    trace_printf(), etc, is implemented twice with a set of parallel
    wrappers).

  - some constructs are just impossible and we've had to live without
    them (e.g., a cross between FLEX_ALLOC and xstrfmt)

Since this feature is present in C99, we may be able to start counting
on it being available everywhere. Let's start with a weather balloon
patch to find out.

This patch makes the absolute minimal change by always setting
HAVE_VARIADIC_MACROS. If somebody runs into a platform where it's a
problem, they can undo it by commenting out the define. Likewise, if we
have to revert this, it would be quite unlikely to cause conflicts.

Once we feel comfortable that this is the right direction, then we can
start ripping out all the spots that actually look at the flag, and
removing the dead code.

Signed-off-by: Jeff King <peff@peff.net>
---
We've talked about this off and on for a few years. I don't have any
immediate plans for any features that need it, but let's get the ball
rolling.

 git-compat-util.h | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/git-compat-util.h b/git-compat-util.h
index 104993b975..5d5e47fbe2 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -1176,9 +1176,12 @@ static inline int regexec_buf(const regex_t *preg, const char *buf, size_t size,
 #endif
 #endif
 
-#if defined(__GNUC__) || (_MSC_VER >= 1400) || defined(__C99_MACRO_WITH_VA_ARGS)
+/*
+ * This is always defined as a first step towards making the use of variadic
+ * macros unconditional. If it causes compilation problems on your platform,
+ * please report it to the Git mailing list at git@vger.kernel.org.
+ */
 #define HAVE_VARIADIC_MACROS 1
-#endif
 
 /* usage.c: only to be used for testing BUG() implementation (see test-tool) */
 extern int BUG_exit_code;
-- 
2.30.0.758.gfe500d6872

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

* Re: [PATCH] git-compat-util: always enable variadic macros
  2021-01-28  5:28 [PATCH] git-compat-util: always enable variadic macros Jeff King
@ 2021-01-28  6:13 ` Junio C Hamano
  2021-01-29  2:11 ` brian m. carlson
  1 sibling, 0 replies; 3+ messages in thread
From: Junio C Hamano @ 2021-01-28  6:13 UTC (permalink / raw)
  To: Jeff King; +Cc: git

Jeff King <peff@peff.net> writes:

> We allow variadic macros in the code base, but only if there is fallback
> code for platforms that lack it. This leads to some annoyances:
>
>   - the code is more complicated because of the fallbacks (e.g.,
>     trace_printf(), etc, is implemented twice with a set of parallel
>     wrappers).
>
>   - some constructs are just impossible and we've had to live without
>     them (e.g., a cross between FLEX_ALLOC and xstrfmt)
>
> Since this feature is present in C99, we may be able to start counting
> on it being available everywhere. Let's start with a weather balloon
> patch to find out.
>
> This patch makes the absolute minimal change by always setting
> HAVE_VARIADIC_MACROS. If somebody runs into a platform where it's a
> problem, they can undo it by commenting out the define. Likewise, if we
> have to revert this, it would be quite unlikely to cause conflicts.
>
> Once we feel comfortable that this is the right direction, then we can
> start ripping out all the spots that actually look at the flag, and
> removing the dead code.
>
> Signed-off-by: Jeff King <peff@peff.net>
> ---
> We've talked about this off and on for a few years. I don't have any
> immediate plans for any features that need it, but let's get the ball
> rolling.

OK, so this is just callmine canary that can easily be undone when
somebody finds it problematic.  Let's give it enough time before we
actually start removing the fallback code that are protected by
"#ifndef HAVE_VARIADIC_MACROS" (they are quite well isolated---only
in the usage and trace, which is pretty much expected as we'd be
using the feature for printf-like macros).

Thanks.

>  git-compat-util.h | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/git-compat-util.h b/git-compat-util.h
> index 104993b975..5d5e47fbe2 100644
> --- a/git-compat-util.h
> +++ b/git-compat-util.h
> @@ -1176,9 +1176,12 @@ static inline int regexec_buf(const regex_t *preg, const char *buf, size_t size,
>  #endif
>  #endif
>  
> -#if defined(__GNUC__) || (_MSC_VER >= 1400) || defined(__C99_MACRO_WITH_VA_ARGS)
> +/*
> + * This is always defined as a first step towards making the use of variadic
> + * macros unconditional. If it causes compilation problems on your platform,
> + * please report it to the Git mailing list at git@vger.kernel.org.
> + */
>  #define HAVE_VARIADIC_MACROS 1
> -#endif
>  
>  /* usage.c: only to be used for testing BUG() implementation (see test-tool) */
>  extern int BUG_exit_code;

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

* Re: [PATCH] git-compat-util: always enable variadic macros
  2021-01-28  5:28 [PATCH] git-compat-util: always enable variadic macros Jeff King
  2021-01-28  6:13 ` Junio C Hamano
@ 2021-01-29  2:11 ` brian m. carlson
  1 sibling, 0 replies; 3+ messages in thread
From: brian m. carlson @ 2021-01-29  2:11 UTC (permalink / raw)
  To: Jeff King; +Cc: git

[-- Attachment #1: Type: text/plain, Size: 1633 bytes --]

On 2021-01-28 at 05:28:33, Jeff King wrote:
> We allow variadic macros in the code base, but only if there is fallback
> code for platforms that lack it. This leads to some annoyances:
> 
>   - the code is more complicated because of the fallbacks (e.g.,
>     trace_printf(), etc, is implemented twice with a set of parallel
>     wrappers).
> 
>   - some constructs are just impossible and we've had to live without
>     them (e.g., a cross between FLEX_ALLOC and xstrfmt)
> 
> Since this feature is present in C99, we may be able to start counting
> on it being available everywhere. Let's start with a weather balloon
> patch to find out.
> 
> This patch makes the absolute minimal change by always setting
> HAVE_VARIADIC_MACROS. If somebody runs into a platform where it's a
> problem, they can undo it by commenting out the define. Likewise, if we
> have to revert this, it would be quite unlikely to cause conflicts.
> 
> Once we feel comfortable that this is the right direction, then we can
> start ripping out all the spots that actually look at the flag, and
> removing the dead code.
> 
> Signed-off-by: Jeff King <peff@peff.net>

I'm in favor of this change.  In fact, as I've previously mentioned, I'm
in favor of just requiring C99 support across the board.  It has been
almost 22 years since that standard came out, after all.

Apparently, even Visual Studio supports C11 and C17 now[0], so there's
really no reason not to switch.

[0] https://docs.microsoft.com/en-us/cpp/overview/install-c17-support?view=msvc-160
-- 
brian m. carlson (he/him or they/them)
Houston, Texas, US

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 263 bytes --]

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

end of thread, other threads:[~2021-01-29  2:16 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-28  5:28 [PATCH] git-compat-util: always enable variadic macros Jeff King
2021-01-28  6:13 ` Junio C Hamano
2021-01-29  2:11 ` brian m. carlson

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).