diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-09-21 03:08:33 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-09-21 03:08:33 +0000 |
commit | bfabc05a4375b84fa128af89337b1195248bd6da (patch) | |
tree | ae0c8f703dca2b6ae94a5b5518c736d373bca377 /enum.c | |
parent | 90ae99b0f0505f66a6fc1dfb7d7c631bf4bf76cc (diff) | |
download | ruby-bfabc05a4375b84fa128af89337b1195248bd6da.tar.gz |
* enum.c (enum_sort_by): do not use qsort directly. use
rb_ary_sort_bang() instead. [ruby-dev:24291]
* enum.c (enum_sort_by): pedantic type check added.
[ruby-dev:24291]
* hash.c (rb_hash_foreach_iter): check iter_lev after each
iteration. [ruby-dev:24289]
* array.c (rb_ary_and): element size might change during
comparison. [ruby-dev:24290]
* array.c (rb_ary_or): ditto. [ruby-dev:24292]
* array.c (rb_ary_equal): wrong fix. [ruby-dev:24286]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6939 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'enum.c')
-rw-r--r-- | enum.c | 17 |
1 files changed, 10 insertions, 7 deletions
@@ -397,14 +397,17 @@ sort_by_i(i, ary) return Qnil; } -static int -sort_by_cmp(a, b) - VALUE *a, *b; +static VALUE +sort_by_cmp(values, ary) + VALUE values; { - VALUE retval; + VALUE a = RARRAY(values)->ptr[0]; + VALUE b = RARRAY(values)->ptr[1]; - retval = rb_funcall(RARRAY(*a)->ptr[0], id_cmp, 1, RARRAY(*b)->ptr[0]); - return rb_cmpint(retval, *a, *b); + /* pedantic check; they must be arrays */ + Check_Type(a, T_ARRAY); + Check_Type(b, T_ARRAY); + return rb_funcall(RARRAY(a)->ptr[0], id_cmp, 1, RARRAY(b)->ptr[0]); } /* @@ -491,7 +494,7 @@ enum_sort_by(obj) } rb_iterate(rb_each, obj, sort_by_i, ary); if (RARRAY(ary)->len > 1) { - qsort(RARRAY(ary)->ptr, RARRAY(ary)->len, sizeof(VALUE), sort_by_cmp); + rb_iterate(rb_ary_sort_bang, ary, sort_by_cmp, ary); } for (i=0; i<RARRAY(ary)->len; i++) { VALUE e = RARRAY(ary)->ptr[i]; |