From abc4b723bdcd0c4480427b74e052990cfd8f0065 Mon Sep 17 00:00:00 2001 From: nobu Date: Fri, 12 Jun 2015 08:19:24 +0000 Subject: array.c: fix for enumerator * array.c (rb_ary_bsearch_index): fix function typt to return enumerator if no block given. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50844 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- array.c | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/array.c b/array.c index ee7428f4f1..7eb27cd915 100644 --- a/array.c +++ b/array.c @@ -2547,7 +2547,7 @@ rb_ary_sort(VALUE ary) return ary; } -static long ary_bsearch_index(VALUE ary); +static VALUE rb_ary_bsearch_index(VALUE ary); /* * call-seq: @@ -2605,10 +2605,12 @@ static long ary_bsearch_index(VALUE ary); static VALUE rb_ary_bsearch(VALUE ary) { - long index_result = ary_bsearch_index(ary); + VALUE index_result = rb_ary_bsearch_index(ary); - if (index_result < 0) return rb_ary_entry(ary, index_result); - return INT2FIX(index_result); + if (FIXNUM_P(index_result)) { + return rb_ary_entry(ary, FIX2LONG(index_result)); + } + return index_result; } /* @@ -2626,14 +2628,6 @@ rb_ary_bsearch(VALUE ary) static VALUE rb_ary_bsearch_index(VALUE ary) -{ - long index_result = ary_bsearch_index(ary); - - return INT2FIX(index_result); -} - -static long -ary_bsearch_index(VALUE ary) { long low = 0, high = RARRAY_LEN(ary), mid; int smaller = 0, satisfied = 0; @@ -2645,7 +2639,7 @@ ary_bsearch_index(VALUE ary) val = rb_ary_entry(ary, mid); v = rb_yield(val); if (FIXNUM_P(v)) { - if (v == INT2FIX(0)) return mid; + if (v == INT2FIX(0)) return INT2FIX(mid); smaller = (SIGNED_VALUE)v < 0; /* Fixnum preserves its sign-bit */ } else if (v == Qtrue) { @@ -2658,7 +2652,7 @@ ary_bsearch_index(VALUE ary) else if (rb_obj_is_kind_of(v, rb_cNumeric)) { const VALUE zero = INT2FIX(0); switch (rb_cmpint(rb_funcallv(v, id_cmp, 1, &zero), v, zero)) { - case 0: return mid; + case 0: return INT2FIX(mid); case 1: smaller = 1; break; case -1: smaller = 0; } @@ -2675,8 +2669,8 @@ ary_bsearch_index(VALUE ary) low = mid + 1; } } - if (!satisfied) return -1; - return low; + if (!satisfied) return Qnil; + return INT2FIX(low); } -- cgit v1.2.3