aboutsummaryrefslogtreecommitdiffstats
path: root/variable.c
diff options
context:
space:
mode:
Diffstat (limited to 'variable.c')
-rw-r--r--variable.c27
1 files changed, 19 insertions, 8 deletions
diff --git a/variable.c b/variable.c
index 42c4cb7cd4..3146168924 100644
--- a/variable.c
+++ b/variable.c
@@ -1802,8 +1802,10 @@ struct autoload_const {
VALUE mod;
VALUE ad; /* autoload_data_i */
VALUE value;
+ VALUE file;
ID id;
rb_const_flag_t flag;
+ int line;
};
/* always on stack, no need to mark */
@@ -1872,6 +1874,7 @@ autoload_c_compact(void *ptr)
ac->mod = rb_gc_location(ac->mod);
ac->ad = rb_gc_location(ac->ad);
ac->value = rb_gc_location(ac->value);
+ ac->file = rb_gc_location(ac->file);
}
static void
@@ -1882,6 +1885,7 @@ autoload_c_mark(void *ptr)
rb_gc_mark_movable(ac->mod);
rb_gc_mark_movable(ac->ad);
rb_gc_mark_movable(ac->value);
+ rb_gc_mark_movable(ac->file);
}
static void
@@ -2768,11 +2772,11 @@ rb_const_set(VALUE klass, ID id, VALUE val)
setup_const_entry(ce, klass, val, CONST_PUBLIC);
}
else {
- struct autoload_const ac;
- ac.mod = klass;
- ac.id = id;
- ac.value = val;
- ac.flag = CONST_PUBLIC;
+ struct autoload_const ac = {
+ .mod = klass, .id = id,
+ .value = val, .flag = CONST_PUBLIC,
+ /* fill the rest with 0 */
+ };
const_tbl_update(&ac);
}
/*
@@ -2837,10 +2841,17 @@ const_tbl_update(struct autoload_const *ac)
rb_clear_constant_cache();
ac->value = val; /* autoload_i is non-WB-protected */
- return;
+ ac->file = rb_source_location(&ac->line);
}
- /* otherwise, allow to override */
- autoload_delete(klass, id);
+ else {
+ /* otherwise autoloaded constant, allow to override */
+ autoload_delete(klass, id);
+ ce->flag = visibility;
+ RB_OBJ_WRITE(klass, &ce->value, val);
+ RB_OBJ_WRITE(klass, &ce->file, ac->file);
+ ce->line = ac->line;
+ }
+ return;
}
else {
VALUE name = QUOTE_ID(id);