diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-11-09 08:14:42 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-11-09 08:14:42 +0000 |
commit | 854426a86f3674e283af3779e3ef1787d0646370 (patch) | |
tree | 0595a158b75dbd2e8b1b059d012b79cbdfc06d1b | |
parent | f5a74b2322b06dee8e85c25733f86de17426218e (diff) | |
download | ruby-854426a86f3674e283af3779e3ef1787d0646370.tar.gz ruby-854426a86f3674e283af3779e3ef1787d0646370.tar.xz ruby-854426a86f3674e283af3779e3ef1787d0646370.zip |
* variable.c (rb_cvar_set): cvar assignment obey same rule to cvar
reference. [ruby-dev:32192]
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@13854 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 3 | ||||
-rw-r--r-- | variable.c | 62 |
2 files changed, 30 insertions, 35 deletions
@@ -3,6 +3,9 @@ Fri Nov 9 16:51:42 2007 Yukihiro Matsumoto <matz@ruby-lang.org> * io.c (rb_io_each_byte): should update rbuf_off and rbuf_len for each iteration. [ruby-dev:31659][ruby-dev:32192] + * variable.c (rb_cvar_set): cvar assignment obey same rule to cvar + reference. [ruby-dev:32192] + Fri Nov 9 15:52:00 2007 Nobuyoshi Nakada <nobu@ruby-lang.org> * encoding.c (enc_check_encoding, rb_set_primary_encoding): ENCODING diff --git a/variable.c b/variable.c index a0f68f207..5106c8af4 100644 --- a/variable.c +++ b/variable.c @@ -1710,41 +1710,6 @@ original_module(c) return c; } -void -rb_cvar_set(VALUE klass, ID id, VALUE val) -{ - VALUE tmp; - VALUE front = 0, target = 0; - - tmp = klass; - while (tmp) { - if (RCLASS_IV_TBL(tmp) && st_lookup(RCLASS_IV_TBL(tmp),id,0)) { - if (!front) front = tmp; - target = tmp; - } - tmp = RCLASS_SUPER(tmp); - } - if (target) { - if (front && target != front) { - ID did = id; - - if (RTEST(ruby_verbose)) { - rb_warning("class variable %s of %s is overtaken by %s", - rb_id2name(id), rb_class2name(original_module(front)), - rb_class2name(original_module(target))); - } - if (BUILTIN_TYPE(front) == T_CLASS) { - st_delete(RCLASS_IV_TBL(front),&did,0); - } - } - } - else { - target = klass; - } - - mod_av_set(target, id, val, Qfalse); -} - #define CVAR_LOOKUP(v,r) do {\ if (RCLASS_IV_TBL(klass) && st_lookup(RCLASS_IV_TBL(klass),id,(v))) {\ r;\ @@ -1772,6 +1737,33 @@ rb_cvar_set(VALUE klass, ID id, VALUE val) }\ } while(0) +void +rb_cvar_set(VALUE klass, ID id, VALUE val) +{ + VALUE tmp, front = 0, target = 0; + + tmp = klass; + CVAR_LOOKUP(0, {if (!front) front = klass; target = klass;}); + if (target) { + if (front && target != front) { + ID did = id; + + if (RTEST(ruby_verbose)) { + rb_warning("class variable %s of %s is overtaken by %s", + rb_id2name(id), rb_class2name(original_module(front)), + rb_class2name(original_module(target))); + } + if (BUILTIN_TYPE(front) == T_CLASS) { + st_delete(RCLASS_IV_TBL(front),&did,0); + } + } + } + else { + target = tmp; + } + mod_av_set(target, id, val, Qfalse); +} + VALUE rb_cvar_get(VALUE klass, ID id) { |