ruby-changes:32810
From: glass <ko1@a...>
Date: Sat, 8 Feb 2014 21:50:33 +0900 (JST)
Subject: [ruby-changes:32810] glass:r44889 (trunk): * configure.in: check qsort_r(3) and whether it is GNU version.
glass 2014-02-08 21:50:28 +0900 (Sat, 08 Feb 2014) New Revision: 44889 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=44889 Log: * configure.in: check qsort_r(3) and whether it is GNU version. BSD version has different prototype. * util.h: use qsort_r() as ruby_qsort() if it is GNU version. * util.c: define ruby_qsort() if needed. Modified files: trunk/ChangeLog trunk/configure.in trunk/include/ruby/util.h trunk/util.c Index: include/ruby/util.h =================================================================== --- include/ruby/util.h (revision 44888) +++ include/ruby/util.h (revision 44889) @@ -55,8 +55,12 @@ unsigned long ruby_scan_oct(const char * https://github.com/ruby/ruby/blob/trunk/include/ruby/util.h#L55 #define scan_hex(s,l,e) ((int)ruby_scan_hex((s),(l),(e))) unsigned long ruby_scan_hex(const char *, size_t, size_t *); +#ifdef HAVE_GNU_QSORT_R +# define ruby_qsort qsort_r +#else void ruby_qsort(void *, const size_t, const size_t, int (*)(const void *, const void *, void *), void *); +#endif void ruby_setenv(const char *, const char *); void ruby_unsetenv(const char *); Index: configure.in =================================================================== --- configure.in (revision 44888) +++ configure.in (revision 44889) @@ -1920,6 +1920,7 @@ AC_CHECK_FUNCS(posix_fadvise) https://github.com/ruby/ruby/blob/trunk/configure.in#L1920 AC_CHECK_FUNCS(posix_memalign) AC_CHECK_FUNCS(ppoll) AC_CHECK_FUNCS(pread) +AC_CHECK_FUNCS(qsort_r) AC_CHECK_FUNCS(readlink) AC_CHECK_FUNCS(round) AC_CHECK_FUNCS(seekdir) @@ -1980,6 +1981,39 @@ RUBY_CHECK_BUILTIN_FUNC(__builtin_clzll, https://github.com/ruby/ruby/blob/trunk/configure.in#L1981 RUBY_CHECK_BUILTIN_FUNC(__builtin_choose_expr, [__builtin_choose_expr(0, 0, 0)]) RUBY_CHECK_BUILTIN_FUNC(__builtin_types_compatible_p, [__builtin_types_compatible_p(int, int)]) +if test "$ac_cv_func_qsort_r" != no; then + AC_CACHE_CHECK(that qsort_r is GNU version, rb_cv_gnu_qsort_r, + [AC_RUN_IFELSE( + [AC_LANG_SOURCE([[ +#include <stdlib.h> + +int unsorted[] = { 4, 3, 2, 1 }; +int sorted[] = { 1, 2, 3, 4 }; + +int +compar(const void *a, const void *b, void *arg) +{ + if (*(int *)arg != 42) exit(1); + return *(int *)a - *(int *)b; +} + +int +main(void) +{ + int arg = 42; + qsort_r(unsorted, 4, sizeof(int), compar, &arg); + if (memcmp(sorted, unsorted, 4) != 0) return 1; + return 0; +} + ]])], + [rb_cv_gnu_qsort_r=yes], + [rb_cv_gnu_qsort_r=no]) + ]) + if test "$rb_cv_gnu_qsort_r" != no; then + AC_DEFINE(HAVE_GNU_QSORT_R, 1) + fi +fi + # Some platform need -lrt for clock_gettime, but the other don't. if test x"$ac_cv_func_clock_gettime" != xyes; then # glibc 2.17 moves clock_* functions from librt to the main C library. Index: ChangeLog =================================================================== --- ChangeLog (revision 44888) +++ ChangeLog (revision 44889) @@ -1,3 +1,12 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Sat Feb 8 21:44:07 2014 Masaki Matsushita <glass.saga@g...> + + * configure.in: check qsort_r(3) and whether it is GNU version. + BSD version has different prototype. + + * util.h: use qsort_r() as ruby_qsort() if it is GNU version. + + * util.c: define ruby_qsort() if needed. + Sat Feb 8 16:34:36 2014 Tanaka Akira <akr@f...> * lib/resolv.rb (Resolv::DNS::Message::MessageDecoder#get_labels): Index: util.c =================================================================== --- util.c (revision 44888) +++ util.c (revision 44889) @@ -186,6 +186,7 @@ ruby_strtoul(const char *str, char **end https://github.com/ruby/ruby/blob/trunk/util.c#L186 #endif +#ifndef HAVE_GNU_QSORT_R /* mm.c */ #define mmtype long @@ -452,6 +453,7 @@ ruby_qsort(void* base, const size_t nel, https://github.com/ruby/ruby/blob/trunk/util.c#L453 else goto nxt; /* need not to sort both sides */ } } +#endif /* HAVE_GNU_QSORT_R */ char * ruby_strdup(const char *str) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/