* eval.c (avalue_to_svalue): use rb_check_array_type() again.
Clarify how "to_ary" and "to_a" work. [ruby-talk:68155] * eval.c (svalue_to_avalue): ditto. * eval.c (svalue_to_mrhs): ditto. * eval.c (rb_eval): unary splat to use to_a, but we need a hack to exclude Object#to_a until it's removed. * object.c (rb_Array): check obj.respond_to?("to_a"). Currently all object respond_to "to_a", but Object#to_a will be removed. * range.c (Init_Range): undefine to_ary. * re.c (Init_Regexp): ditto. * regex.c (re_compile_pattern): do not warn if "-" is at the top or last of character class. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3633 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
95785964f6
commit
fec60bc7c4
24
ChangeLog
24
ChangeLog
@ -1,3 +1,22 @@
|
||||
Sat Mar 29 09:48:35 2003 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||
|
||||
* eval.c (avalue_to_svalue): use rb_check_array_type() again.
|
||||
Clarify how "to_ary" and "to_a" work. [ruby-talk:68155]
|
||||
|
||||
* eval.c (svalue_to_avalue): ditto.
|
||||
|
||||
* eval.c (svalue_to_mrhs): ditto.
|
||||
|
||||
* eval.c (rb_eval): unary splat to use to_a, but we need a hack to
|
||||
exclude Object#to_a until it's removed.
|
||||
|
||||
* object.c (rb_Array): check obj.respond_to?("to_a"). Currently
|
||||
all object respond_to "to_a", but Object#to_a will be removed.
|
||||
|
||||
* range.c (Init_Range): undefine to_ary.
|
||||
|
||||
* re.c (Init_Regexp): ditto.
|
||||
|
||||
Sat Mar 29 09:47:52 2003 Nobuyoshi Nakada <nobu.nokada@softhome.net>
|
||||
|
||||
* MANIFEST (ext/aix_mksym.rb): remove obsolete file.
|
||||
@ -10,6 +29,11 @@ Fri Mar 28 19:33:39 2003 Nobuyoshi Nakada <nobu.nokada@softhome.net>
|
||||
* variable.c (classname): remove temporary class path when exact
|
||||
name found.
|
||||
|
||||
Fri Mar 28 18:29:23 2003 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||
|
||||
* regex.c (re_compile_pattern): do not warn if "-" is at the top
|
||||
or last of character class.
|
||||
|
||||
Thu Mar 27 12:10:15 2003 Tanaka Akira <akr@m17n.org>
|
||||
|
||||
* regex.c (re_compile_pattern): fix [:name:] handling.
|
||||
|
72
eval.c
72
eval.c
@ -2201,42 +2201,47 @@ static VALUE
|
||||
avalue_to_svalue(v)
|
||||
VALUE v;
|
||||
{
|
||||
if (TYPE(v) != T_ARRAY) {
|
||||
VALUE tmp, top;
|
||||
|
||||
tmp = rb_check_array_type(v);
|
||||
if (NIL_P(v)) {
|
||||
return v;
|
||||
}
|
||||
if (RARRAY(v)->len == 0) {
|
||||
if (RARRAY(tmp)->len == 0) {
|
||||
return Qundef;
|
||||
}
|
||||
if (RARRAY(v)->len == 1) {
|
||||
VALUE tmp = RARRAY(v)->ptr[0];
|
||||
if (TYPE(tmp) != T_ARRAY) {
|
||||
return tmp;
|
||||
if (RARRAY(tmp)->len == 1) {
|
||||
top = rb_check_array_type(RARRAY(tmp)->ptr[0]);
|
||||
if (NIL_P(top)) {
|
||||
return RARRAY(tmp)->ptr[0];
|
||||
}
|
||||
if (RARRAY(tmp)->len > 1) {
|
||||
if (RARRAY(top)->len > 1) {
|
||||
return v;
|
||||
}
|
||||
return tmp;
|
||||
return top;
|
||||
}
|
||||
return v;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
svalue_to_avalue(v)
|
||||
VALUE v;
|
||||
{
|
||||
VALUE tmp;
|
||||
VALUE tmp, top;
|
||||
|
||||
if (v == Qundef) return rb_ary_new2(0);
|
||||
if (TYPE(v) != T_ARRAY) {
|
||||
tmp = rb_check_array_type(v);
|
||||
if (NIL_P(tmp)) {
|
||||
return rb_ary_new3(1, v);
|
||||
}
|
||||
if (RARRAY(v)->len == 1) {
|
||||
tmp = RARRAY(v)->ptr[0];
|
||||
if (TYPE(tmp) == T_ARRAY && RARRAY(tmp)->len > 1)
|
||||
if (RARRAY(tmp)->len == 1) {
|
||||
top = rb_check_array_type(RARRAY(tmp)->ptr[0]);
|
||||
if (!NIL_P(top) && RARRAY(top)->len > 1) {
|
||||
return v;
|
||||
}
|
||||
return rb_ary_new3(1, v);
|
||||
}
|
||||
return v;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
@ -2257,15 +2262,18 @@ svalue_to_mrhs(v, lhs)
|
||||
VALUE v;
|
||||
NODE *lhs;
|
||||
{
|
||||
VALUE tmp;
|
||||
|
||||
if (v == Qundef) return rb_ary_new2(0);
|
||||
if (TYPE(v) != T_ARRAY) {
|
||||
tmp = rb_check_array_type(v);
|
||||
if (NIL_P(tmp)) {
|
||||
return rb_ary_new3(1, v);
|
||||
}
|
||||
/* no lhs means splat lhs only */
|
||||
if (!lhs && RARRAY(v)->len <= 1) {
|
||||
if (!lhs && RARRAY(tmp)->len <= 1) {
|
||||
return rb_ary_new3(1, v);
|
||||
}
|
||||
return v;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
@ -2652,15 +2660,31 @@ rb_eval(self, n)
|
||||
break;
|
||||
|
||||
case NODE_SPLAT:
|
||||
{
|
||||
VALUE tmp;
|
||||
#if 0
|
||||
/* simplified version after Object#to_a removed */
|
||||
result = rb_eval(self, node->nd_head);
|
||||
if (NIL_P(result)) result = rb_ary_new3(1, Qnil);
|
||||
result = avalue_splat(rb_Array(result));
|
||||
#else
|
||||
result = rb_eval(self, node->nd_head);
|
||||
if (NIL_P(result)) result = rb_ary_new3(1, Qnil);
|
||||
if (TYPE(result) != T_ARRAY) {
|
||||
VALUE tmp = rb_check_array_type(result);
|
||||
if (NIL_P(tmp)) {
|
||||
VALUE origin;
|
||||
ID id = rb_intern("to_a");
|
||||
|
||||
result = rb_eval(self, node->nd_head);
|
||||
tmp = rb_check_array_type(result);
|
||||
if (!NIL_P(tmp)) {
|
||||
result = avalue_splat(tmp);
|
||||
if (search_method(CLASS_OF(result), id, &origin) &&
|
||||
origin != RCLASS(rb_cObject)->super) { /* exclude Object#to_a */
|
||||
result = rb_funcall(result, id, 0);
|
||||
}
|
||||
else {
|
||||
result = rb_ary_new3(1, result);
|
||||
}
|
||||
}
|
||||
}
|
||||
result = avalue_splat(rb_Array(result));
|
||||
#endif
|
||||
break;
|
||||
|
||||
case NODE_SVALUE:
|
||||
|
@ -138,7 +138,7 @@ rb_dlhandle_sym(int argc, VALUE argv[], VALUE self)
|
||||
const char *name, *stype;
|
||||
const char *err;
|
||||
|
||||
rb_secure(4);
|
||||
rb_secure(2);
|
||||
if (rb_scan_args(argc, argv, "11", &sym, &type) == 2) {
|
||||
SafeStringValue(type);
|
||||
stype = StringValuePtr(type);
|
||||
@ -159,9 +159,8 @@ rb_dlhandle_sym(int argc, VALUE argv[], VALUE self)
|
||||
name = StringValuePtr(sym);
|
||||
}
|
||||
|
||||
|
||||
Data_Get_Struct(self, struct dl_handle, dlhandle);
|
||||
if (! dlhandle->open) {
|
||||
if (!dlhandle->open) {
|
||||
rb_raise(rb_eRuntimeError, "Closed handle.");
|
||||
}
|
||||
handle = dlhandle->ptr;
|
||||
|
@ -330,7 +330,7 @@ rb_dlsym_call(int argc, VALUE argv[], VALUE self)
|
||||
long ftype;
|
||||
void *func;
|
||||
|
||||
rb_secure(2);
|
||||
rb_secure_update(self);
|
||||
Data_Get_Struct(self, struct sym_data, sym);
|
||||
DEBUG_CODE({
|
||||
printf("rb_dlsym_call(): type = '%s', func = 0x%x\n", sym->type, sym->func);
|
||||
|
10
object.c
10
object.c
@ -1270,10 +1270,16 @@ rb_Array(val)
|
||||
val = rb_funcall(val, to_ary, 0);
|
||||
}
|
||||
else {
|
||||
val = rb_funcall(val, rb_intern("to_a"), 0);
|
||||
to_ary = rb_intern("to_a");
|
||||
if (rb_respond_to(val, to_ary)) {
|
||||
val = rb_funcall(val, to_ary, 0);
|
||||
}
|
||||
else {
|
||||
val = rb_ary_new3(1, val);
|
||||
}
|
||||
}
|
||||
if (TYPE(val) != T_ARRAY) {
|
||||
rb_raise(rb_eTypeError, "`to_a' did not return Array");
|
||||
rb_raise(rb_eTypeError, "`%s' did not return Array", rb_id2name(to_ary));
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
1
range.c
1
range.c
@ -497,7 +497,6 @@ Init_Range()
|
||||
rb_define_method(rb_cRange, "end", range_last, 0);
|
||||
rb_define_method(rb_cRange, "to_s", range_to_s, 0);
|
||||
rb_define_method(rb_cRange, "inspect", range_inspect, 0);
|
||||
rb_define_alias(rb_cRange, "to_ary", "to_a");
|
||||
|
||||
rb_define_method(rb_cRange, "exclude_end?", range_exclude_end_p, 0);
|
||||
|
||||
|
1
re.c
1
re.c
@ -1713,7 +1713,6 @@ Init_Regexp()
|
||||
rb_define_method(rb_cMatch, "begin", match_begin, 1);
|
||||
rb_define_method(rb_cMatch, "end", match_end, 1);
|
||||
rb_define_method(rb_cMatch, "to_a", match_to_a, 0);
|
||||
rb_define_method(rb_cMatch, "to_ary", match_to_a, 0);
|
||||
rb_define_method(rb_cMatch, "[]", match_aref, -1);
|
||||
rb_define_method(rb_cMatch, "select", match_select, -1);
|
||||
rb_define_method(rb_cMatch, "pre_match", rb_reg_match_pre, 0);
|
||||
|
Loading…
x
Reference in New Issue
Block a user