ruby-changes:54017
From: mame <ko1@a...>
Date: Thu, 6 Dec 2018 15:40:59 +0900 (JST)
Subject: [ruby-changes:54017] mame:r66237 (trunk): load.c (RubyVM.resolve_feature_path): New method. [Feature #15230]
mame 2018-12-06 15:40:54 +0900 (Thu, 06 Dec 2018) New Revision: 66237 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=66237 Log: load.c (RubyVM.resolve_feature_path): New method. [Feature #15230] Modified files: trunk/NEWS trunk/load.c trunk/vm.c Index: NEWS =================================================================== --- NEWS (revision 66236) +++ NEWS (revision 66237) @@ -266,6 +266,13 @@ sufficient information, see the ChangeLo https://github.com/ruby/ruby/blob/trunk/NEWS#L266 * Range#step now returns an instance of Enumerator::ArithmeticSequence class rather than one of Enumerator class. +[RubyVM] + + [New methods] + + * RubyVM.resolve_feature_path identifies the file that will be loaded by + "require(feature)". [experimental] [Feature #15230] + [RubyVM::AbstractSyntaxTree] [New methods] Index: vm.c =================================================================== --- vm.c (revision 66236) +++ vm.c (revision 66237) @@ -2869,6 +2869,8 @@ static VALUE usage_analysis_operand_stop https://github.com/ruby/ruby/blob/trunk/vm.c#L2869 static VALUE usage_analysis_register_stop(VALUE self); #endif +VALUE rb_resolve_feature_path(VALUE klass, VALUE fname); + void Init_VM(void) { @@ -3171,6 +3173,8 @@ Init_VM(void) https://github.com/ruby/ruby/blob/trunk/vm.c#L3173 /* vm_backtrace.c */ Init_vm_backtrace(); + + rb_define_singleton_method(rb_cRubyVM, "resolve_feature_path", rb_resolve_feature_path, 1); } void Index: load.c =================================================================== --- load.c (revision 66236) +++ load.c (revision 66237) @@ -943,6 +943,42 @@ load_ext(VALUE path) https://github.com/ruby/ruby/blob/trunk/load.c#L943 } /* + * 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) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/