1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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
This commit is contained in:
matz 2007-11-09 08:14:42 +00:00
parent 1c4e2b11a1
commit 70f70f7dfe
2 changed files with 30 additions and 35 deletions

View file

@ -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

View file

@ -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)
{