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:
parent
32f264bfef
commit
1b03efee58
8 changed files with 31 additions and 28 deletions
|
@ -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().
|
||||
|
|
22
array.c
22
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;
|
||||
}
|
||||
|
||||
|
|
8
enum.c
8
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");
|
||||
|
|
4
eval.c
4
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);
|
||||
|
|
3
file.c
3
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]);
|
||||
}
|
||||
|
|
2
intern.h
2
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 *);
|
||||
|
|
9
util.c
9
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 */
|
||||
|
|
3
util.h
3
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*);
|
||||
|
|
Loading…
Reference in a new issue