summaryrefslogtreecommitdiff
path: root/array.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-10-11 12:30:48 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-10-11 12:30:48 +0000
commit1b03efee58ee4c825b278a7bcb4ac80e41e7c18a (patch)
tree816ef7c640e729eeb44447211cb3be2071ee86c6 /array.c
parent32f264bfef9ef6eb96c791ee33ffad8d5e461578 (diff)
* array.c, enum.c, eval.c, util.c: safer function pointer usage.
fixed: [ruby-core:06143] * util.h (qsort): removed the definition incompatible to ANSI. fixed: [ruby-core:06147] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9374 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'array.c')
-rw-r--r--array.c22
1 files changed, 12 insertions, 10 deletions
diff --git a/array.c b/array.c
index 055526f0ce..5a8c391ca4 100644
--- a/array.c
+++ b/array.c
@@ -1245,8 +1245,9 @@ rb_ary_dup(VALUE ary)
extern VALUE rb_output_fs;
static VALUE
-recursive_join(VALUE ary, VALUE *arg, int recur)
+recursive_join(VALUE ary, VALUE argp, int recur)
{
+ VALUE *arg = (VALUE *)argp;
if (recur) {
return rb_str_new2("[...]");
}
@@ -1473,21 +1474,22 @@ ary_sort_check(struct ary_sort_data *data)
}
static int
-sort_1(VALUE *a, VALUE *b, struct ary_sort_data *data)
+sort_1(const void *ap, const void *bp, void *data)
{
- VALUE retval = rb_yield_values(2, *a, *b);
+ VALUE a = *(const VALUE *)ap, b = *(const VALUE *)bp;
+ VALUE retval = rb_yield_values(2, a, b);
int n;
- n = rb_cmpint(retval, *a, *b);
- ary_sort_check(data);
+ n = rb_cmpint(retval, a, b);
+ ary_sort_check((struct ary_sort_data *)data);
return n;
}
static int
-sort_2(VALUE *ap, VALUE *bp, struct ary_sort_data *data)
+sort_2(const void *ap, const void *bp, void *data)
{
VALUE retval;
- VALUE a = *ap, b = *bp;
+ VALUE a = *(const VALUE *)ap, b = *(const VALUE *)bp;
int n;
if (FIXNUM_P(a) && FIXNUM_P(b)) {
@@ -1501,7 +1503,7 @@ sort_2(VALUE *ap, VALUE *bp, struct ary_sort_data *data)
retval = rb_funcall(a, id_cmp, 1, b);
n = rb_cmpint(retval, a, b);
- ary_sort_check(data);
+ ary_sort_check((struct ary_sort_data *)data);
return n;
}
@@ -1513,8 +1515,8 @@ sort_internal(VALUE ary)
data.ary = ary;
data.ptr = RARRAY(ary)->ptr; data.len = RARRAY(ary)->len;
- qsort(RARRAY(ary)->ptr, RARRAY(ary)->len, sizeof(VALUE),
- rb_block_given_p()?sort_1:sort_2, &data);
+ ruby_qsort(RARRAY(ary)->ptr, RARRAY(ary)->len, sizeof(VALUE),
+ rb_block_given_p()?sort_1:sort_2, &data);
return ary;
}