Adds a configure test for qsort_r and use the fallback code path if
it's not available. Fixes d/88127. rt/qsort.d changes have been
pushed upstream and reviewed there: https://github.com/dlang/druntime/pull/2480
Bootstrapped & ran D test suite on x86_64_linux with a recent glibc,
checked that Have_Qsort_R is set correctly in config.d.

libphobos/ChangeLog:

2019-02-02  Johannes Pfau  <johannesp...@gmail.com>

        * m4/druntime/libraries.m4: Add check for qsort_r as 
DRUNTIME_LIBRARIES_CLIB.
        * configure.ac: Use qsort_r check.
        * libdruntime/gcc/config.d.in: Add Have_Qsort_R to store check result.
        * libdruntime/rt/qsort.d: Check Have_Qsort_R before using qsort_r.
        * Makefile.in: Regenerate.
        * aclocal.m4: Regenerate.
        * configure: Regenerate.
        * libdruntime/Makefile.in: Regenerate.
        * src/Makefile.in: Regenerate.
        * testsuite/Makefile.in: Regenerate.

---
 libphobos/Makefile.in                 |  7 +++--
 libphobos/aclocal.m4                  | 40 +++++++++++++--------------
 libphobos/configure                   | 26 +++++++++++++++--
 libphobos/configure.ac                |  1 +
 libphobos/libdruntime/Makefile.in     |  7 +++--
 libphobos/libdruntime/gcc/config.d.in |  3 ++
 libphobos/libdruntime/rt/qsort.d      | 18 ++++++++++++
 libphobos/m4/druntime/libraries.m4    | 12 ++++++++
 libphobos/src/Makefile.in             |  5 ++--
 libphobos/testsuite/Makefile.in       |  5 ++--
 10 files changed, 92 insertions(+), 32 deletions(-)

diff --git a/libphobos/configure.ac b/libphobos/configure.ac
index 919bc194af4..a0cd9bc9546 100644
--- a/libphobos/configure.ac
+++ b/libphobos/configure.ac
@@ -126,6 +126,7 @@ DRUNTIME_OS_SOURCES
 DRUNTIME_OS_THREAD_MODEL
 DRUNTIME_OS_ARM_EABI_UNWINDER
 DRUNTIME_OS_MINFO_BRACKETING
+DRUNTIME_LIBRARIES_CLIB
 
 WITH_LOCAL_DRUNTIME([
   AC_LANG_PUSH([D])
diff --git a/libphobos/libdruntime/gcc/config.d.in 
b/libphobos/libdruntime/gcc/config.d.in
index 3a1d493f3c4..803adb90c4a 100644
--- a/libphobos/libdruntime/gcc/config.d.in
+++ b/libphobos/libdruntime/gcc/config.d.in
@@ -46,3 +46,6 @@ enum GNU_Have_64Bit_Atomics = @DCFG_HAVE_64BIT_ATOMICS@;
 
 // Do we have libatomic available
 enum GNU_Have_LibAtomic = @DCFG_HAVE_LIBATOMIC@;
+
+// Do we have qsort_r function
+enum Have_Qsort_R = @DCFG_HAVE_QSORT_R@;
diff --git a/libphobos/libdruntime/rt/qsort.d b/libphobos/libdruntime/rt/qsort.d
index 6c3e71c35c7..af0c1eb704a 100644
--- a/libphobos/libdruntime/rt/qsort.d
+++ b/libphobos/libdruntime/rt/qsort.d
@@ -27,7 +27,25 @@ else version (TVOS)
 else version (WatchOS)
     version = Darwin;
 
+// qsort_r was added in glibc in 2.8. 
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88127
 version (CRuntime_Glibc)
+{
+    version (GNU)
+    {
+        import gcc.config : Have_Qsort_R;
+        enum Glibc_Qsort_R = Have_Qsort_R;
+    }
+    else
+    {
+        enum Glibc_Qsort_R = true;
+    }
+}
+else
+{
+    enum Glibc_Qsort_R = false;
+}
+
+static if (Glibc_Qsort_R)
 {
     alias extern (C) int function(scope const void *, scope const void *, 
scope void *) Cmp;
     extern (C) void qsort_r(scope void *base, size_t nmemb, size_t size, Cmp 
cmp, scope void *arg);
diff --git a/libphobos/m4/druntime/libraries.m4 
b/libphobos/m4/druntime/libraries.m4
index 17f93468b87..35a791d137a 100644
--- a/libphobos/m4/druntime/libraries.m4
+++ b/libphobos/m4/druntime/libraries.m4
@@ -161,3 +161,15 @@ AC_DEFUN([DRUNTIME_LIBRARIES_BACKTRACE],
   AC_SUBST(BACKTRACE_SUPPORTS_THREADS)
   AC_LANG_POP([C])
 ])
+
+# DRUNTIME_LIBRARIES_CLIB
+# -----------------------
+# Perform various feature checks on the C library.
+AC_DEFUN([DRUNTIME_LIBRARIES_CLIB],
+[
+  AC_LANG_PUSH([C])
+  DCFG_HAVE_QSORT_R=false
+  AC_CHECK_FUNC(qsort_r, [DCFG_HAVE_QSORT_R=true])
+  AC_SUBST(DCFG_HAVE_QSORT_R)
+  AC_LANG_POP([C])
+])

Reply via email to