ruby-changes:39776
From: nobu <ko1@a...>
Date: Tue, 15 Sep 2015 12:44:54 +0900 (JST)
Subject: [ruby-changes:39776] nobu:r51857 (trunk): util.c: BSD qsort_r
nobu 2015-09-15 12:44:34 +0900 (Tue, 15 Sep 2015) New Revision: 51857 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=51857 Log: util.c: BSD qsort_r * util.c (ruby_qsort): use BSD-style qsort_r if available. Modified files: trunk/ChangeLog trunk/configure.in trunk/util.c Index: configure.in =================================================================== --- configure.in (revision 51856) +++ configure.in (revision 51857) @@ -2314,6 +2314,9 @@ void qsort_r(void *base, size_t nmemb, s https://github.com/ruby/ruby/blob/trunk/configure.in#L2314 AS_CASE("$rb_cv_gnu_qsort_r:$rb_cv_bsd_qsort_r", [yes:no], [ AC_DEFINE(HAVE_GNU_QSORT_R, 1) + ], + [no:yes], [ + AC_DEFINE(HAVE_BSD_QSORT_R, 1) ]) fi Index: ChangeLog =================================================================== --- ChangeLog (revision 51856) +++ ChangeLog (revision 51857) @@ -1,3 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Tue Sep 15 12:44:32 2015 Nobuyoshi Nakada <nobu@r...> + + * util.c (ruby_qsort): use BSD-style qsort_r if available. + Mon Sep 14 19:26:34 2015 Shugo Maeda <shugo@r...> * lib/net/ftp.rb (parse_mlsx_entry): parse pathnames including Index: util.c =================================================================== --- util.c (revision 51856) +++ util.c (revision 51857) @@ -191,8 +191,30 @@ ruby_strtoul(const char *str, char **end https://github.com/ruby/ruby/blob/trunk/util.c#L191 # define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) #endif +#if defined HAVE_BSD_QSORT_R +typedef int (cmpfunc_t)(const void*, const void*, void*); -#ifndef HAVE_GNU_QSORT_R +struct bsd_qsort_r_args { + cmpfunc_t *cmp; + void *arg; +}; + +static int +cmp_bsd_qsort(void *d, const void *a, const void *b) +{ + const struct bsd_qsort_r_args *args = d; + return (*args->cmp)(a, b, args->arg); +} + +void +ruby_qsort(void* base, const size_t nel, const size_t size, cmpfunc_t *cmp, void *d) +{ + struct bsd_qsort_r_args args; + args.cmp = cmp; + args.arg = d; + qsort_r(base, nel, size, &args, cmp_bsd_qsort); +} +#elif !defined HAVE_GNU_QSORT_R /* mm.c */ #define mmtype long -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/