public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Iain D Sandoe <iains@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc(refs/users/iains/heads/d-for-darwin)] darwin: Implement osxVersionMin for getTargetInfo
Date: Mon, 11 Oct 2021 20:35:04 +0000 (GMT)	[thread overview]
Message-ID: <20211011203504.CFBCB3857816@sourceware.org> (raw)

https://gcc.gnu.org/g:3ad1f9e192e579fc590ed6551ac9b3ff47db3e2e

commit 3ad1f9e192e579fc590ed6551ac9b3ff47db3e2e
Author: Iain Buclaw <ibuclaw@gdcproject.org>
Date:   Sat Dec 5 00:08:04 2020 +0100

    darwin: Implement osxVersionMin for getTargetInfo

Diff:
---
 gcc/config/darwin-d.c                        | 54 ++++++++++++++++++++++++++++
 libphobos/libdruntime/core/sys/posix/stdio.d |  7 ++--
 2 files changed, 59 insertions(+), 2 deletions(-)

diff --git a/gcc/config/darwin-d.c b/gcc/config/darwin-d.c
index 67d69b721b5..295db5164cc 100644
--- a/gcc/config/darwin-d.c
+++ b/gcc/config/darwin-d.c
@@ -21,6 +21,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "tm_d.h"
 #include "d/d-target.h"
 #include "d/d-target-def.h"
+#include "diagnostic.h"
 
 /* Implement TARGET_D_OS_VERSIONS for Darwin targets.  */
 
@@ -42,6 +43,58 @@ darwin_d_handle_target_object_format (void)
   return build_string_literal (strlen (objfmt) + 1, objfmt);
 }
 
+/* Given an OS X version VERSION_STR, return it as a six digit integer.  */
+
+static unsigned long
+parse_version (const char *version_str)
+{
+  const size_t version_len = strlen (version_str);
+  if (version_len < 1)
+    return 0;
+
+  /* Version string must consist of digits and periods only.  */
+  if (strspn (version_str, "0123456789.") != version_len)
+    return 0;
+
+  if (!ISDIGIT (version_str[0]) || !ISDIGIT (version_str[version_len - 1]))
+    return 0;
+
+  char *endptr;
+  unsigned long major = strtoul (version_str, &endptr, 10);
+  version_str = endptr + ((*endptr == '.') ? 1 : 0);
+
+  /* Version string must not contain adjacent periods.  */
+  if (*version_str == '.')
+    return 0;
+
+  unsigned long minor = strtoul (version_str, &endptr, 10);
+  version_str = endptr + ((*endptr == '.') ? 1 : 0);
+
+  unsigned long tiny = strtoul (version_str, &endptr, 10);
+
+  /* Version string must contain no more than three tokens.  */
+  if (*endptr != '\0')
+    return 0;
+
+  return (major * 10000) + (minor * 100) + tiny;
+}
+
+/* Handle a call to `__traits(getTargetInfo, "osxVersionMin")'.  */
+
+static tree
+darwin_d_handle_target_version_min (void)
+{
+  const unsigned long version = parse_version (darwin_macosx_version_min);
+
+  if (version == 0)
+    {
+      error ("unknown value %qs of %<-mmacosx-version-min%>",
+	     darwin_macosx_version_min);
+    }
+
+  return build_int_cst_type (integer_type_node, version);
+}
+
 /* Implement TARGET_D_REGISTER_OS_TARGET_INFO for Darwin targets.  */
 
 static void
@@ -49,6 +102,7 @@ darwin_d_register_target_info (void)
 {
   const struct d_target_info_spec handlers[] = {
     { "objectFormat", darwin_d_handle_target_object_format },
+    { "osxVersionMin", darwin_d_handle_target_version_min },
     { NULL, NULL },
   };
 
diff --git a/libphobos/libdruntime/core/sys/posix/stdio.d b/libphobos/libdruntime/core/sys/posix/stdio.d
index 41b52da7c64..fcd9fcbc29c 100644
--- a/libphobos/libdruntime/core/sys/posix/stdio.d
+++ b/libphobos/libdruntime/core/sys/posix/stdio.d
@@ -378,8 +378,11 @@ else version (Darwin)
     int   fseeko(FILE*, off_t, int);
     off_t ftello(FILE*);
 
-    ssize_t getdelim(char**, size_t*, int, FILE*);
-    ssize_t getline(char**, size_t*, FILE*);
+    static if (__traits(getTargetInfo, "osxVersionMin") >= 100700)
+    {
+        ssize_t getdelim(char**, size_t*, int, FILE*);
+        ssize_t getline(char**, size_t*, FILE*);
+    }
 }
 else version (FreeBSD)
 {


             reply	other threads:[~2021-10-11 20:35 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-11 20:35 Iain D Sandoe [this message]
  -- strict thread matches above, loose matches on Subject: below --
2021-10-18 15:54 Iain D Sandoe
2021-10-15 19:33 Iain D Sandoe
2021-10-13  8:30 Iain D Sandoe
2020-12-21 20:36 Iain D Sandoe
2020-12-13 17:43 Iain D Sandoe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211011203504.CFBCB3857816@sourceware.org \
    --to=iains@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).