diff mbox

[1/2] Fix __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__

Message ID 1408989818-40728-1-git-send-email-jrtc27@jrtc27.com
State New
Headers show

Commit Message

Jessica Clarke Aug. 25, 2014, 6:03 p.m. UTC
Previously, this macro had taken the form 10X0, where X is the minor
version number, e.g. 1090 for OS X 10.9 Mavericks. However, as of OS X
10.10 Yosemite, it should take the form 10XX00, i.e. 101000 for 10.10.

Added a test for the new format and fixed the formatting for the
existing ones.

gcc/ChangeLog:

    * config/darwin-c.c (version_as_macro): Added extra 0 for OS X
    10.10 and above
    * config/darwin-driver.c (darwin_find_version_from_kernel): Bump
    supported kernel version

gcc/testsuite/ChangeLog:

    * gcc.db/darwin-minversion-1.c: Fixed formatting
    * gcc.db/darwin-minversion-2.c: Fixed formatting
    * gcc.db/darwin-minversion-3.c: Fixed formatting
    * gcc.dg/darwin-minversion-4.c: Added test for OS X 10.10
---
 gcc/config/darwin-c.c                      | 25 +++++++++++++++++++------
 gcc/config/darwin-driver.c                 |  2 +-
 gcc/testsuite/gcc.dg/darwin-minversion-1.c |  3 ++-
 gcc/testsuite/gcc.dg/darwin-minversion-2.c |  3 ++-
 gcc/testsuite/gcc.dg/darwin-minversion-3.c |  3 ++-
 gcc/testsuite/gcc.dg/darwin-minversion-4.c | 12 ++++++++++++
 6 files changed, 38 insertions(+), 10 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/darwin-minversion-4.c

Comments

Mike Stump Aug. 25, 2014, 8:05 p.m. UTC | #1
On Aug 25, 2014, at 11:03 AM, James Clarke <jrtc27@jrtc27.com> wrote:
> Previously, this macro had taken the form 10X0, where X is the minor
> version number, e.g. 1090 for OS X 10.9 Mavericks. However, as of OS X
> 10.10 Yosemite, it should take the form 10XX00, i.e. 101000 for 10.10.

So, if they continue using the same scheme, I’d prefer to future proof this (I don’t like software time bombs) so that 10.11.0 works as well as 10.12.0 and so on.

We didn’t do this last time, as we were unsure how the numbers would work out.  Now, it is much safer to see what the likely format will be.

Could you try that?

> -  if (major_vers > 4 + 9)
> +  if (major_vers > 4 + 10)

I think this is the only thing that has to change.
Jessica Clarke Aug. 26, 2014, 6:04 a.m. UTC | #2
So I should just take that particular check out then?

James Clarke

> On 25 Aug 2014, at 21:05, Mike Stump <mikestump@comcast.net> wrote:
> 
>> On Aug 25, 2014, at 11:03 AM, James Clarke <jrtc27@jrtc27.com> wrote:
>> Previously, this macro had taken the form 10X0, where X is the minor
>> version number, e.g. 1090 for OS X 10.9 Mavericks. However, as of OS X
>> 10.10 Yosemite, it should take the form 10XX00, i.e. 101000 for 10.10.
> 
> So, if they continue using the same scheme, I’d prefer to future proof this (I don’t like software time bombs) so that 10.11.0 works as well as 10.12.0 and so on.
> 
> We didn’t do this last time, as we were unsure how the numbers would work out.  Now, it is much safer to see what the likely format will be.
> 
> Could you try that?
> 
>> -  if (major_vers > 4 + 9)
>> +  if (major_vers > 4 + 10)
> 
> I think this is the only thing that has to change.
Mike Stump Aug. 26, 2014, 3:20 p.m. UTC | #3
On Aug 25, 2014, at 11:04 PM, James Clarke <jrtc27@jrtc27.com> wrote:
> So I should just take that particular check out then?

Oh, yeah, I guess the is the way to fix it.
diff mbox

Patch

diff --git a/gcc/config/darwin-c.c b/gcc/config/darwin-c.c
index 892ba35..7fe4b1f 100644
--- a/gcc/config/darwin-c.c
+++ b/gcc/config/darwin-c.c
@@ -571,21 +571,34 @@  find_subframework_header (cpp_reader *pfile, const char *header, cpp_dir **dirp)
 }
 
 /* Return the value of darwin_macosx_version_min suitable for the
-   __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ macro,
-   so '10.4.2' becomes 1040.  The lowest digit is always zero.
+   __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ macro, so '10.4.2'
+   becomes 1040 and '10.10.0' becomes 101000.  The lowest digit is
+   always zero, as is the second lowest for '10.10.x' and above.
    Print a warning if the version number can't be understood.  */
 static const char *
 version_as_macro (void)
 {
-  static char result[] = "1000";
+  static char result[7] = "1000";
+  int minorDigitIdx;
 
   if (strncmp (darwin_macosx_version_min, "10.", 3) != 0)
     goto fail;
   if (! ISDIGIT (darwin_macosx_version_min[3]))
     goto fail;
-  result[2] = darwin_macosx_version_min[3];
-  if (darwin_macosx_version_min[4] != '\0'
-      && darwin_macosx_version_min[4] != '.')
+
+  minorDigitIdx = 3;
+  result[2] = darwin_macosx_version_min[minorDigitIdx++];
+  if (ISDIGIT (darwin_macosx_version_min[minorDigitIdx]))
+  {
+    /* Starting with OS X 10.10, the macro ends '00' rather than '0',
+       i.e. 10.10.x becomes 101000 rather than 10100.  */
+    result[3] = darwin_macosx_version_min[minorDigitIdx++];
+    result[4] = '0';
+    result[5] = '0';
+    result[6] = '\0';
+  }
+  if (darwin_macosx_version_min[minorDigitIdx] != '\0'
+      && darwin_macosx_version_min[minorDigitIdx] != '.')
     goto fail;
 
   return result;
diff --git a/gcc/config/darwin-driver.c b/gcc/config/darwin-driver.c
index 8b6ae93..a115616 100644
--- a/gcc/config/darwin-driver.c
+++ b/gcc/config/darwin-driver.c
@@ -57,7 +57,7 @@  darwin_find_version_from_kernel (char *new_flag)
   version_p = osversion + 1;
   if (ISDIGIT (*version_p))
     major_vers = major_vers * 10 + (*version_p++ - '0');
-  if (major_vers > 4 + 9)
+  if (major_vers > 4 + 10)
     goto parse_failed;
   if (*version_p++ != '.')
     goto parse_failed;
diff --git a/gcc/testsuite/gcc.dg/darwin-minversion-1.c b/gcc/testsuite/gcc.dg/darwin-minversion-1.c
index d8a3243..6221d61 100644
--- a/gcc/testsuite/gcc.dg/darwin-minversion-1.c
+++ b/gcc/testsuite/gcc.dg/darwin-minversion-1.c
@@ -2,7 +2,8 @@ 
 /* { dg-options "-mmacosx-version-min=10.1" } */
 /* { dg-do run { target *-*-darwin* } } */
 
-int main(void)
+int
+main ()
 {
 #if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ != 1010
   fail me;
diff --git a/gcc/testsuite/gcc.dg/darwin-minversion-2.c b/gcc/testsuite/gcc.dg/darwin-minversion-2.c
index fd4975a..8e18d52 100644
--- a/gcc/testsuite/gcc.dg/darwin-minversion-2.c
+++ b/gcc/testsuite/gcc.dg/darwin-minversion-2.c
@@ -2,7 +2,8 @@ 
 /* { dg-options "-mmacosx-version-min=10.1 -mmacosx-version-min=10.3" } */
 /* { dg-do run { target *-*-darwin* } } */
 
-int main(void)
+int
+main ()
 {
 #if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ != 1030
   fail me;
diff --git a/gcc/testsuite/gcc.dg/darwin-minversion-3.c b/gcc/testsuite/gcc.dg/darwin-minversion-3.c
index d0c5934..4fcb969 100644
--- a/gcc/testsuite/gcc.dg/darwin-minversion-3.c
+++ b/gcc/testsuite/gcc.dg/darwin-minversion-3.c
@@ -2,7 +2,8 @@ 
 /* { dg-options "-mmacosx-version-min=10.4.10" } */
 /* { dg-do compile { target *-*-darwin* } } */
 
-int main(void)
+int
+main ()
 {
 #if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ != 1040
   fail me;
diff --git a/gcc/testsuite/gcc.dg/darwin-minversion-4.c b/gcc/testsuite/gcc.dg/darwin-minversion-4.c
new file mode 100644
index 0000000..1cb42eb
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/darwin-minversion-4.c
@@ -0,0 +1,12 @@ 
+/* Test that major versions greater than 9 work and have the additional 0.  */
+/* { dg-options "-mmacosx-version-min=10.10.0" } */
+/* { dg-do compile { target *-*-darwin* } } */
+
+int
+main ()
+{
+#if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ != 101000
+  fail me;
+#endif
+  return 0;
+}