summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-11-09 08:14:42 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-11-09 08:14:42 +0000
commit70f70f7dfef89b145f74e44ad0777328caac3388 (patch)
tree0595a158b75dbd2e8b1b059d012b79cbdfc06d1b
parent1c4e2b11a1f5fc00d727809225d089b7990ed979 (diff)
* variable.c (rb_cvar_set): cvar assignment obey same rule to cvar
reference. [ruby-dev:32192] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13854 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog3
-rw-r--r--variable.c62
2 files changed, 30 insertions, 35 deletions
diff --git a/ChangeLog b/ChangeLog
index f27b805ff8..0730a04d60 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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 a0f68f2073..5106c8af41 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)
{