summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog3
-rw-r--r--variable.c62
2 files changed, 30 insertions, 35 deletions
diff --git a/ChangeLog b/ChangeLog
index f27b805ff..0730a04d6 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 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)
{