summaryrefslogtreecommitdiff
path: root/variable.c
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2021-06-23 09:39:04 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2021-06-23 10:55:22 +0900
commit0700ee0e946ff278699eb9aa068e7abbc3700dda (patch)
tree519e8ebc7faec3728dcadcf65b03ed8e4977789e /variable.c
parent46ff44ef17cc6ed48f4c5657b26ee8c8c7cab9c8 (diff)
Refactor class variable cache functions
Extracted repeated code as update_classvariable_cache. When cvc table is not set in getclassvariable, an empty table was created but it has no id and would cause [BUG], so made the code same as setclassvariable.
Diffstat (limited to 'variable.c')
-rw-r--r--variable.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/variable.c b/variable.c
index 778778c866..a2f485a9d4 100644
--- a/variable.c
+++ b/variable.c
@@ -3407,14 +3407,17 @@ rb_cvar_set(VALUE klass, ID id, VALUE val)
}
struct rb_cvar_class_tbl_entry *ent;
+ VALUE ent_data;
- if (!rb_id_table_lookup(rb_cvc_tbl, id, (VALUE*)&ent)) {
+ if (!rb_id_table_lookup(rb_cvc_tbl, id, &ent_data)) {
ent = ALLOC(struct rb_cvar_class_tbl_entry);
ent->class_value = target;
ent->global_cvar_state = GET_GLOBAL_CVAR_STATE();
rb_id_table_insert(rb_cvc_tbl, id, (VALUE)ent);
RB_DEBUG_COUNTER_INC(cvar_inline_miss);
- } else {
+ }
+ else {
+ ent = (void *)ent_data;
ent->global_cvar_state = GET_GLOBAL_CVAR_STATE();
}