[前][次][番号順一覧][スレッド一覧]

ruby-changes:54446

From: nobu <ko1@a...>
Date: Mon, 31 Dec 2018 10:14:56 +0900 (JST)
Subject: [ruby-changes:54446] nobu:r66661 (trunk): load.c: resolve_feature_path

nobu	2018-12-31 10:14:51 +0900 (Mon, 31 Dec 2018)

  New Revision: 66661

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=66661

  Log:
    load.c: resolve_feature_path
    
    * load.c (rb_resolve_feature_path): search the path for already
      loaded feature.

  Modified files:
    trunk/load.c
    trunk/test/ruby/test_require.rb
Index: test/ruby/test_require.rb
===================================================================
--- test/ruby/test_require.rb	(revision 66660)
+++ test/ruby/test_require.rb	(revision 66661)
@@ -897,4 +897,24 @@ class TestRequire < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_require.rb#L897
       assert_operator(result, :end_with?, "/real/a.rb")
     }
   end
+
+  if defined?(RubyVM.resolve_feature_path)
+    def test_resolve_feature_path
+      paths, loaded = $:.dup, $".dup
+      Dir.mktmpdir do |tmp|
+        Tempfile.create(%w[feature .rb], tmp) do |file|
+          file.close
+          path = File.realpath(file.path)
+          dir, base = File.split(path)
+          $:.unshift(dir)
+          assert_equal([:rb, path], RubyVM.resolve_feature_path(base))
+          $".push(path)
+          assert_equal([:rb, path], RubyVM.resolve_feature_path(base))
+        end
+      end
+    ensure
+      $:.replace(paths)
+      $".replace(loaded)
+    end
+  end
 end
Index: load.c
===================================================================
--- load.c	(revision 66660)
+++ load.c	(revision 66661)
@@ -840,8 +840,10 @@ rb_f_require_relative(VALUE obj, VALUE f https://github.com/ruby/ruby/blob/trunk/load.c#L840
     return rb_require_safe(rb_file_absolute_path(fname, base), rb_safe_level());
 }
 
+typedef int (*feature_func)(const char *feature, const char *ext, int rb, int expanded, const char **fn);
+
 static int
-search_required(VALUE fname, volatile VALUE *path, int safe_level)
+search_required(VALUE fname, volatile VALUE *path, int safe_level, feature_func rb_feature_p)
 {
     VALUE tmp;
     char *ext, *ftptr;
@@ -945,6 +947,12 @@ load_ext(VALUE path) https://github.com/ruby/ruby/blob/trunk/load.c#L947
 
 /* Method is documented in vm.c */
 
+static int
+no_feature_p(const char *feature, const char *ext, int rb, int expanded, const char **fn)
+{
+    return 0;
+}
+
 VALUE
 rb_resolve_feature_path(VALUE klass, VALUE fname)
 {
@@ -954,7 +962,7 @@ rb_resolve_feature_path(VALUE klass, VAL https://github.com/ruby/ruby/blob/trunk/load.c#L962
 
     fname = rb_get_path_check(fname, 0);
     path = rb_str_encode_ospath(fname);
-    found = search_required(path, &path, 0);
+    found = search_required(path, &path, 0, no_feature_p);
 
     switch (found) {
       case 'r':
@@ -1003,7 +1011,7 @@ rb_require_internal(VALUE fname, int saf https://github.com/ruby/ruby/blob/trunk/load.c#L1011
 	rb_set_safe_level_force(0);
 
 	RUBY_DTRACE_HOOK(FIND_REQUIRE_ENTRY, RSTRING_PTR(fname));
-	found = search_required(path, &path, safe);
+	found = search_required(path, &path, safe, rb_feature_p);
 	RUBY_DTRACE_HOOK(FIND_REQUIRE_RETURN, RSTRING_PTR(fname));
 
 	if (found) {

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]