summaryrefslogtreecommitdiff
path: root/variable.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2001-08-20 04:29:58 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2001-08-20 04:29:58 +0000
commitc7868668121470b56f173a596b750e8a27fe9e18 (patch)
tree96b130e912efefc888dd4f84dc35ca5de9077776 /variable.c
parent772ed5507e569d7697841492a37d7607adbc9385 (diff)
* range.c (range_step): 'iter' here should be an array.
* marshal.c (w_object): should retrieve __member__ data from non-singleton class. * variable.c (rb_cvar_get): class variable override check added. * variable.c (rb_cvar_set): ditto * variable.c (rb_cvar_declare): ditto. * parse.y (parse_regx): handle backslash escaping of delimiter here. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1703 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'variable.c')
-rw-r--r--variable.c31
1 files changed, 29 insertions, 2 deletions
diff --git a/variable.c b/variable.c
index 8090efd76c..eab951d102 100644
--- a/variable.c
+++ b/variable.c
@@ -1376,6 +1376,22 @@ rb_cvar_singleton(obj)
return CLASS_OF(obj);
}
+static void
+cvar_override_check(id, a, b)
+ VALUE a, b;
+{
+ a = RCLASS(a)->super;
+ while (a) {
+ if (!RCLASS(a)->iv_tbl) continue;
+ if (st_lookup(RCLASS(a)->iv_tbl,id,0)) {
+ rb_warning("class variable %s of %s is overridden by %s",
+ rb_id2name(id), rb_class2name(a),
+ rb_class2name(b));
+ }
+ a = RCLASS(a)->super;
+ }
+}
+
void
rb_cvar_set(klass, id, val)
VALUE klass;
@@ -1386,10 +1402,14 @@ rb_cvar_set(klass, id, val)
tmp = klass;
while (tmp) {
- if (RCLASS(tmp)->iv_tbl && st_lookup(RCLASS(tmp)->iv_tbl,id,0)) {
+ if (!RCLASS(tmp)->iv_tbl) continue;
+ if (st_lookup(RCLASS(tmp)->iv_tbl,id,0)) {
if (!OBJ_TAINTED(tmp) && rb_safe_level() >= 4)
rb_raise(rb_eSecurityError, "Insecure: can't modify class variable");
st_insert(RCLASS(tmp)->iv_tbl,id,val);
+ if (ruby_verbose) {
+ cvar_override_check(id, tmp, klass);
+ }
return;
}
tmp = RCLASS(tmp)->super;
@@ -1416,6 +1436,9 @@ rb_cvar_declare(klass, id, val)
rb_warning("already initialized class variable %s", rb_id2name(id));
}
st_insert(RCLASS(tmp)->iv_tbl,id,val);
+ if (ruby_verbose) {
+ cvar_override_check(id, tmp, klass);
+ }
return;
}
tmp = RCLASS(tmp)->super;
@@ -1434,7 +1457,11 @@ rb_cvar_get(klass, id)
tmp = klass;
while (tmp) {
- if (RCLASS(tmp)->iv_tbl && st_lookup(RCLASS(tmp)->iv_tbl,id,&value)) {
+ if (!RCLASS(tmp)->iv_tbl) continue;
+ if (st_lookup(RCLASS(tmp)->iv_tbl,id,&value)) {
+ if (ruby_verbose) {
+ cvar_override_check(id, tmp, klass);
+ }
return value;
}
tmp = RCLASS(tmp)->super;