summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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 2db64f938f..bc27765f61 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 e166712ed0..d361bd57d7 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 17e8e5221d..9ca2fa0a54 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 2034c0a7ff..4a2d736465 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 6694e2f8fa..69e99f60b0 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 3fa5bca484..830228eed6 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 8b5a97c404..9dd9d9bc4d 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 90f86f46c9..655d2f077e 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");