1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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
This commit is contained in:
nobu 2005-10-11 12:30:48 +00:00
parent 32f264bfef
commit 1b03efee58
8 changed files with 31 additions and 28 deletions

View file

@ -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 * configure.in (RUBY_FUNC_ATTRIBUTE): check prefixed attribute form
first. [ruby-dev:27398] 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> Mon Oct 10 00:09:54 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* parse.y (ripper_initialize): rollback obj_respond_to(). * parse.y (ripper_initialize): rollback obj_respond_to().

22
array.c
View file

@ -1245,8 +1245,9 @@ rb_ary_dup(VALUE ary)
extern VALUE rb_output_fs; extern VALUE rb_output_fs;
static VALUE static VALUE
recursive_join(VALUE ary, VALUE *arg, int recur) recursive_join(VALUE ary, VALUE argp, int recur)
{ {
VALUE *arg = (VALUE *)argp;
if (recur) { if (recur) {
return rb_str_new2("[...]"); return rb_str_new2("[...]");
} }
@ -1473,21 +1474,22 @@ ary_sort_check(struct ary_sort_data *data)
} }
static int 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; int n;
n = rb_cmpint(retval, *a, *b); n = rb_cmpint(retval, a, b);
ary_sort_check(data); ary_sort_check((struct ary_sort_data *)data);
return n; return n;
} }
static int 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 retval;
VALUE a = *ap, b = *bp; VALUE a = *(const VALUE *)ap, b = *(const VALUE *)bp;
int n; int n;
if (FIXNUM_P(a) && FIXNUM_P(b)) { 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); retval = rb_funcall(a, id_cmp, 1, b);
n = rb_cmpint(retval, a, b); n = rb_cmpint(retval, a, b);
ary_sort_check(data); ary_sort_check((struct ary_sort_data *)data);
return n; return n;
} }
@ -1513,8 +1515,8 @@ sort_internal(VALUE ary)
data.ary = ary; data.ary = ary;
data.ptr = RARRAY(ary)->ptr; data.len = RARRAY(ary)->len; data.ptr = RARRAY(ary)->ptr; data.len = RARRAY(ary)->len;
qsort(RARRAY(ary)->ptr, RARRAY(ary)->len, sizeof(VALUE), ruby_qsort(RARRAY(ary)->ptr, RARRAY(ary)->len, sizeof(VALUE),
rb_block_given_p()?sort_1:sort_2, &data); rb_block_given_p()?sort_1:sort_2, &data);
return ary; return ary;
} }

8
enum.c
View file

@ -433,10 +433,10 @@ sort_by_i(VALUE i, VALUE ary)
} }
static int 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 a = (*(NODE *const *)ap)->u1.value;
VALUE b = bb[0]->u1.value; VALUE b = (*(NODE *const *)bp)->u1.value;
return rb_cmpint(rb_funcall(a, id_cmp, 1, b), a, b); 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; RBASIC(ary)->klass = 0;
rb_iterate(rb_each, obj, sort_by_i, ary); rb_iterate(rb_each, obj, sort_by_i, ary);
if (RARRAY(ary)->len > 1) { 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) { if (RBASIC(ary)->klass) {
rb_raise(rb_eRuntimeError, "sort_by reentered"); rb_raise(rb_eRuntimeError, "sort_by reentered");

4
eval.c
View file

@ -12943,9 +12943,7 @@ recursive_pop(void)
} }
VALUE VALUE
rb_exec_recursive(VALUE (*func) (/* ??? */), VALUE obj, VALUE arg) rb_exec_recursive(VALUE (*func)(VALUE, VALUE, int), VALUE obj, VALUE arg)
/* VALUE obj, VALUE arg, int flag */
{ {
if (recursive_check(obj)) { if (recursive_check(obj)) {
return (*func)(obj, arg, Qtrue); return (*func)(obj, arg, Qtrue);

3
file.c
View file

@ -2695,8 +2695,9 @@ static VALUE separator;
static VALUE rb_file_join(VALUE ary, VALUE sep); static VALUE rb_file_join(VALUE ary, VALUE sep);
static VALUE 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("[...]"); if (recur) return rb_str_new2("[...]");
return rb_file_join(arg[0], arg[1]); return rb_file_join(arg[0], arg[1]);
} }

View file

@ -281,7 +281,7 @@ VALUE rb_thread_main(void);
VALUE rb_thread_local_aref(VALUE, ID); VALUE rb_thread_local_aref(VALUE, ID);
VALUE rb_thread_local_aset(VALUE, ID, VALUE); VALUE rb_thread_local_aset(VALUE, ID, VALUE);
void rb_thread_atfork(void); 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 */ /* file.c */
int eaccess(const char*, int); int eaccess(const char*, int);
VALUE rb_file_s_expand_path(int, VALUE *); VALUE rb_file_s_expand_path(int, VALUE *);

9
util.c
View file

@ -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 ? c : a)) : \
((*cmp)(b,c,d)>0 ? b : ((*cmp)(a,c,d)<0 ? a : c))) ((*cmp)(b,c,d)>0 ? b : ((*cmp)(a,c,d)<0 ? a : c)))
void ruby_qsort (base, nel, size, cmp, d) void
void* base; ruby_qsort(void* base, const int nel, const int size,
const int nel; int (*cmp)(const void*, const void*, void*), void *d)
const int size;
int (*cmp)();
void *d;
{ {
register char *l, *r, *m; /* l,r:left,right group m:median point */ 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 */ register int t, eq_l, eq_r; /* eq_l: all items in left group are equal to S */

3
util.h
View file

@ -43,8 +43,7 @@ unsigned long scan_hex(const char*, int, int*);
void ruby_add_suffix(VALUE str, char *suffix); void ruby_add_suffix(VALUE str, char *suffix);
#endif #endif
void ruby_qsort(void*, const int, const int, int (*)(), void*); void ruby_qsort(void*, const int, const int, int (*)(const void*,const void*,void*), void*);
#define qsort(b,n,s,c,d) ruby_qsort(b,n,s,c,d)
void ruby_setenv(const char*, const char*); void ruby_setenv(const char*, const char*);
void ruby_unsetenv(const char*); void ruby_unsetenv(const char*);