* object.c (Init_Object): should do exact match for Module#==.

* compar.c (cmp_eq): returns 'false' if <=> returns 'nil'.

* compar.c (cmp_gt,cmp_ge,cmp_lt,cmp_le,cmp_between): ditto.

* pack.c (pack_pack): should propagate taintedness.

* pack.c (pack_unpack): ditto.

* eval.c (rb_thread_schedule): need to preserve errno before
  calling rb_trap_exec().

* regex.c (calculate_must_string): a bug in charset/charset_not
  parsing.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2482 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2002-05-21 05:39:19 +00:00
parent 9402cbeec5
commit edbe98d848
9 changed files with 216 additions and 192 deletions

View File

@ -20,6 +20,14 @@ Tue May 21 00:20:25 2002 Takaaki Tateishi <ttate@kt.jaist.ac.jp>
* ext/dl/lib/dl/struct.c: rename Struct#alloc to Struct#malloc. * ext/dl/lib/dl/struct.c: rename Struct#alloc to Struct#malloc.
Mon May 20 14:29:14 2002 Yukihiro Matsumoto <matz@ruby-lang.org>
* object.c (Init_Object): should do exact match for Module#==.
* compar.c (cmp_eq): returns 'false' if <=> returns 'nil'.
* compar.c (cmp_gt,cmp_ge,cmp_lt,cmp_le,cmp_between): ditto.
Mon May 20 13:28:52 2002 Nobuyoshi Nakada <nobu.nokada@softhome.net> Mon May 20 13:28:52 2002 Nobuyoshi Nakada <nobu.nokada@softhome.net>
* io.c (rb_io_clone): writing stream was not copied properly. * io.c (rb_io_clone): writing stream was not copied properly.
@ -34,6 +42,12 @@ Sat May 18 21:18:00 2002 NAKAMURA Usaku <usa@ruby-lang.org>
* win32/Makefile.sub (config.h): add VC++4/5 support about noreturn * win32/Makefile.sub (config.h): add VC++4/5 support about noreturn
directive. directive.
Sat May 18 02:16:41 2002 Yukihiro Matsumoto <matz@ruby-lang.org>
* pack.c (pack_pack): should propagate taintedness.
* pack.c (pack_unpack): ditto.
Fri May 17 16:16:19 2002 WATANABE Hirofumi <eban@ruby-lang.org> Fri May 17 16:16:19 2002 WATANABE Hirofumi <eban@ruby-lang.org>
* sampl/test.rb: use eval instead of './miniruby -c', * sampl/test.rb: use eval instead of './miniruby -c',
@ -43,6 +57,14 @@ Thu May 16 14:46:34 2002 Nobuyoshi Nakada <nobu.nokada@softhome.net>
* eval.c (rb_thread_select): cleanup conditional compilation. * eval.c (rb_thread_select): cleanup conditional compilation.
Wed May 15 06:13:35 2002 Yukihiro Matsumoto <matz@ruby-lang.org>
* eval.c (rb_thread_schedule): need to preserve errno before
calling rb_trap_exec().
* regex.c (calculate_must_string): a bug in charset/charset_not
parsing.
Tue May 14 18:17:44 2002 Nobuyoshi Nakada <nobu.nokada@softhome.net> Tue May 14 18:17:44 2002 Nobuyoshi Nakada <nobu.nokada@softhome.net>
* win32/Makefile.sub: config.h inlined. and catch up with the * win32/Makefile.sub: config.h inlined. and catch up with the
@ -60,7 +82,7 @@ Tue May 14 03:07:35 2002 Yukihiro Matsumoto <matz@ruby-lang.org>
* eval.c (rb_clear_cache_by_class): new function. * eval.c (rb_clear_cache_by_class): new function.
* eval.c (set_method_visibility): should have clear cache forq * eval.c (set_method_visibility): should have clear cache for
updated visibility. updated visibility.
Mon May 13 14:38:33 2002 WATANABE Hirofumi <eban@ruby-lang.org> Mon May 13 14:38:33 2002 WATANABE Hirofumi <eban@ruby-lang.org>

221
array.c
View File

@ -62,14 +62,14 @@ rb_ary_modify(ary)
VALUE *ptr; VALUE *ptr;
rb_ary_modify_check(ary); rb_ary_modify_check(ary);
if (!FL_TEST(ary, ELTS_SHARED)) return; if (FL_TEST(ary, ELTS_SHARED)) {
ptr = ALLOC_N(VALUE, RARRAY(ary)->len); ptr = ALLOC_N(VALUE, RARRAY(ary)->len);
FL_UNSET(ary, ELTS_SHARED); FL_UNSET(ary, ELTS_SHARED);
RARRAY(ary)->aux.capa = RARRAY(ary)->len; RARRAY(ary)->aux.capa = RARRAY(ary)->len;
MEMCPY(ptr, RARRAY(ary)->ptr, VALUE, RARRAY(ary)->len); MEMCPY(ptr, RARRAY(ary)->ptr, VALUE, RARRAY(ary)->len);
RARRAY(ary)->ptr = ptr; RARRAY(ary)->ptr = ptr;
}
} }
VALUE VALUE
rb_ary_freeze(ary) rb_ary_freeze(ary)
VALUE ary; VALUE ary;
@ -110,7 +110,7 @@ ary_new(klass, len)
if (len < 0) { if (len < 0) {
rb_raise(rb_eArgError, "negative array size (or size too big)"); rb_raise(rb_eArgError, "negative array size (or size too big)");
} }
if (len > 0 && len*sizeof(VALUE) <= 0) { if (len > 0 && len * sizeof(VALUE) <= 0) {
rb_raise(rb_eArgError, "array size too big"); rb_raise(rb_eArgError, "array size too big");
} }
if (len == 0) len++; if (len == 0) len++;
@ -155,10 +155,7 @@ rb_ary_new3(n, va_alist)
VALUE ary; VALUE ary;
long i; long i;
if (n < 0) { ary = rb_ary_new2(n);
rb_raise(rb_eIndexError, "negative number of items(%d)", n);
}
ary = rb_ary_new2(n<ARY_DEFAULT_SIZE?ARY_DEFAULT_SIZE:n);
va_init_list(ar, n); va_init_list(ar, n);
for (i=0; i<n; i++) { for (i=0; i<n; i++) {
@ -239,12 +236,12 @@ rb_ary_initialize(argc, argv, ary)
if (len < 0) { if (len < 0) {
rb_raise(rb_eArgError, "negative array size"); rb_raise(rb_eArgError, "negative array size");
} }
if (len > 0 && len*sizeof(VALUE) <= 0) { if (len > 0 && len * sizeof(VALUE) <= 0) {
rb_raise(rb_eArgError, "array size too big"); rb_raise(rb_eArgError, "array size too big");
} }
if (len > RARRAY(ary)->aux.capa) { if (len > RARRAY(ary)->aux.capa) {
RARRAY(ary)->aux.capa = len; RARRAY(ary)->aux.capa = len;
REALLOC_N(RARRAY(ary)->ptr, VALUE, RARRAY(ary)->aux.capa); REALLOC_N(RARRAY(ary)->ptr, VALUE, len);
} }
if (rb_block_given_p()) { if (rb_block_given_p()) {
long i; long i;
@ -254,7 +251,7 @@ rb_ary_initialize(argc, argv, ary)
} }
for (i=0; i<len; i++) { for (i=0; i<len; i++) {
RARRAY(ary)->ptr[i] = rb_yield(INT2NUM(i)); RARRAY(ary)->ptr[i] = rb_yield(INT2NUM(i));
RARRAY(ary)->len = i+1; RARRAY(ary)->len = i + 1;
} }
} }
else { else {
@ -273,7 +270,10 @@ rb_ary_s_create(argc, argv, klass)
{ {
VALUE ary = rb_obj_alloc(klass); VALUE ary = rb_obj_alloc(klass);
if (argc != 0) { if (argc < 0) {
rb_raise(rb_eArgError, "negative number of arguments");
}
if (argc > 0) {
RARRAY(ary)->ptr = ALLOC_N(VALUE, argc); RARRAY(ary)->ptr = ALLOC_N(VALUE, argc);
MEMCPY(RARRAY(ary)->ptr, argv, VALUE, argc); MEMCPY(RARRAY(ary)->ptr, argv, VALUE, argc);
} }
@ -307,7 +307,7 @@ rb_ary_store(ary, idx, val)
} }
if (idx > RARRAY(ary)->len) { if (idx > RARRAY(ary)->len) {
rb_mem_clear(RARRAY(ary)->ptr+RARRAY(ary)->len, rb_mem_clear(RARRAY(ary)->ptr+RARRAY(ary)->len,
idx-RARRAY(ary)->len+1); idx-RARRAY(ary)->len + 1);
} }
if (idx >= RARRAY(ary)->len) { if (idx >= RARRAY(ary)->len) {
@ -331,14 +331,12 @@ rb_ary_push_m(argc, argv, ary)
VALUE *argv; VALUE *argv;
VALUE ary; VALUE ary;
{ {
if (argc == 0) { if (argc <= 0) {
rb_raise(rb_eArgError, "wrong number arguments(at least 1)"); rb_raise(rb_eArgError, "wrong number arguments (at least 1)");
} }
if (argc > 0) {
while (argc--) { while (argc--) {
rb_ary_push(ary, *argv++); rb_ary_push(ary, *argv++);
} }
}
return ary; return ary;
} }
@ -349,7 +347,7 @@ rb_ary_pop(ary)
rb_ary_modify_check(ary); rb_ary_modify_check(ary);
if (RARRAY(ary)->len == 0) return Qnil; if (RARRAY(ary)->len == 0) return Qnil;
if (!FL_TEST(ary, ELTS_SHARED) && if (!FL_TEST(ary, ELTS_SHARED) &&
RARRAY(ary)->len * 10 < RARRAY(ary)->aux.capa && RARRAY(ary)->len * 2 < RARRAY(ary)->aux.capa &&
RARRAY(ary)->aux.capa > ARY_DEFAULT_SIZE) { RARRAY(ary)->aux.capa > ARY_DEFAULT_SIZE) {
RARRAY(ary)->aux.capa = RARRAY(ary)->len * 2; RARRAY(ary)->aux.capa = RARRAY(ary)->len * 2;
REALLOC_N(RARRAY(ary)->ptr, VALUE, RARRAY(ary)->aux.capa); REALLOC_N(RARRAY(ary)->ptr, VALUE, RARRAY(ary)->aux.capa);
@ -361,8 +359,7 @@ static void
ary_make_shared(ary) ary_make_shared(ary)
VALUE ary; VALUE ary;
{ {
if (FL_TEST(ary, ELTS_SHARED)) return; if (!FL_TEST(ary, ELTS_SHARED)) {
else {
NEWOBJ(shared, struct RArray); NEWOBJ(shared, struct RArray);
OBJSETUP(shared, rb_cArray, T_ARRAY); OBJSETUP(shared, rb_cArray, T_ARRAY);
@ -400,12 +397,12 @@ rb_ary_unshift(ary, item)
if (capa_inc < ARY_DEFAULT_SIZE) { if (capa_inc < ARY_DEFAULT_SIZE) {
capa_inc = ARY_DEFAULT_SIZE; capa_inc = ARY_DEFAULT_SIZE;
} }
RARRAY(ary)->aux.capa+=capa_inc; RARRAY(ary)->aux.capa += capa_inc;
REALLOC_N(RARRAY(ary)->ptr, VALUE, RARRAY(ary)->aux.capa); REALLOC_N(RARRAY(ary)->ptr, VALUE, RARRAY(ary)->aux.capa);
} }
/* sliding items */ /* sliding items */
MEMMOVE(RARRAY(ary)->ptr+1, RARRAY(ary)->ptr, VALUE, RARRAY(ary)->len); MEMMOVE(RARRAY(ary)->ptr + 1, RARRAY(ary)->ptr, VALUE, RARRAY(ary)->len);
RARRAY(ary)->len++; RARRAY(ary)->len++;
RARRAY(ary)->ptr[0] = item; RARRAY(ary)->ptr[0] = item;
@ -419,19 +416,19 @@ rb_ary_unshift_m(argc, argv, ary)
VALUE *argv; VALUE *argv;
VALUE ary; VALUE ary;
{ {
if (argc == 0) {
rb_raise(rb_eArgError, "wrong number of arguments(at least 1)");
}
if (argc > 0) {
long len = RARRAY(ary)->len; long len = RARRAY(ary)->len;
if (argc <= 0) {
rb_raise(rb_eArgError, "wrong number of arguments (at least 1)");
}
/* make rooms by setting the last item */ /* make rooms by setting the last item */
rb_ary_store(ary, len + argc - 1, Qnil); rb_ary_store(ary, len + argc - 1, Qnil);
/* sliding items */ /* sliding items */
MEMMOVE(RARRAY(ary)->ptr + argc, RARRAY(ary)->ptr, VALUE, len); MEMMOVE(RARRAY(ary)->ptr + argc, RARRAY(ary)->ptr, VALUE, len);
MEMCPY(RARRAY(ary)->ptr, argv, VALUE, argc); MEMCPY(RARRAY(ary)->ptr, argv, VALUE, argc);
}
return ary; return ary;
} }
@ -464,16 +461,15 @@ rb_ary_subseq(ary, beg, len)
if (beg + len > RARRAY(ary)->len) { if (beg + len > RARRAY(ary)->len) {
len = RARRAY(ary)->len - beg; len = RARRAY(ary)->len - beg;
} if (len < 0)
if (len < 0) {
len = 0; len = 0;
} }
klass = rb_obj_class(ary); klass = rb_obj_class(ary);
if (len == 0) return ary_new(klass,0); if (len == 0) return ary_new(klass, 0);
ary_make_shared(ary); ary_make_shared(ary);
ary2 = rb_obj_alloc(klass); ary2 = rb_obj_alloc(klass);
RARRAY(ary2)->ptr = RARRAY(ary)->ptr+beg; RARRAY(ary2)->ptr = RARRAY(ary)->ptr + beg;
RARRAY(ary2)->len = len; RARRAY(ary2)->len = len;
RARRAY(ary2)->aux.shared = RARRAY(ary)->aux.shared; RARRAY(ary2)->aux.shared = RARRAY(ary)->aux.shared;
FL_SET(ary2, ELTS_SHARED); FL_SET(ary2, ELTS_SHARED);
@ -506,10 +502,9 @@ rb_ary_aref(argc, argv, ary)
if (FIXNUM_P(arg)) { if (FIXNUM_P(arg)) {
return rb_ary_entry(ary, FIX2LONG(arg)); return rb_ary_entry(ary, FIX2LONG(arg));
} }
else if (TYPE(arg) == T_BIGNUM) { if (TYPE(arg) == T_BIGNUM) {
rb_raise(rb_eIndexError, "index too big"); rb_raise(rb_eIndexError, "index too big");
} }
else {
/* check if idx is Range */ /* check if idx is Range */
switch (rb_range_beg_len(arg, &beg, &len, RARRAY(ary)->len, 0)) { switch (rb_range_beg_len(arg, &beg, &len, RARRAY(ary)->len, 0)) {
case Qfalse: case Qfalse:
@ -519,7 +514,6 @@ rb_ary_aref(argc, argv, ary)
default: default:
return rb_ary_subseq(ary, beg, len); return rb_ary_subseq(ary, beg, len);
} }
}
return rb_ary_entry(ary, NUM2LONG(arg)); return rb_ary_entry(ary, NUM2LONG(arg));
} }
@ -585,7 +579,7 @@ rb_ary_index(ary, val)
for (i=0; i<RARRAY(ary)->len; i++) { for (i=0; i<RARRAY(ary)->len; i++) {
if (rb_equal(RARRAY(ary)->ptr[i], val)) if (rb_equal(RARRAY(ary)->ptr[i], val))
return INT2NUM(i); return LONG2NUM(i);
} }
return Qnil; return Qnil;
} }
@ -648,14 +642,14 @@ rb_ary_update(ary, beg, len, rpl)
rpl = rb_ary_to_ary(rpl); rpl = rb_ary_to_ary(rpl);
rlen = RARRAY(rpl)->len; rlen = RARRAY(rpl)->len;
if (len < 0) rb_raise(rb_eIndexError, "negative length %d", len); if (len < 0) rb_raise(rb_eIndexError, "negative length (%d)", len);
if (beg < 0) { if (beg < 0) {
beg += RARRAY(ary)->len; beg += RARRAY(ary)->len;
}
if (beg < 0) { if (beg < 0) {
beg -= RARRAY(ary)->len; beg -= RARRAY(ary)->len;
rb_raise(rb_eIndexError, "index %d out of array", beg); rb_raise(rb_eIndexError, "index %d out of array", beg);
} }
}
if (beg + len > RARRAY(ary)->len) { if (beg + len > RARRAY(ary)->len) {
len = RARRAY(ary)->len - beg; len = RARRAY(ary)->len - beg;
} }
@ -664,11 +658,11 @@ rb_ary_update(ary, beg, len, rpl)
if (beg >= RARRAY(ary)->len) { if (beg >= RARRAY(ary)->len) {
len = beg + rlen; len = beg + rlen;
if (len >= RARRAY(ary)->aux.capa) { if (len >= RARRAY(ary)->aux.capa) {
RARRAY(ary)->aux.capa=len; RARRAY(ary)->aux.capa = len;
REALLOC_N(RARRAY(ary)->ptr, VALUE, RARRAY(ary)->aux.capa); REALLOC_N(RARRAY(ary)->ptr, VALUE, len);
} }
rb_mem_clear(RARRAY(ary)->ptr+RARRAY(ary)->len, beg-RARRAY(ary)->len); rb_mem_clear(RARRAY(ary)->ptr + RARRAY(ary)->len, beg - RARRAY(ary)->len);
MEMCPY(RARRAY(ary)->ptr+beg, RARRAY(rpl)->ptr, VALUE, rlen); MEMCPY(RARRAY(ary)->ptr + beg, RARRAY(rpl)->ptr, VALUE, rlen);
RARRAY(ary)->len = len; RARRAY(ary)->len = len;
} }
else { else {
@ -681,15 +675,15 @@ rb_ary_update(ary, beg, len, rpl)
alen = RARRAY(ary)->len + rlen - len; alen = RARRAY(ary)->len + rlen - len;
if (alen >= RARRAY(ary)->aux.capa) { if (alen >= RARRAY(ary)->aux.capa) {
RARRAY(ary)->aux.capa = alen; RARRAY(ary)->aux.capa = alen;
REALLOC_N(RARRAY(ary)->ptr, VALUE, RARRAY(ary)->aux.capa); REALLOC_N(RARRAY(ary)->ptr, VALUE, alen);
} }
if (len != rlen) { if (len != rlen) {
MEMMOVE(RARRAY(ary)->ptr+beg+rlen, RARRAY(ary)->ptr+beg+len, MEMMOVE(RARRAY(ary)->ptr + beg + rlen, RARRAY(ary)->ptr + beg + len,
VALUE, RARRAY(ary)->len-(beg+len)); VALUE, RARRAY(ary)->len - (beg + len));
RARRAY(ary)->len = alen; RARRAY(ary)->len = alen;
} }
MEMMOVE(RARRAY(ary)->ptr+beg, RARRAY(rpl)->ptr, VALUE, rlen); MEMMOVE(RARRAY(ary)->ptr + beg, RARRAY(rpl)->ptr, VALUE, rlen);
} }
} }
@ -706,23 +700,23 @@ rb_ary_aset(argc, argv, ary)
return argv[2]; return argv[2];
} }
if (argc != 2) { if (argc != 2) {
rb_raise(rb_eArgError, "wrong number of arguments(%d for 2)", argc); rb_raise(rb_eArgError, "wrong number of arguments (%d for 2)", argc);
} }
if (FIXNUM_P(argv[0])) { if (FIXNUM_P(argv[0])) {
offset = FIX2LONG(argv[0]); offset = FIX2LONG(argv[0]);
goto fixnum; goto fixnum;
} }
else if (rb_range_beg_len(argv[0], &beg, &len, RARRAY(ary)->len, 1)) { if (TYPE(argv[0]) == T_BIGNUM) {
rb_raise(rb_eIndexError, "index too big");
}
if (rb_range_beg_len(argv[0], &beg, &len, RARRAY(ary)->len, 1)) {
/* check if idx is Range */ /* check if idx is Range */
rb_ary_update(ary, beg, len, argv[1]); rb_ary_update(ary, beg, len, argv[1]);
return argv[1]; return argv[1];
} }
if (TYPE(argv[0]) == T_BIGNUM) {
rb_raise(rb_eIndexError, "index too big");
}
offset = NUM2LONG(argv[0]); offset = NUM2LONG(argv[0]);
fixnum: fixnum:
rb_ary_store(ary, offset, argv[1]); rb_ary_store(ary, offset, argv[1]);
return argv[1]; return argv[1];
} }
@ -736,7 +730,7 @@ rb_ary_insert(argc, argv, ary)
long pos; long pos;
if (argc < 2) { if (argc < 2) {
rb_raise(rb_eArgError, "wrong number of arguments(at least 2)"); rb_raise(rb_eArgError, "wrong number of arguments (at least 2)");
} }
pos = NUM2LONG(argv[0]); pos = NUM2LONG(argv[0]);
if (pos == -1) { if (pos == -1) {
@ -746,7 +740,7 @@ rb_ary_insert(argc, argv, ary)
pos++; pos++;
} }
rb_ary_update(ary, pos, 0, rb_ary_new4(argc-1, argv+1)); rb_ary_update(ary, pos, 0, rb_ary_new4(argc - 1, argv + 1));
return ary; return ary;
} }
@ -861,15 +855,13 @@ VALUE
rb_ary_join(ary, sep) rb_ary_join(ary, sep)
VALUE ary, sep; VALUE ary, sep;
{ {
long len, i; long len = 1, i;
int taint = 0; int taint = Qfalse;
VALUE result, tmp; VALUE result, tmp;
if (RARRAY(ary)->len == 0) return rb_str_new(0, 0); if (RARRAY(ary)->len == 0) return rb_str_new(0, 0);
if (OBJ_TAINTED(ary)) taint = 1; if (OBJ_TAINTED(ary) || OBJ_TAINTED(sep)) taint = Qtrue;
if (OBJ_TAINTED(sep)) taint = 1;
len = 1;
for (i=0; i<RARRAY(ary)->len; i++) { for (i=0; i<RARRAY(ary)->len; i++) {
if (TYPE(RARRAY(ary)->ptr[i]) == T_STRING) { if (TYPE(RARRAY(ary)->ptr[i]) == T_STRING) {
len += RSTRING(RARRAY(ary)->ptr[i])->len; len += RSTRING(RARRAY(ary)->ptr[i])->len;
@ -906,7 +898,7 @@ rb_ary_join(ary, sep)
if (i > 0 && !NIL_P(sep)) if (i > 0 && !NIL_P(sep))
rb_str_buf_append(result, sep); rb_str_buf_append(result, sep);
rb_str_buf_append(result, tmp); rb_str_buf_append(result, tmp);
if (OBJ_TAINTED(tmp)) taint = 1; if (OBJ_TAINTED(tmp)) taint = Qtrue;
} }
if (taint) OBJ_TAINT(result); if (taint) OBJ_TAINT(result);
@ -923,6 +915,7 @@ rb_ary_join_m(argc, argv, ary)
rb_scan_args(argc, argv, "01", &sep); rb_scan_args(argc, argv, "01", &sep);
if (NIL_P(sep)) sep = rb_output_fs; if (NIL_P(sep)) sep = rb_output_fs;
return rb_ary_join(ary, sep); return rb_ary_join(ary, sep);
} }
@ -930,12 +923,9 @@ VALUE
rb_ary_to_s(ary) rb_ary_to_s(ary)
VALUE ary; VALUE ary;
{ {
VALUE str, sep;
if (RARRAY(ary)->len == 0) return rb_str_new(0, 0); if (RARRAY(ary)->len == 0) return rb_str_new(0, 0);
sep = rb_output_fs;
str = rb_ary_join(ary, sep); return rb_ary_join(ary, rb_output_fs);
return str;
} }
static ID inspect_key; static ID inspect_key;
@ -972,9 +962,6 @@ rb_protect_inspect(func, obj, arg)
VALUE inspect_tbl; VALUE inspect_tbl;
VALUE id; VALUE id;
if (!inspect_key) {
inspect_key = rb_intern("__inspect_key__");
}
inspect_tbl = rb_thread_local_aref(rb_thread_current(), inspect_key); inspect_tbl = rb_thread_local_aref(rb_thread_current(), inspect_key);
if (NIL_P(inspect_tbl)) { if (NIL_P(inspect_tbl)) {
inspect_tbl = rb_ary_new(); inspect_tbl = rb_ary_new();
@ -998,9 +985,6 @@ rb_inspecting_p(obj)
{ {
VALUE inspect_tbl; VALUE inspect_tbl;
if (!inspect_key) {
inspect_key = rb_intern("__inspect_key__");
}
inspect_tbl = rb_thread_local_aref(rb_thread_current(), inspect_key); inspect_tbl = rb_thread_local_aref(rb_thread_current(), inspect_key);
if (NIL_P(inspect_tbl)) return Qfalse; if (NIL_P(inspect_tbl)) return Qfalse;
return rb_ary_includes(inspect_tbl, rb_obj_id(obj)); return rb_ary_includes(inspect_tbl, rb_obj_id(obj));
@ -1011,13 +995,13 @@ inspect_ary(ary)
VALUE ary; VALUE ary;
{ {
int tainted = OBJ_TAINTED(ary); int tainted = OBJ_TAINTED(ary);
long i = 0; long i;
VALUE s, str; VALUE s, str;
str = rb_str_buf_new2("["); str = rb_str_buf_new2("[");
for (i=0; i<RARRAY(ary)->len; i++) { for (i=0; i<RARRAY(ary)->len; i++) {
s = rb_inspect(RARRAY(ary)->ptr[i]); s = rb_inspect(RARRAY(ary)->ptr[i]);
if (OBJ_TAINTED(s)) tainted = 1; if (OBJ_TAINTED(s)) tainted = Qtrue;
if (i > 0) rb_str_buf_cat2(str, ", "); if (i > 0) rb_str_buf_cat2(str, ", ");
rb_str_buf_append(str, s); rb_str_buf_append(str, s);
} }
@ -1049,8 +1033,8 @@ rb_ary_reverse(ary)
VALUE *p1, *p2; VALUE *p1, *p2;
VALUE tmp; VALUE tmp;
if (RARRAY(ary)->len <= 1) return ary;
rb_ary_modify(ary); rb_ary_modify(ary);
if (RARRAY(ary)->len <= 1) return ary;
p1 = RARRAY(ary)->ptr; p1 = RARRAY(ary)->ptr;
p2 = p1 + RARRAY(ary)->len - 1; /* points last item */ p2 = p1 + RARRAY(ary)->len - 1; /* points last item */
@ -1083,13 +1067,13 @@ int
rb_cmpint(cmp) rb_cmpint(cmp)
VALUE cmp; VALUE cmp;
{ {
if (FIXNUM_P(cmp)) return NUM2LONG(cmp); if (FIXNUM_P(cmp)) return FIX2INT(cmp);
if (TYPE(cmp) == T_BIGNUM) { if (TYPE(cmp) == T_BIGNUM) {
if (RBIGNUM(cmp)->sign) return 1; if (RBIGNUM(cmp)->sign) return 1;
return -1; return -1;
} }
if (rb_funcall(cmp, '>', 1, INT2FIX(0))) return 1; if (RTEST(rb_funcall(cmp, '>', 1, INT2FIX(0)))) return 1;
if (rb_funcall(cmp, '<', 1, INT2FIX(0))) return -1; if (RTEST(rb_funcall(cmp, '<', 1, INT2FIX(0)))) return -1;
return 0; return 0;
} }
@ -1107,10 +1091,10 @@ sort_2(a, b)
{ {
VALUE retval; VALUE retval;
if (FIXNUM_P(*a)) { if (FIXNUM_P(*a) && FIXNUM_P(*b)) {
if (FIXNUM_P(*b)) return *a - *b; return *a - *b;
} }
else if (TYPE(*a) == T_STRING && TYPE(*b) == T_STRING) { if (TYPE(*a) == T_STRING && TYPE(*b) == T_STRING) {
return rb_str_cmp(*a, *b); return rb_str_cmp(*a, *b);
} }
@ -1199,7 +1183,7 @@ rb_ary_select(argc, argv, ary)
if (rb_block_given_p()) { if (rb_block_given_p()) {
if (argc > 0) { if (argc > 0) {
rb_raise(rb_eArgError, "wrong number arguments(%d for 0)", argc); rb_raise(rb_eArgError, "wrong number arguments (%d for 0)", argc);
} }
for (i = 0; i < RARRAY(ary)->len; i++) { for (i = 0; i < RARRAY(ary)->len; i++) {
if (RTEST(rb_yield(RARRAY(ary)->ptr[i]))) { if (RTEST(rb_yield(RARRAY(ary)->ptr[i]))) {
@ -1236,8 +1220,12 @@ rb_ary_delete(ary, item)
} }
return Qnil; return Qnil;
} }
else {
RARRAY(ary)->len = i2; RARRAY(ary)->len = i2;
if (i2 * 2 < RARRAY(ary)->aux.capa &&
RARRAY(ary)->aux.capa > ARY_DEFAULT_SIZE) {
RARRAY(ary)->aux.capa = i2 * 2;
REALLOC_N(RARRAY(ary)->ptr, VALUE, RARRAY(ary)->aux.capa);
} }
return item; return item;
@ -1249,12 +1237,14 @@ rb_ary_delete_at(ary, pos)
long pos; long pos;
{ {
long i, len = RARRAY(ary)->len; long i, len = RARRAY(ary)->len;
VALUE del = Qnil; VALUE del;
rb_ary_modify(ary); rb_ary_modify(ary);
if (pos >= len) return Qnil; if (pos >= len) return Qnil;
if (pos < 0) pos += len; if (pos < 0) {
pos += len;
if (pos < 0) return Qnil; if (pos < 0) return Qnil;
}
del = RARRAY(ary)->ptr[pos]; del = RARRAY(ary)->ptr[pos];
for (i = pos + 1; i < len; i++, pos++) { for (i = pos + 1; i < len; i++, pos++) {
@ -1279,13 +1269,13 @@ rb_ary_slice_bang(argc, argv, ary)
VALUE ary; VALUE ary;
{ {
VALUE arg1, arg2; VALUE arg1, arg2;
long pos, len, i; long pos, len;
rb_ary_modify(ary); rb_ary_modify(ary);
if (rb_scan_args(argc, argv, "11", &arg1, &arg2) == 2) { if (rb_scan_args(argc, argv, "11", &arg1, &arg2) == 2) {
pos = NUM2LONG(arg1); pos = NUM2LONG(arg1);
len = NUM2LONG(arg2); len = NUM2LONG(arg2);
delete_pos_len: delete_pos_len:
if (pos < 0) { if (pos < 0) {
pos = RARRAY(ary)->len + pos; pos = RARRAY(ary)->len + pos;
} }
@ -1298,18 +1288,7 @@ rb_ary_slice_bang(argc, argv, ary)
goto delete_pos_len; goto delete_pos_len;
} }
pos = NUM2LONG(arg1); rb_ary_delete_at(ary, NUM2LONG(arg1));
len = RARRAY(ary)->len;
if (pos >= len) return Qnil;
if (pos < 0) pos += len;
if (pos < 0) return Qnil;
arg2 = RARRAY(ary)->ptr[pos];
for (i = pos + 1; i < len; i++, pos++) {
RARRAY(ary)->ptr[pos] = RARRAY(ary)->ptr[i];
}
RARRAY(ary)->len = pos;
return arg2; return arg2;
} }
@ -1367,7 +1346,7 @@ rb_ary_clear(ary)
{ {
rb_ary_modify(ary); rb_ary_modify(ary);
RARRAY(ary)->len = 0; RARRAY(ary)->len = 0;
if (ARY_DEFAULT_SIZE*3 < RARRAY(ary)->aux.capa) { if (ARY_DEFAULT_SIZE * 2 < RARRAY(ary)->aux.capa) {
RARRAY(ary)->aux.capa = ARY_DEFAULT_SIZE * 2; RARRAY(ary)->aux.capa = ARY_DEFAULT_SIZE * 2;
REALLOC_N(RARRAY(ary)->ptr, VALUE, RARRAY(ary)->aux.capa); REALLOC_N(RARRAY(ary)->ptr, VALUE, RARRAY(ary)->aux.capa);
} }
@ -1404,12 +1383,12 @@ rb_ary_fill(argc, argv, ary)
} }
/* fall through */ /* fall through */
case 3: case 3:
beg = NIL_P(arg1)?0:NUM2LONG(arg1); beg = NIL_P(arg1) ? 0 : NUM2LONG(arg1);
if (beg < 0) { if (beg < 0) {
beg = RARRAY(ary)->len + beg; beg = RARRAY(ary)->len + beg;
if (beg < 0) beg = 0; if (beg < 0) beg = 0;
} }
len = NIL_P(arg2)?RARRAY(ary)->len - beg:NUM2LONG(arg2); len = NIL_P(arg2) ? RARRAY(ary)->len - beg : NUM2LONG(arg2);
break; break;
} }
rb_ary_modify(ary); rb_ary_modify(ary);
@ -1417,19 +1396,19 @@ rb_ary_fill(argc, argv, ary)
if (end > RARRAY(ary)->len) { if (end > RARRAY(ary)->len) {
if (end >= RARRAY(ary)->aux.capa) { if (end >= RARRAY(ary)->aux.capa) {
RARRAY(ary)->aux.capa = end; RARRAY(ary)->aux.capa = end;
REALLOC_N(RARRAY(ary)->ptr, VALUE, RARRAY(ary)->aux.capa); REALLOC_N(RARRAY(ary)->ptr, VALUE, end);
} }
if (beg > RARRAY(ary)->len) { if (beg > RARRAY(ary)->len) {
rb_mem_clear(RARRAY(ary)->ptr+RARRAY(ary)->len,end-RARRAY(ary)->len); rb_mem_clear(RARRAY(ary)->ptr + RARRAY(ary)->len, end - RARRAY(ary)->len);
} }
RARRAY(ary)->len = end; RARRAY(ary)->len = end;
} }
p = RARRAY(ary)->ptr + beg; pend = p + len; p = RARRAY(ary)->ptr + beg;
pend = p + len;
if (block_p) { if (block_p) {
while (p < pend) { while (p < pend) {
*p++ = rb_yield(INT2NUM(beg)); *p++ = rb_yield(INT2NUM(beg++));
beg++;
} }
} }
else { else {
@ -1445,12 +1424,14 @@ rb_ary_plus(x, y)
VALUE x, y; VALUE x, y;
{ {
VALUE z; VALUE z;
long len;
y = to_ary(y); y = to_ary(y);
z = rb_ary_new2(RARRAY(x)->len + RARRAY(y)->len); len = RARRAY(x)->len + RARRAY(y)->len;
z = rb_ary_new2(len);
MEMCPY(RARRAY(z)->ptr, RARRAY(x)->ptr, VALUE, RARRAY(x)->len); MEMCPY(RARRAY(z)->ptr, RARRAY(x)->ptr, VALUE, RARRAY(x)->len);
MEMCPY(RARRAY(z)->ptr+RARRAY(x)->len, RARRAY(y)->ptr, VALUE, RARRAY(y)->len); MEMCPY(RARRAY(z)->ptr + RARRAY(x)->len, RARRAY(y)->ptr, VALUE, RARRAY(y)->len);
RARRAY(z)->len = RARRAY(x)->len + RARRAY(y)->len; RARRAY(z)->len = len;
return z; return z;
} }
@ -1496,16 +1477,17 @@ rb_ary_times(ary, times)
VALUE VALUE
rb_ary_assoc(ary, key) rb_ary_assoc(ary, key)
VALUE ary; VALUE ary, key;
VALUE key;
{ {
VALUE *p, *pend; VALUE *p, *pend;
p = RARRAY(ary)->ptr; pend = p + RARRAY(ary)->len; p = RARRAY(ary)->ptr;
pend = p + RARRAY(ary)->len;
while (p < pend) { while (p < pend) {
if (TYPE(*p) == T_ARRAY if (TYPE(*p) == T_ARRAY &&
&& RARRAY(*p)->len > 0 RARRAY(*p)->len > 0 &&
&& rb_equal(RARRAY(*p)->ptr[0], key)) rb_equal(RARRAY(*p)->ptr[0], key))
return *p; return *p;
p++; p++;
} }
@ -1519,7 +1501,9 @@ rb_ary_rassoc(ary, value)
{ {
VALUE *p, *pend; VALUE *p, *pend;
p = RARRAY(ary)->ptr; pend = p + RARRAY(ary)->len; p = RARRAY(ary)->ptr;
pend = p + RARRAY(ary)->len;
while (p < pend) { while (p < pend) {
if (TYPE(*p) == T_ARRAY if (TYPE(*p) == T_ARRAY
&& RARRAY(*p)->len > 1 && RARRAY(*p)->len > 1
@ -1571,11 +1555,11 @@ rb_ary_hash(ary)
h = RARRAY(ary)->len; h = RARRAY(ary)->len;
for (i=0; i<RARRAY(ary)->len; i++) { for (i=0; i<RARRAY(ary)->len; i++) {
h = (h<<1) | (h<0 ? 1 : 0); h = (h << 1) | (h<0 ? 1 : 0);
n = rb_hash(RARRAY(ary)->ptr[i]); n = rb_hash(RARRAY(ary)->ptr[i]);
h ^= NUM2LONG(n); h ^= NUM2LONG(n);
} }
return INT2FIX(h); return LONG2FIX(h);
} }
VALUE VALUE
@ -1746,6 +1730,7 @@ rb_ary_compact_bang(ary)
rb_ary_modify(ary); rb_ary_modify(ary);
p = t = RARRAY(ary)->ptr; p = t = RARRAY(ary)->ptr;
end = p + RARRAY(ary)->len; end = p + RARRAY(ary)->len;
while (t < end) { while (t < end) {
if (NIL_P(*t)) t++; if (NIL_P(*t)) t++;
else *p++ = *t++; else *p++ = *t++;
@ -1777,6 +1762,7 @@ rb_ary_nitems(ary)
p = RARRAY(ary)->ptr; p = RARRAY(ary)->ptr;
pend = p + RARRAY(ary)->len; pend = p + RARRAY(ary)->len;
while (p < pend) { while (p < pend) {
if (!NIL_P(*p)) n++; if (!NIL_P(*p)) n++;
p++; p++;
@ -1784,7 +1770,7 @@ rb_ary_nitems(ary)
return INT2NUM(n); return INT2NUM(n);
} }
static int static long
flatten(ary, idx, ary2, memo) flatten(ary, idx, ary2, memo)
VALUE ary; VALUE ary;
long idx; long idx;
@ -1934,4 +1920,5 @@ Init_Array()
rb_define_method(rb_cArray, "nitems", rb_ary_nitems, 0); rb_define_method(rb_cArray, "nitems", rb_ary_nitems, 0);
id_cmp = rb_intern("<=>"); id_cmp = rb_intern("<=>");
inspect_key = rb_intern("__inspect_key__");
} }

View File

@ -16,33 +16,15 @@ VALUE rb_mComparable;
static ID cmp; static ID cmp;
static VALUE
cmp_eq(a)
VALUE *a;
{
VALUE c = rb_funcall(a[0], cmp, 1, a[1]);
int t = NUM2INT(c);
if (t == 0) return Qtrue;
return Qfalse;
}
static VALUE
cmp_failed()
{
return Qfalse;
}
static VALUE static VALUE
cmp_equal(x, y) cmp_equal(x, y)
VALUE x, y; VALUE x, y;
{ {
VALUE a[2]; VALUE c = rb_funcall(x, cmp, 1, y);
if (x == y) return Qtrue; if (NIL_P(c)) return Qnil;
if (NUM2LONG(c) == 0) return Qtrue;
a[0] = x; a[1] = y; return Qfalse;
return rb_rescue(cmp_eq, (VALUE)a, cmp_failed, 0);
} }
static VALUE static VALUE
@ -50,9 +32,9 @@ cmp_gt(x, y)
VALUE x, y; VALUE x, y;
{ {
VALUE c = rb_funcall(x, cmp, 1, y); VALUE c = rb_funcall(x, cmp, 1, y);
int t = NUM2INT(c);
if (t > 0) return Qtrue; if (NIL_P(c)) return Qfalse;
if (NUM2LONG(c) > 0) return Qtrue;
return Qfalse; return Qfalse;
} }
@ -61,9 +43,9 @@ cmp_ge(x, y)
VALUE x, y; VALUE x, y;
{ {
VALUE c = rb_funcall(x, cmp, 1, y); VALUE c = rb_funcall(x, cmp, 1, y);
int t = NUM2INT(c);
if (t >= 0) return Qtrue; if (NIL_P(c)) return Qfalse;
if (NUM2LONG(c) >= 0) return Qtrue;
return Qfalse; return Qfalse;
} }
@ -72,9 +54,9 @@ cmp_lt(x, y)
VALUE x, y; VALUE x, y;
{ {
VALUE c = rb_funcall(x, cmp, 1, y); VALUE c = rb_funcall(x, cmp, 1, y);
int t = NUM2INT(c);
if (t < 0) return Qtrue; if (NIL_P(c)) return Qfalse;
if (NUM2LONG(c) < 0) return Qtrue;
return Qfalse; return Qfalse;
} }
@ -83,9 +65,9 @@ cmp_le(x, y)
VALUE x, y; VALUE x, y;
{ {
VALUE c = rb_funcall(x, cmp, 1, y); VALUE c = rb_funcall(x, cmp, 1, y);
int t = NUM2INT(c);
if (t <= 0) return Qtrue; if (NIL_P(c)) return Qfalse;
if (NUM2LONG(c) <= 0) return Qtrue;
return Qfalse; return Qfalse;
} }
@ -94,12 +76,13 @@ cmp_between(x, min, max)
VALUE x, min, max; VALUE x, min, max;
{ {
VALUE c = rb_funcall(x, cmp, 1, min); VALUE c = rb_funcall(x, cmp, 1, min);
long t = NUM2LONG(c);
if (t < 0) return Qfalse; if (NIL_P(c)) return Qfalse;
if (NUM2LONG(c) < 0) return Qfalse;
c = rb_funcall(x, cmp, 1, max); c = rb_funcall(x, cmp, 1, max);
t = NUM2LONG(c); if (NIL_P(c)) return Qfalse;
if (t > 0) return Qfalse; if (NUM2LONG(c) > 0) return Qfalse;
return Qtrue; return Qtrue;
} }

7
eval.c
View File

@ -7813,8 +7813,13 @@ rb_thread_schedule()
n = select(max+1, &readfds, &writefds, &exceptfds, delay_ptr); n = select(max+1, &readfds, &writefds, &exceptfds, delay_ptr);
if (n < 0) { if (n < 0) {
int e = errno;
if (rb_trap_pending) rb_trap_exec(); if (rb_trap_pending) rb_trap_exec();
if (errno == EINTR) goto again; if (e == EINTR) goto again;
#ifdef ERESTART
if (e == ERESTART) goto again;
#endif
FOREACH_THREAD_FROM(curr, th) { FOREACH_THREAD_FROM(curr, th) {
if (th->wait_for & WAIT_SELECT) { if (th->wait_for & WAIT_SELECT) {
int v = 0; int v = 0;

13
hash.c
View File

@ -55,6 +55,19 @@ eql(args)
return (VALUE)rb_eql(args[0], args[1]); return (VALUE)rb_eql(args[0], args[1]);
} }
static VALUE
eql_failed()
{
return Qfalse;
}
static VALUE
any_eql(args)
VALUE *args;
{
return rb_rescue(eql, (VALUE)args, eql_failed, 0);
}
static int static int
rb_any_cmp(a, b) rb_any_cmp(a, b)
VALUE a, b; VALUE a, b;

View File

@ -604,8 +604,7 @@ rb_mod_cmp(mod, arg)
return INT2FIX(1); return INT2FIX(1);
arg = RCLASS(arg)->super; arg = RCLASS(arg)->super;
} }
rb_raise(rb_eArgError, "non related class/module"); return Qnil;
return Qnil; /* not reached */
} }
static VALUE static VALUE
@ -1308,6 +1307,7 @@ Init_Object()
rb_define_method(rb_cSymbol, "intern", sym_intern, 0); rb_define_method(rb_cSymbol, "intern", sym_intern, 0);
rb_define_method(rb_cModule, "===", rb_mod_eqq, 1); rb_define_method(rb_cModule, "===", rb_mod_eqq, 1);
rb_define_method(rb_cModule, "==", rb_obj_equal, 1);
rb_define_method(rb_cModule, "<=>", rb_mod_cmp, 1); rb_define_method(rb_cModule, "<=>", rb_mod_cmp, 1);
rb_define_method(rb_cModule, "<", rb_mod_lt, 1); rb_define_method(rb_cModule, "<", rb_mod_lt, 1);
rb_define_method(rb_cModule, "<=", rb_mod_le, 1); rb_define_method(rb_cModule, "<=", rb_mod_le, 1);

26
pack.c
View File

@ -406,6 +406,7 @@ pack_pack(ary, fmt)
StringValue(from); StringValue(from);
ptr = RSTRING(from)->ptr; ptr = RSTRING(from)->ptr;
plen = RSTRING(from)->len; plen = RSTRING(from)->len;
OBJ_INFECT(res, from);
} }
if (p[-1] == '*') if (p[-1] == '*')
@ -1052,6 +1053,18 @@ hex2num(c)
#define PACK_ITEM_ADJUST() while (tmp--) rb_ary_push(ary, Qnil) #define PACK_ITEM_ADJUST() while (tmp--) rb_ary_push(ary, Qnil)
static VALUE
infected_str_new(ptr, len, str)
const char *ptr;
long len;
VALUE str;
{
VALUE s = rb_str_new(ptr, len);
OBJ_INFECT(s, str);
return s;
}
static VALUE static VALUE
pack_unpack(str, fmt) pack_unpack(str, fmt)
VALUE str, fmt; VALUE str, fmt;
@ -1130,7 +1143,7 @@ pack_unpack(str, fmt)
if (*t != ' ' && *t != '\0') break; if (*t != ' ' && *t != '\0') break;
t--; len--; t--; len--;
} }
rb_ary_push(ary, rb_str_new(s, len)); rb_ary_push(ary, infected_str_new(s, len, str));
s += end; s += end;
} }
break; break;
@ -1145,14 +1158,14 @@ pack_unpack(str, fmt)
if (*t) break; if (*t) break;
t--; len--; t--; len--;
} }
rb_ary_push(ary, rb_str_new(s, len)); rb_ary_push(ary, infected_str_new(s, len, str));
s += end; s += end;
} }
break; break;
case 'a': case 'a':
if (len > send - s) len = send - s; if (len > send - s) len = send - s;
rb_ary_push(ary, rb_str_new(s, len)); rb_ary_push(ary, infected_str_new(s, len, str));
s += len; s += len;
break; break;
@ -1478,7 +1491,7 @@ pack_unpack(str, fmt)
case 'u': case 'u':
{ {
VALUE str = rb_str_new(0, (send - s)*3/4); VALUE str = infected_str_new(0, (send - s)*3/4, str);
char *ptr = RSTRING(str)->ptr; char *ptr = RSTRING(str)->ptr;
int total = 0; int total = 0;
@ -1534,7 +1547,7 @@ pack_unpack(str, fmt)
case 'm': case 'm':
{ {
VALUE str = rb_str_new(0, (send - s)*3/4); VALUE str = infected_str_new(0, (send - s)*3/4, str);
char *ptr = RSTRING(str)->ptr; char *ptr = RSTRING(str)->ptr;
int a,b,c,d; int a,b,c,d;
static int first = 1; static int first = 1;
@ -1577,7 +1590,7 @@ pack_unpack(str, fmt)
case 'M': case 'M':
{ {
VALUE str = rb_str_new(0, send - s); VALUE str = infected_str_new(0, send - s, str);
char *ptr = RSTRING(str)->ptr; char *ptr = RSTRING(str)->ptr;
int c1, c2; int c1, c2;
@ -1686,6 +1699,7 @@ pack_unpack(str, fmt)
rb_raise(rb_eArgError, "non associated pointer"); rb_raise(rb_eArgError, "non associated pointer");
} }
tmp = rb_str_new2(t); tmp = rb_str_new2(t);
OBJ_INFECT(tmp, str);
} }
else { else {
tmp = Qnil; tmp = Qnil;

View File

@ -1050,7 +1050,7 @@ calculate_must_string(start, end)
p += mcnt; p += mcnt;
mcnt = EXTRACT_UNSIGNED_AND_INCR(p); mcnt = EXTRACT_UNSIGNED_AND_INCR(p);
while (mcnt--) { while (mcnt--) {
p += 4; p += 8;
} }
break; break;

View File

@ -1,4 +1,4 @@
#define RUBY_VERSION "1.7.2" #define RUBY_VERSION "1.7.2"
#define RUBY_RELEASE_DATE "2002-05-20" #define RUBY_RELEASE_DATE "2002-05-21"
#define RUBY_VERSION_CODE 172 #define RUBY_VERSION_CODE 172
#define RUBY_RELEASE_CODE 20020520 #define RUBY_RELEASE_CODE 20020521