aboutsummaryrefslogtreecommitdiffstats
path: root/load.c
diff options
context:
space:
mode:
authormame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-12-06 06:40:54 +0000
committermame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-12-06 06:40:54 +0000
commit0cd28199e50039e9425f10b880c436d3ecacde0b (patch)
tree167cd97193185476d018e9f26ae512813dbc76e7 /load.c
parent98ff2bbd7a9d033a629644a4576e5293eea3dc53 (diff)
downloadruby-0cd28199e50039e9425f10b880c436d3ecacde0b.tar.gz
load.c (RubyVM.resolve_feature_path): New method. [Feature #15230]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66237 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'load.c')
-rw-r--r--load.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/load.c b/load.c
index ddde2baf3b..46367358ca 100644
--- a/load.c
+++ b/load.c
@@ -943,6 +943,42 @@ load_ext(VALUE path)
}
/*
+ * call-seq:
+ * RubyVM.resolve_feature_path(feature) -> [:rb or :so, path]
+ *
+ * Identifies the file that will be loaded by "require(feature)".
+ * This API is experimental and just for internal.
+ *
+ * RubyVM.resolve_feature_path("set")
+ * #=> [:rb, "/path/to/feature.rb"]
+ */
+
+VALUE
+rb_resolve_feature_path(VALUE klass, VALUE fname)
+{
+ VALUE path;
+ int found;
+ VALUE sym;
+
+ fname = rb_get_path_check(fname, 0);
+ path = rb_str_encode_ospath(fname);
+ found = search_required(path, &path, 0);
+
+ switch (found) {
+ case 'r':
+ sym = ID2SYM(rb_intern("rb"));
+ break;
+ case 's':
+ sym = ID2SYM(rb_intern("so"));
+ break;
+ default:
+ load_failed(fname);
+ }
+
+ return rb_ary_new_from_args(2, sym, path);
+}
+
+/*
* returns
* 0: if already loaded (false)
* 1: successfully loaded (true)