summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakashi Kokubun <takashikkbn@gmail.com>2025-10-07 09:41:15 -0700
committerTakashi Kokubun <takashikkbn@gmail.com>2025-10-07 09:41:15 -0700
commitef3ce711fb29f7273216edb2fe41bb2604c835c3 (patch)
treec2c3c6be30bffc12c31d26d942210eb04ff06bbc
parenta7eb7e7c6fe02f7127ff527fff18a0914a7aa888 (diff)
merge revision(s) 7ae67e8f6ad6e7fd0677b28a7a10961f79d55495: [Backport #21568]
[PATCH] load.c: Fix dest and src of MEMMOVE When multiple files with the same name are required, the features_index hash stores the indexes in `$LOADED_FEATURES` array into a darray. The dest and src arguments for `MEMMOVE` were wrongly reversed when inserting a new index in the darray. [Bug #21568]
-rw-r--r--load.c2
-rw-r--r--test/ruby/test_require.rb14
-rw-r--r--version.h2
3 files changed, 16 insertions, 2 deletions
diff --git a/load.c b/load.c
index 8b6de1c8b0..d346fc4377 100644
--- a/load.c
+++ b/load.c
@@ -284,7 +284,7 @@ features_index_add_single_callback(st_data_t *key, st_data_t *value, st_data_t r
if (pos >= 0) {
long *ptr = rb_darray_data_ptr(feature_indexes);
long len = rb_darray_size(feature_indexes);
- MEMMOVE(ptr + pos, ptr + pos + 1, long, len - pos - 1);
+ MEMMOVE(ptr + pos + 1, ptr + pos, long, len - pos - 1);
ptr[pos] = FIX2LONG(offset);
}
}
diff --git a/test/ruby/test_require.rb b/test/ruby/test_require.rb
index f8578b4a90..d108e08118 100644
--- a/test/ruby/test_require.rb
+++ b/test/ruby/test_require.rb
@@ -1035,4 +1035,18 @@ class TestRequire < Test::Unit::TestCase
end
RUBY
end
+
+ def test_bug_21568
+ load_path = $LOAD_PATH.dup
+ loaded_featrures = $LOADED_FEATURES.dup
+
+ $LOAD_PATH.clear
+ $LOADED_FEATURES.replace(["foo.so", "a/foo.rb", "b/foo.rb"])
+
+ assert_nothing_raised(LoadError) { require "foo" }
+
+ ensure
+ $LOAD_PATH.replace(load_path) if load_path
+ $LOADED_FEATURES.replace loaded_featrures
+ end
end
diff --git a/version.h b/version.h
index c8fcf77fbd..1941abbc87 100644
--- a/version.h
+++ b/version.h
@@ -11,7 +11,7 @@
# define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR
#define RUBY_VERSION_TEENY 6
#define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR
-#define RUBY_PATCHLEVEL 57
+#define RUBY_PATCHLEVEL 58
#include "ruby/version.h"
#include "ruby/internal/abi.h"