summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog8
-rw-r--r--array.c22
-rw-r--r--enum.c8
-rw-r--r--eval.c4
-rw-r--r--file.c3
-rw-r--r--intern.h2
-rw-r--r--util.c9
-rw-r--r--util.h3
8 files changed, 31 insertions, 28 deletions
diff --git a/ChangeLog b/ChangeLog
index d0eb8d68b6..5f1cc20636 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,8 +1,14 @@
-Tue Oct 11 21:28:38 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Tue Oct 11 21:30:11 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* configure.in (RUBY_FUNC_ATTRIBUTE): check prefixed attribute form
first. [ruby-dev:27398]
+ * 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]
+
Mon Oct 10 00:09:54 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* parse.y (ripper_initialize): rollback obj_respond_to().
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;
}
diff --git a/enum.c b/enum.c
index 662e8da141..2229f49da5 100644
--- a/enum.c
+++ b/enum.c
@@ -433,10 +433,10 @@ sort_by_i(VALUE i, VALUE ary)
}
static int
-sort_by_cmp(NODE **aa, NODE **bb)
+sort_by_cmp(const void *ap, const void *bp, void *data)
{
- VALUE a = aa[0]->u1.value;
- VALUE b = bb[0]->u1.value;
+ VALUE a = (*(NODE *const *)ap)->u1.value;
+ VALUE b = (*(NODE *const *)bp)->u1.value;
return rb_cmpint(rb_funcall(a, id_cmp, 1, b), a, b);
}
@@ -527,7 +527,7 @@ enum_sort_by(VALUE obj)
RBASIC(ary)->klass = 0;
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, 0);
+ ruby_qsort(RARRAY(ary)->ptr, RARRAY(ary)->len, sizeof(VALUE), sort_by_cmp, 0);
}
if (RBASIC(ary)->klass) {
rb_raise(rb_eRuntimeError, "sort_by reentered");
diff --git a/eval.c b/eval.c
index 47d968830b..d04180f11c 100644
--- a/eval.c
+++ b/eval.c
@@ -12943,9 +12943,7 @@ recursive_pop(void)
}
VALUE
-rb_exec_recursive(VALUE (*func) (/* ??? */), VALUE obj, VALUE arg)
- /* VALUE obj, VALUE arg, int flag */
-
+rb_exec_recursive(VALUE (*func)(VALUE, VALUE, int), VALUE obj, VALUE arg)
{
if (recursive_check(obj)) {
return (*func)(obj, arg, Qtrue);
diff --git a/file.c b/file.c
index a69d8369d8..0c94063443 100644
--- a/file.c
+++ b/file.c
@@ -2695,8 +2695,9 @@ static VALUE separator;
static VALUE rb_file_join(VALUE ary, VALUE sep);
static VALUE
-file_inspect_join(VALUE ary, VALUE *arg, int recur)
+file_inspect_join(VALUE ary, VALUE argp, int recur)
{
+ VALUE *arg = (VALUE *)argp;
if (recur) return rb_str_new2("[...]");
return rb_file_join(arg[0], arg[1]);
}
diff --git a/intern.h b/intern.h
index ffa0906621..db233fb290 100644
--- a/intern.h
+++ b/intern.h
@@ -281,7 +281,7 @@ VALUE rb_thread_main(void);
VALUE rb_thread_local_aref(VALUE, ID);
VALUE rb_thread_local_aset(VALUE, ID, VALUE);
void rb_thread_atfork(void);
-VALUE rb_exec_recursive(VALUE(*)(ANYARGS),VALUE,VALUE);
+VALUE rb_exec_recursive(VALUE(*)(VALUE, VALUE, int),VALUE,VALUE);
/* file.c */
int eaccess(const char*, int);
VALUE rb_file_s_expand_path(int, VALUE *);
diff --git a/util.c b/util.c
index 1c841b346b..da21ee412e 100644
--- a/util.c
+++ b/util.c
@@ -470,12 +470,9 @@ typedef struct { char *LL, *RR; } stack_node; /* Stack structure for L,l,R,r */
((*cmp)(b,c,d)<0 ? b : ((*cmp)(a,c,d)<0 ? c : a)) : \
((*cmp)(b,c,d)>0 ? b : ((*cmp)(a,c,d)<0 ? a : c)))
-void ruby_qsort (base, nel, size, cmp, d)
- void* base;
- const int nel;
- const int size;
- int (*cmp)();
- void *d;
+void
+ruby_qsort(void* base, const int nel, const int size,
+ int (*cmp)(const void*, const void*, void*), void *d)
{
register char *l, *r, *m; /* l,r:left,right group m:median point */
register int t, eq_l, eq_r; /* eq_l: all items in left group are equal to S */
diff --git a/util.h b/util.h
index 032c3337b5..23316292bf 100644
--- a/util.h
+++ b/util.h
@@ -43,8 +43,7 @@ unsigned long scan_hex(const char*, int, int*);
void ruby_add_suffix(VALUE str, char *suffix);
#endif
-void ruby_qsort(void*, const int, const int, int (*)(), void*);
-#define qsort(b,n,s,c,d) ruby_qsort(b,n,s,c,d)
+void ruby_qsort(void*, const int, const int, int (*)(const void*,const void*,void*), void*);
void ruby_setenv(const char*, const char*);
void ruby_unsetenv(const char*);