Re: [PATCH] qsort_r: new module, for GNU-style qsort_r
On 16/09/14 21:28, Paul Eggert wrote: Thanks, should be fixed with the attached patch, which I pushed. Confirmed. -tgc
Re: [PATCH] qsort_r: new module, for GNU-style qsort_r
On 15/09/14 18:00, Paul Eggert wrote: On 09/15/2014 07:11 AM, Pádraig Brady wrote: Did you forget to git add m4/qsort_r.m4 ? Oops, yes I did. Thanks for catching that. I added it as per attached. The daily build failed on my Solaris 9 host: gcc -std=gnu99 -DHAVE_CONFIG_H -DEXEEXT=\\ -DEXEEXT=\\ -DNO_XMALLOC -DEXEEXT=\\ -I. -I.. -DGNULIB_STRICT_CHECKING=1 -I/usr/tgcware/include -D_REENTRANT -fvisibility=hidden -g -O2 -MT qsort.o -MD -MP -MF $depbase.Tpo -c -o qsort.o qsort.c \ mv -f $depbase.Tpo $depbase.Po In file included from ./stdlib.h:96:0, from qsort.c:24: ./unistd.h:135:3: error: #error Please include config.h first. #error Please include config.h first. ^ In file included from /usr/include/sys/time.h:419:0, from ./sys/time.h:39, from /usr/include/sys/select.h:20, from ./sys/select.h:36, from /usr/tgcware/lib/gcc/i386-pc-solaris2.9/4.9.1/include-fixed/sys/types.h:588, from ./sys/types.h:28, from /usr/include/sys/wait.h:20, from ./sys/wait.h:28, from ./stdlib.h:46, from qsort.c:24: ./unistd.h:567:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'extern' _GL_CXXALIAS_SYS (chdir, int, (const char *file) _GL_ARG_NONNULL ((1))); ^ ./stdlib.h:455:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'extern' _GL_FUNCDECL_SYS (_Exit, _Noreturn void, (int status)); ^ make[4]: *** [qsort.o] Error 1 -tgc
Re: [PATCH] qsort_r: new module, for GNU-style qsort_r
Thanks, should be fixed with the attached patch, which I pushed. From 70fc25e89c4fc8721a9633df01d774b6ec8775f2 Mon Sep 17 00:00:00 2001 From: Paul Eggert egg...@cs.ucla.edu Date: Tue, 16 Sep 2014 12:26:48 -0700 Subject: [PATCH] qsort_r: include config.h Problem reported by Tom G. Christensen in: http://lists.gnu.org/archive/html/bug-gnulib/2014-09/msg00071.html * lib/qsort.c [!_LIBC]: Include config.h first. --- ChangeLog | 7 +++ lib/qsort.c | 4 2 files changed, 11 insertions(+) diff --git a/ChangeLog b/ChangeLog index fbdc903..58a6511 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2014-09-16 Paul Eggert egg...@cs.ucla.edu + + qsort_r: include config.h + Problem reported by Tom G. Christensen in: + http://lists.gnu.org/archive/html/bug-gnulib/2014-09/msg00071.html + * lib/qsort.c [!_LIBC]: Include config.h first. + 2014-09-16 Dylan Cali calid1...@gmail.com avltree-list: avoid compiler warnings (trivial) diff --git a/lib/qsort.c b/lib/qsort.c index a6c33eb..8dd4ff1 100644 --- a/lib/qsort.c +++ b/lib/qsort.c @@ -20,6 +20,10 @@ Engineering a sort function; Jon Bentley and M. Douglas McIlroy; Software - Practice and Experience; Vol. 23 (11), 1249-1265, 1993. */ +#ifndef _LIBC +# include config.h +#endif + #include limits.h #include stdlib.h #include string.h -- 1.9.3
Re: [PATCH] qsort_r: new module, for GNU-style qsort_r
Did you forget to git add m4/qsort_r.m4 ?
Re: [PATCH] qsort_r: new module, for GNU-style qsort_r
On 09/15/2014 07:11 AM, Pádraig Brady wrote: Did you forget to git add m4/qsort_r.m4 ? Oops, yes I did. Thanks for catching that. I added it as per attached. From 41473cf94a0e9eef96870b76eed9070f87d0c01a Mon Sep 17 00:00:00 2001 From: Paul Eggert egg...@cs.ucla.edu Date: Mon, 15 Sep 2014 08:59:18 -0700 Subject: [PATCH] qsort_r: new module, for GNU-style qsort_r * m4/qsort_r.m4: New file. Forgot to add this earlier. --- ChangeLog | 5 + m4/qsort_r.m4 | 48 2 files changed, 53 insertions(+) create mode 100644 m4/qsort_r.m4 diff --git a/ChangeLog b/ChangeLog index 3748237..689d21b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2014-09-15 Paul Eggert egg...@cs.ucla.edu + + qsort_r: new module, for GNU-style qsort_r + * m4/qsort_r.m4: New file. Forgot to add this earlier. + 2014-09-15 Werner LEMBERG w...@gnu.org strerror_r-posix: support compilation with C++ diff --git a/m4/qsort_r.m4 b/m4/qsort_r.m4 new file mode 100644 index 000..c4576f4 --- /dev/null +++ b/m4/qsort_r.m4 @@ -0,0 +1,48 @@ +dnl Reentrant sort function. + +dnl Copyright 2014 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl Written by Paul Eggert. + +AC_DEFUN([gl_FUNC_QSORT_R], +[ + dnl Persuade glibc to declare qsort_r. + AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS]) + + AC_REQUIRE([gl_STDLIB_H_DEFAULTS]) + + AC_CACHE_CHECK([for qsort_r signature], [gl_cv_qsort_r_signature], +[AC_LINK_IFELSE( + [AC_LANG_PROGRAM([[#include stdlib.h + void qsort_r (void *, size_t, size_t, +int (*) (void const *, void const *, + void *), +void *); + void (*p) (void *, size_t, size_t, + int (*) (void const *, void const *, + void *), + void *) = qsort_r; +]])], + [gl_cv_qsort_r_signature=GNU], + [AC_LINK_IFELSE( + [AC_LANG_PROGRAM([[#include stdlib.h + void qsort_r (void *, size_t, size_t, void *, + int (*) (void *, +void const *, +void const *)); + void (*p) (void *, size_t, size_t, void *, +int (*) (void *, void const *, + void const *)) = qsort_r; + ]])], + [gl_cv_qsort_r_signature=BSD], + [gl_cv_qsort_r_signature=no])])]) + + case $gl_cv_qsort_r_signature in +GNU) HAVE_QSORT_R=1;; +BSD) HAVE_QSORT_R=1 REPLACE_QSORT_R=1;; +*) HAVE_QSORT_R=0 REPLACE_QSORT_R=1;; + esac +]) -- 1.9.3
Re: [PATCH] qsort_r: new module, for GNU-style qsort_r
On Fri, Aug 29, 2014 at 01:50:48PM -0700, Paul Eggert wrote: This works even on FreeBSD, which has an incompatible qsort_r API. * MODULES.html.sh: Add it. * doc/glibc-functions/qsort_r.texi: It's now supported. * lib/qsort.c: New file, taken from glibc with minor changes inside #ifndef _LIBC and with an unnecessary #include alloca.h removed. * lib/qsort_r.c: New file, compiled only on FreeBSD. * lib/stdlib.in.h (qsort_r): Declare in the usual way. * m4/stdlib_h.m4 (gl_STDLIB_H_DEFAULTS): * modules/qsort_r, modules/qsort_r-tests: New files. * modules/stdlib (Makefile): Set up its defaults. * tests/test-qsort_r.c: New file. I'm happy to see this module; it's often useful to have the ability to pass auxiliary data to a sort comparison function. I skimmed through the patch but I did not review it in detail. Thanks, Ben.
[PATCH] qsort_r: new module, for GNU-style qsort_r
This works even on FreeBSD, which has an incompatible qsort_r API. * MODULES.html.sh: Add it. * doc/glibc-functions/qsort_r.texi: It's now supported. * lib/qsort.c: New file, taken from glibc with minor changes inside #ifndef _LIBC and with an unnecessary #include alloca.h removed. * lib/qsort_r.c: New file, compiled only on FreeBSD. * lib/stdlib.in.h (qsort_r): Declare in the usual way. * m4/stdlib_h.m4 (gl_STDLIB_H_DEFAULTS): * modules/qsort_r, modules/qsort_r-tests: New files. * modules/stdlib (Makefile): Set up its defaults. * tests/test-qsort_r.c: New file. --- ChangeLog| 16 +++ MODULES.html.sh | 1 + doc/glibc-functions/qsort_r.texi | 9 +- lib/qsort.c | 254 +++ lib/qsort_r.c| 51 lib/stdlib.in.h | 23 m4/stdlib_h.m4 | 2 + modules/qsort_r | 31 + modules/qsort_r-tests| 10 ++ modules/stdlib | 2 + tests/test-qsort_r.c | 47 11 files changed, 443 insertions(+), 3 deletions(-) create mode 100644 lib/qsort.c create mode 100644 lib/qsort_r.c create mode 100644 modules/qsort_r create mode 100644 modules/qsort_r-tests create mode 100644 tests/test-qsort_r.c diff --git a/ChangeLog b/ChangeLog index f440efe..a1f9602 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,19 @@ +2014-08-29 Paul Eggert egg...@cs.ucla.edu + + qsort_r: new module, for GNU-style qsort_r + This works even on FreeBSD, which has an incompatible qsort_r API. + * MODULES.html.sh: Add it. + * doc/glibc-functions/qsort_r.texi: It's now supported. + * lib/qsort.c: New file, taken from glibc with minor changes + inside #ifndef _LIBC and with an unnecessary #include alloca.h + removed. + * lib/qsort_r.c: New file, compiled only on FreeBSD. + * lib/stdlib.in.h (qsort_r): Declare in the usual way. + * m4/stdlib_h.m4 (gl_STDLIB_H_DEFAULTS): + * modules/qsort_r, modules/qsort_r-tests: New files. + * modules/stdlib (Makefile): Set up its defaults. + * tests/test-qsort_r.c: New file. + 2014-08-08 Paul Eggert egg...@cs.ucla.edu vla: new module diff --git a/MODULES.html.sh b/MODULES.html.sh index 6c4520a..db66253 100755 --- a/MODULES.html.sh +++ b/MODULES.html.sh @@ -1712,6 +1712,7 @@ func_all_modules () func_begin_table func_module array-mergesort func_module mpsort + func_module qsort_r func_end_table element=Date and time time.h diff --git a/doc/glibc-functions/qsort_r.texi b/doc/glibc-functions/qsort_r.texi index 94df972..ced8c70 100644 --- a/doc/glibc-functions/qsort_r.texi +++ b/doc/glibc-functions/qsort_r.texi @@ -6,11 +6,14 @@ Gnulib module: --- Portability problems fixed by Gnulib: @itemize +@item +This function has an incompatible API on some platforms: +FreeBSD 10. +@item +This function is missing on some platforms: +glibc 2.7, NetBSD 5.0, OpenBSD 3.8, Minix 3.1.8, AIX 7.1, HP-UX 11.31, IRIX 6.5, OSF/1 5.1, Solaris 11 2011-11, Cygwin, mingw, MSVC 9, Interix 3.5, BeOS. @end itemize Portability problems not fixed by Gnulib: @itemize -@item -This function is missing on some platforms: -glibc 2.7, NetBSD 5.0, OpenBSD 3.8, Minix 3.1.8, AIX 7.1, HP-UX 11.31, IRIX 6.5, OSF/1 5.1, Solaris 11 2011-11, Cygwin, mingw, MSVC 9, Interix 3.5, BeOS. @end itemize diff --git a/lib/qsort.c b/lib/qsort.c new file mode 100644 index 000..a6c33eb --- /dev/null +++ b/lib/qsort.c @@ -0,0 +1,254 @@ +/* Copyright (C) 1991-2014 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Written by Douglas C. Schmidt (schm...@ics.uci.edu). + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + http://www.gnu.org/licenses/. */ + +/* If you consider tuning this algorithm, you should consult first: + Engineering a sort function; Jon Bentley and M. Douglas McIlroy; + Software - Practice and Experience; Vol. 23 (11), 1249-1265, 1993. */ + +#include limits.h +#include stdlib.h +#include string.h + +#ifndef _LIBC +# define _quicksort qsort_r +# define __compar_d_fn_t compar_d_fn_t +typedef int (*compar_d_fn_t) (const void *, const void *, void *); +#endif + +/* Byte-wise swap two items of size SIZE. */ +#define SWAP(a, b, size)