{"thread":{"id":"39707","subject":"[PATCH] Fix definition of ARRAY_SIZE for non-gcc builds","startedAt":"2015-06-24T07:44:27Z","lastAt":"2015-06-24T22:19:10Z","messageCount":3,"participants":["Charles Bailey"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"264707","messageId":"1435131867-11361-1-git-send-email-charles@hashpling.org","threadId":"39707","inReplyTo":null,"subject":"[PATCH] Fix definition of ARRAY_SIZE for non-gcc builds","fromName":"Charles Bailey","fromEmail":"charles@hashpling.org","sentAt":"2015-06-24T07:44:27Z","receivedAt":"2015-06-24T07:44:27Z","isPatch":true,"sender":{"key":"charles@hashpling.org","avatar":"https://avatars.githubusercontent.com/u/1668475?v=4"},"body":"From: Charles Bailey <cbailey32@bloomberg.net>\n\nThe improved ARRAY_SIZE macro uses BARF_UNLESS_AN_ARRAY which is expands\nto a valid check for recent gcc versions and to 0 for older gcc\nversions but is not defined on non-gcc builds.\n\nNon-gcc builds need this macro to expand to 0 as well. The current\nouter test (defined(__GNUC__) && (__GNUC__)) is a strictly weaker\ncondition than the inner test (GIT_GNUC_PREREQ(3, 1)) so we can omit the\nouter test and cause the BARF_UNLESS_AN_ARRAY macro to be defined\ncorrectly on non-gcc builds as well as gcc builds with older versions.\n\nSigned-off-by: Charles Bailey <cbailey32@bloomberg.net>\n---\n\nThis fixes a build regression introduced in v2.4.4 so this patch is\nbased off that tag.\n\n git-compat-util.h | 8 +++-----\n 1 file changed, 3 insertions(+), 5 deletions(-)\n\ndiff --git a/git-compat-util.h b/git-compat-util.h\nindex b45c75f..8c2b7aa 100644\n--- a/git-compat-util.h\n+++ b/git-compat-util.h\n@@ -58,15 +58,13 @@\n #define BUILD_ASSERT_OR_ZERO(cond) \\\n \t(sizeof(char [1 - 2*!(cond)]) - 1)\n \n-#if defined(__GNUC__) && (__GNUC__ >= 3)\n-# if GIT_GNUC_PREREQ(3, 1)\n+#if GIT_GNUC_PREREQ(3, 1)\n  /* &arr[0] degrades to a pointer: a different type from an array */\n # define BARF_UNLESS_AN_ARRAY(arr)\t\t\t\t\t\t\\\n \tBUILD_ASSERT_OR_ZERO(!__builtin_types_compatible_p(__typeof__(arr), \\\n \t\t\t\t\t\t\t   __typeof__(&(arr)[0])))\n-# else\n-#  define BARF_UNLESS_AN_ARRAY(arr) 0\n-# endif\n+#else\n+# define BARF_UNLESS_AN_ARRAY(arr) 0\n #endif\n /*\n  * ARRAY_SIZE - get the number of elements in a visible array\n-- \n2.4.0.53.g8440f74\n"},{"id":"264781","messageId":"1435183927-21217-1-git-send-email-charles@hashpling.org","threadId":"39707","inReplyTo":"1435131867-11361-1-git-send-email-charles@hashpling.org","subject":"[PATCH v2] Fix definition of ARRAY_SIZE for non-gcc builds","fromName":"Charles Bailey","fromEmail":"charles@hashpling.org","sentAt":"2015-06-24T22:12:07Z","receivedAt":"2015-06-24T22:12:07Z","isPatch":true,"sender":{"key":"charles@hashpling.org","avatar":"https://avatars.githubusercontent.com/u/1668475?v=4"},"body":"From: Charles Bailey <cbailey32@bloomberg.net>\n\nThe improved ARRAY_SIZE macro uses BARF_UNLESS_AN_ARRAY which is expands\nto a valid check for recent gcc versions and to 0 for older gcc\nversions but is not defined on non-gcc builds.\n\nNon-gcc builds need this macro to expand to 0 as well. The current outer\ntest (defined(__GNUC__) && (__GNUC__ >= 3)) is a strictly weaker\ncondition than the inner test (GIT_GNUC_PREREQ(3, 1)) so we can omit the\nouter test and cause the BARF_UNLESS_AN_ARRAY macro to be defined\ncorrectly on non-gcc builds as well as gcc builds with older versions.\n\nSigned-off-by: Charles Bailey <cbailey32@bloomberg.net>\n---\n\nThis resend fixes a copy and paste error in the outer test in the\ncommit message. The patch remains the same.\n\nThis fixes a build regression introduced in v2.4.4 so this patch is\nbased off maint.\n\n git-compat-util.h | 8 +++-----\n 1 file changed, 3 insertions(+), 5 deletions(-)\n\ndiff --git a/git-compat-util.h b/git-compat-util.h\nindex b45c75f..8c2b7aa 100644\n--- a/git-compat-util.h\n+++ b/git-compat-util.h\n@@ -58,15 +58,13 @@\n #define BUILD_ASSERT_OR_ZERO(cond) \\\n \t(sizeof(char [1 - 2*!(cond)]) - 1)\n \n-#if defined(__GNUC__) && (__GNUC__ >= 3)\n-# if GIT_GNUC_PREREQ(3, 1)\n+#if GIT_GNUC_PREREQ(3, 1)\n  /* &arr[0] degrades to a pointer: a different type from an array */\n # define BARF_UNLESS_AN_ARRAY(arr)\t\t\t\t\t\t\\\n \tBUILD_ASSERT_OR_ZERO(!__builtin_types_compatible_p(__typeof__(arr), \\\n \t\t\t\t\t\t\t   __typeof__(&(arr)[0])))\n-# else\n-#  define BARF_UNLESS_AN_ARRAY(arr) 0\n-# endif\n+#else\n+# define BARF_UNLESS_AN_ARRAY(arr) 0\n #endif\n /*\n  * ARRAY_SIZE - get the number of elements in a visible array\n-- \n2.4.0.53.g8440f74\n"},{"id":"264782","messageId":"20150624221910.GA21368@hashpling.org","threadId":"39707","inReplyTo":"1435183927-21217-1-git-send-email-charles@hashpling.org","subject":"Re: [PATCH v2] Fix definition of ARRAY_SIZE for non-gcc builds","fromName":"Charles Bailey","fromEmail":"charles@hashpling.org","sentAt":"2015-06-24T22:19:10Z","receivedAt":"2015-06-24T22:19:10Z","isPatch":true,"sender":{"key":"charles@hashpling.org","avatar":"https://avatars.githubusercontent.com/u/1668475?v=4"},"body":"On Wed, Jun 24, 2015 at 11:12:07PM +0100, Charles Bailey wrote:\n> From: Charles Bailey <cbailey32@bloomberg.net>\n> \n> The improved ARRAY_SIZE macro uses BARF_UNLESS_AN_ARRAY which is expands\n> to a valid check for recent gcc versions and to 0 for older gcc\n> versions but is not defined on non-gcc builds.\n \nActually hitting send is a sure fire way to get me spot other errors:\ns/which is expands/which expands/\n"}]}