diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 1998-04-08 08:12:39 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 1998-04-08 08:12:39 +0000 |
commit | 8673eacafa039f056927e0f91ce195afae9b9019 (patch) | |
tree | ad28cdccaa2ee114d3cf523de4d9f9d0167b2d50 | |
parent | 9c855a83f2c34ecf0e2f448d2213a6b091cdce95 (diff) |
local_variables/defined?(TOPLEVEL_CONST) in modules
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/v1_1r@159 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 8 | ||||
-rw-r--r-- | eval.c | 4 | ||||
-rw-r--r-- | lib/delegate.rb | 2 | ||||
-rw-r--r-- | numeric.c | 6 | ||||
-rw-r--r-- | object.c | 7 | ||||
-rw-r--r-- | re.c | 6 | ||||
-rw-r--r-- | string.c | 1 | ||||
-rw-r--r-- | variable.c | 11 |
8 files changed, 34 insertions, 11 deletions
@@ -1,3 +1,11 @@ +Wed Apr 8 00:59:13 1998 Yukihiro Matsumoto <matz@netlab.co.jp> + + * variable.c (rb_const_defined): returned false even if the + constant is defined at the top level. + + * eval.c (f_local_variables): dyna_var->id may be null. should + have checked before calling str_new2(). + Tue Apr 7 18:50:16 1998 Yukihiro Matsumoto <matz@netlab.co.jp> * experimental release 1.1b9_08. @@ -4462,7 +4462,9 @@ f_local_variables() vars = the_dyna_vars; while (vars) { - ary_push(ary, str_new2(rb_id2name(vars->id))); + if (vars->id) { + ary_push(ary, str_new2(rb_id2name(vars->id))); + } vars = vars->next; } diff --git a/lib/delegate.rb b/lib/delegate.rb index a544773983..a4bbe0615c 100644 --- a/lib/delegate.rb +++ b/lib/delegate.rb @@ -47,7 +47,7 @@ class SimpleDelegator<Delegator end end -# backword compatibility ^_^;;; +# backward compatibility ^_^;;; Delegater = Delegator SimpleDelegater = SimpleDelegator @@ -52,6 +52,8 @@ coerce_rescue(x) VALUE *x; { TypeError("%s can't be coerced into %s", + rb_special_const_p(x[1])? + STR2CSTR(rb_inspect(x[1])): rb_class2name(CLASS_OF(x[1])), rb_class2name(CLASS_OF(x[0]))); } @@ -643,6 +645,10 @@ num2int(val) TypeError("no implicit conversion from string"); return Qnil; /* not reached */ + case T_NIL: + TypeError("no implicit conversion from nil"); + return Qnil; /* not reached */ + default: val = rb_rescue(to_integer, val, fail_to_integer, val); if (!obj_is_kind_of(val, cInteger)) { @@ -289,6 +289,7 @@ nil_plus(x, y) VALUE x, y; { switch (TYPE(y)) { + case T_NIL: case T_FIXNUM: case T_FLOAT: case T_BIGNUM: @@ -297,7 +298,8 @@ nil_plus(x, y) return y; default: TypeError("tried to add %s(%s) to nil", - RSTRING(obj_as_string(y))->ptr, rb_class2name(CLASS_OF(y))); + STR2CSTR(rb_inspect(y)), + rb_class2name(CLASS_OF(y))); } /* not reached */ } @@ -722,6 +724,9 @@ f_integer(obj, arg) case T_STRING: return str2inum(RSTRING(arg)->ptr, 0); + case T_NIL: + return INT2FIX(0); + default: i = NUM2INT(arg); } @@ -883,7 +883,7 @@ reg_regsub(str, src, regs) char *ss = s; c = *s++; - if (c != '\\') continue; + if (c != '\\' || s == e) continue; if (!val) val = str_new(p, ss-p); else str_cat(val, p, ss-p); @@ -913,10 +913,6 @@ reg_regsub(str, src, regs) if (no == 0) continue; break; - case '\\': - str_cat(val, s-1, 1); - continue; - default: str_cat(val, s-2, 2); continue; @@ -429,6 +429,7 @@ str_concat(str1, str2) #if 0 str2 = obj_as_string(str2); #else + if (NIL_P(str2)) return str1; Check_Type(str2, T_STRING); #endif str_cat(str1, RSTRING(str2)->ptr, RSTRING(str2)->len); diff --git a/variable.c b/variable.c index 24e66a6b56..ef4b49e60d 100644 --- a/variable.c +++ b/variable.c @@ -967,11 +967,16 @@ rb_const_defined(klass, id) VALUE klass; ID id; { - while (klass) { - if (RCLASS(klass)->iv_tbl && st_lookup(RCLASS(klass)->iv_tbl, id, 0)) { + VALUE tmp = klass; + + while (tmp) { + if (RCLASS(tmp)->iv_tbl && st_lookup(RCLASS(tmp)->iv_tbl,id,0)) { return TRUE; } - klass = RCLASS(klass)->super; + tmp = RCLASS(tmp)->super; + } + if (BUILTIN_TYPE(klass) == T_MODULE) { + return rb_const_defined(cObject, id); } if (st_lookup(class_tbl, id, 0)) return TRUE; |