summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-03-29 02:56:18 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-03-29 02:56:18 +0000
commitfec60bc7c4f851d0cf1c4670ef8f2d9c597b7598 (patch)
treefe375a324a27f43bd07a192814a516ee99557656
parent95785964f693e4af9b93513dce3960ebc5aab452 (diff)
* 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
-rw-r--r--ChangeLog24
-rw-r--r--eval.c74
-rw-r--r--ext/dl/handle.c5
-rw-r--r--ext/dl/sym.c2
-rw-r--r--object.c10
-rw-r--r--range.c1
-rw-r--r--re.c1
-rw-r--r--regex.c2
8 files changed, 85 insertions, 34 deletions
diff --git a/ChangeLog b/ChangeLog
index 2db64f938f4..bc27765f612 100644
--- a/ChangeLog
+++ b/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.
diff --git a/eval.c b/eval.c
index e166712ed06..d361bd57d70 100644
--- a/eval.c
+++ b/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;
-
- result = rb_eval(self, node->nd_head);
- tmp = rb_check_array_type(result);
- if (!NIL_P(tmp)) {
- result = avalue_splat(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");
+
+ 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:
diff --git a/ext/dl/handle.c b/ext/dl/handle.c
index 17e8e5221d0..9ca2fa0a542 100644
--- a/ext/dl/handle.c
+++ b/ext/dl/handle.c
@@ -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;
diff --git a/ext/dl/sym.c b/ext/dl/sym.c
index 2034c0a7ff2..4a2d736465e 100644
--- a/ext/dl/sym.c
+++ b/ext/dl/sym.c
@@ -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);
diff --git a/object.c b/object.c
index 6694e2f8fa7..69e99f60b0c 100644
--- a/object.c
+++ b/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;
}
diff --git a/range.c b/range.c
index 3fa5bca484e..830228eed6e 100644
--- a/range.c
+++ b/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);
diff --git a/re.c b/re.c
index 8b5a97c4041..9dd9d9bc4d5 100644
--- a/re.c
+++ b/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);
diff --git a/regex.c b/regex.c
index 90f86f46c94..655d2f077e8 100644
--- a/regex.c
+++ b/regex.c
@@ -1487,7 +1487,7 @@ re_compile_pattern(pattern, size, bufp)
}
had_char_class = 0;
- if (c == '-')
+ if (c == '-' && p != p0 + 1 && *p != ']')
re_warning("character class has `-' without escape");
if (c == '[' && *p != ':')
re_warning("character class has `[' without escape");