summaryrefslogtreecommitdiff
path: root/variable.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-03-15 07:15:26 (GMT)
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-03-15 07:15:26 (GMT)
commit4691daccc156f290ca09effdd2558cd6dd0cec70 (patch)
tree3635e3e5e8e89c6ab9b5fc9d15d5b621dfe115b3 /variable.c
parent06af2865decb62b467db4f25b5fba9089cd299a4 (diff)
variable.c: hoisted out overtaken cvar warnings
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62756 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'variable.c')
-rw-r--r--variable.c43
1 files changed, 19 insertions, 24 deletions
diff --git a/variable.c b/variable.c
index 4572d5a..46911bf 100644
--- a/variable.c
+++ b/variable.c
@@ -2856,6 +2856,23 @@ cvar_front_klass(VALUE klass)
return RCLASS_SUPER(klass);
}
+static void
+cvar_overtaken(VALUE front, VALUE target, ID id)
+{
+ if (front && target != front) {
+ st_data_t did = (st_data_t)id;
+
+ if (RTEST(ruby_verbose)) {
+ rb_warning("class variable % "PRIsVALUE" of %"PRIsVALUE" is overtaken by %"PRIsVALUE"",
+ ID2SYM(id), rb_class_name(original_module(front)),
+ rb_class_name(original_module(target)));
+ }
+ if (BUILTIN_TYPE(front) == T_CLASS) {
+ st_delete(RCLASS_IV_TBL(front), &did, 0);
+ }
+ }
+}
+
#define CVAR_FOREACH_ANCESTORS(klass, v, r) \
for (klass = cvar_front_klass(klass); klass; klass = RCLASS_SUPER(klass)) { \
if (cvar_lookup_at(klass, id, (v))) { \
@@ -2876,18 +2893,7 @@ rb_cvar_set(VALUE klass, ID id, VALUE val)
tmp = klass;
CVAR_LOOKUP(0, {if (!front) front = klass; target = klass;});
if (target) {
- if (front && target != front) {
- st_data_t did = id;
-
- if (RTEST(ruby_verbose)) {
- rb_warning("class variable %"PRIsVALUE" of %"PRIsVALUE" is overtaken by %"PRIsVALUE"",
- QUOTE_ID(id), rb_class_name(original_module(front)),
- rb_class_name(original_module(target)));
- }
- if (BUILTIN_TYPE(front) == T_CLASS) {
- st_delete(RCLASS_IV_TBL(front),&did,0);
- }
- }
+ cvar_overtaken(front, target, id);
}
else {
target = tmp;
@@ -2913,18 +2919,7 @@ rb_cvar_get(VALUE klass, ID id)
rb_name_err_raise("uninitialized class variable %1$s in %2$s",
tmp, ID2SYM(id));
}
- if (front && target != front) {
- st_data_t did = id;
-
- if (RTEST(ruby_verbose)) {
- rb_warning("class variable %"PRIsVALUE" of %"PRIsVALUE" is overtaken by %"PRIsVALUE"",
- QUOTE_ID(id), rb_class_name(original_module(front)),
- rb_class_name(original_module(target)));
- }
- if (BUILTIN_TYPE(front) == T_CLASS) {
- st_delete(RCLASS_IV_TBL(front),&did,0);
- }
- }
+ cvar_overtaken(front, target, id);
return (VALUE)value;
}