summaryrefslogtreecommitdiff
path: root/enum.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-09-21 09:35:29 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-09-21 09:35:29 +0000
commitba19ba779cc232474d75eb190e7420bf667832dc (patch)
treeac9f317f71df73b44ce9a4b0b485f6df646d44bc /enum.c
parentde5a85496ac4ae7bd24b5fc7acb8001a5e4d8b7d (diff)
* array.c (rb_ary_uniq_bang): element size might change during
comparison. [ruby-dev:24298] * 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/branches/ruby_1_8@6940 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'enum.c')
-rw-r--r--enum.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/enum.c b/enum.c
index d502047..fceed39 100644
--- a/enum.c
+++ b/enum.c
@@ -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];