* [PATCH] Fix definition of ARRAY_SIZE for non-gcc builds
@ 2015-06-24 7:44 Charles Bailey
2015-06-24 22:12 ` [PATCH v2] " Charles Bailey
0 siblings, 1 reply; 3+ messages in thread
From: Charles Bailey @ 2015-06-24 7:44 UTC (permalink / raw)
To: Junio C Hamano, git
From: Charles Bailey <cbailey32@bloomberg.net>
The improved ARRAY_SIZE macro uses BARF_UNLESS_AN_ARRAY which is expands
to a valid check for recent gcc versions and to 0 for older gcc
versions but is not defined on non-gcc builds.
Non-gcc builds need this macro to expand to 0 as well. The current
outer test (defined(__GNUC__) && (__GNUC__)) is a strictly weaker
condition than the inner test (GIT_GNUC_PREREQ(3, 1)) so we can omit the
outer test and cause the BARF_UNLESS_AN_ARRAY macro to be defined
correctly on non-gcc builds as well as gcc builds with older versions.
Signed-off-by: Charles Bailey <cbailey32@bloomberg.net>
---
This fixes a build regression introduced in v2.4.4 so this patch is
based off that tag.
git-compat-util.h | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/git-compat-util.h b/git-compat-util.h
index b45c75f..8c2b7aa 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -58,15 +58,13 @@
#define BUILD_ASSERT_OR_ZERO(cond) \
(sizeof(char [1 - 2*!(cond)]) - 1)
-#if defined(__GNUC__) && (__GNUC__ >= 3)
-# if GIT_GNUC_PREREQ(3, 1)
+#if GIT_GNUC_PREREQ(3, 1)
/* &arr[0] degrades to a pointer: a different type from an array */
# define BARF_UNLESS_AN_ARRAY(arr) \
BUILD_ASSERT_OR_ZERO(!__builtin_types_compatible_p(__typeof__(arr), \
__typeof__(&(arr)[0])))
-# else
-# define BARF_UNLESS_AN_ARRAY(arr) 0
-# endif
+#else
+# define BARF_UNLESS_AN_ARRAY(arr) 0
#endif
/*
* ARRAY_SIZE - get the number of elements in a visible array
--
2.4.0.53.g8440f74
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH v2] Fix definition of ARRAY_SIZE for non-gcc builds
2015-06-24 7:44 [PATCH] Fix definition of ARRAY_SIZE for non-gcc builds Charles Bailey
@ 2015-06-24 22:12 ` Charles Bailey
2015-06-24 22:19 ` Charles Bailey
0 siblings, 1 reply; 3+ messages in thread
From: Charles Bailey @ 2015-06-24 22:12 UTC (permalink / raw)
To: Junio C Hamano, git; +Cc: Elia Pinto
From: Charles Bailey <cbailey32@bloomberg.net>
The improved ARRAY_SIZE macro uses BARF_UNLESS_AN_ARRAY which is expands
to a valid check for recent gcc versions and to 0 for older gcc
versions but is not defined on non-gcc builds.
Non-gcc builds need this macro to expand to 0 as well. The current outer
test (defined(__GNUC__) && (__GNUC__ >= 3)) is a strictly weaker
condition than the inner test (GIT_GNUC_PREREQ(3, 1)) so we can omit the
outer test and cause the BARF_UNLESS_AN_ARRAY macro to be defined
correctly on non-gcc builds as well as gcc builds with older versions.
Signed-off-by: Charles Bailey <cbailey32@bloomberg.net>
---
This resend fixes a copy and paste error in the outer test in the
commit message. The patch remains the same.
This fixes a build regression introduced in v2.4.4 so this patch is
based off maint.
git-compat-util.h | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/git-compat-util.h b/git-compat-util.h
index b45c75f..8c2b7aa 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -58,15 +58,13 @@
#define BUILD_ASSERT_OR_ZERO(cond) \
(sizeof(char [1 - 2*!(cond)]) - 1)
-#if defined(__GNUC__) && (__GNUC__ >= 3)
-# if GIT_GNUC_PREREQ(3, 1)
+#if GIT_GNUC_PREREQ(3, 1)
/* &arr[0] degrades to a pointer: a different type from an array */
# define BARF_UNLESS_AN_ARRAY(arr) \
BUILD_ASSERT_OR_ZERO(!__builtin_types_compatible_p(__typeof__(arr), \
__typeof__(&(arr)[0])))
-# else
-# define BARF_UNLESS_AN_ARRAY(arr) 0
-# endif
+#else
+# define BARF_UNLESS_AN_ARRAY(arr) 0
#endif
/*
* ARRAY_SIZE - get the number of elements in a visible array
--
2.4.0.53.g8440f74
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] Fix definition of ARRAY_SIZE for non-gcc builds
2015-06-24 22:12 ` [PATCH v2] " Charles Bailey
@ 2015-06-24 22:19 ` Charles Bailey
0 siblings, 0 replies; 3+ messages in thread
From: Charles Bailey @ 2015-06-24 22:19 UTC (permalink / raw)
To: Junio C Hamano, git; +Cc: Elia Pinto
On Wed, Jun 24, 2015 at 11:12:07PM +0100, Charles Bailey wrote:
> From: Charles Bailey <cbailey32@bloomberg.net>
>
> The improved ARRAY_SIZE macro uses BARF_UNLESS_AN_ARRAY which is expands
> to a valid check for recent gcc versions and to 0 for older gcc
> versions but is not defined on non-gcc builds.
Actually hitting send is a sure fire way to get me spot other errors:
s/which is expands/which expands/
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-06-24 22:19 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-24 7:44 [PATCH] Fix definition of ARRAY_SIZE for non-gcc builds Charles Bailey
2015-06-24 22:12 ` [PATCH v2] " Charles Bailey
2015-06-24 22:19 ` Charles Bailey
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).