Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions load.c
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,11 @@ get_loaded_features_index(vm_ns_t *vm_ns)
VALUE previous_realpath_map = rb_hash_dup(realpath_map);
rb_hash_clear(realpaths);
rb_hash_clear(realpath_map);

/* We have to make a copy of features here because the StringValue call
* below could call a Ruby method, which could modify $LOADED_FEATURES
* and cause it to be corrupt. */
features = rb_ary_resurrect(features);
for (i = 0; i < RARRAY_LEN(features); i++) {
VALUE entry, as_str;
as_str = entry = rb_ary_entry(features, i);
Expand All @@ -456,6 +461,10 @@ get_loaded_features_index(vm_ns_t *vm_ns)
rb_ary_store(features, i, as_str);
features_index_add(vm_ns, as_str, INT2FIX(i));
}
/* The user modified $LOADED_FEATURES, so we should restore the changes. */
if (!rb_ary_shared_with_p(features, CURRENT_NS_LOADED_FEATURES(vm_ns))) {
rb_ary_replace(CURRENT_NS_LOADED_FEATURES(vm_ns), features);
}
reset_loaded_features_snapshot(vm_ns);

features = CURRENT_NS_LOADED_FEATURES_SNAPSHOT(vm_ns);
Expand Down
Loading