Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Allow to use require_relative from eval and irb environment #139

Closed
wants to merge 4 commits into from

4 participants

Piotr Niełacny Urabe, Shyouhei Zachary Scott Nobuyoshi Nakada
Piotr Niełacny
LTe commented July 05, 2012

Before patch

1.9.3p125 :001 > require_relative "file"
LoadError: cannot infer basepath
    from (irb):1:in `require_relative'
    from (irb):1
    from /home/lite/.rvm/rubies/ruby-1.9.3-p125-perf/bin/irb:16:in `<main>'

After patch

1.9.3p125 :001 > require_relative "file"
 => true 
Urabe, Shyouhei
Owner

Can you also modify necessary files so that make passes?

Piotr Niełacny
LTe commented July 05, 2012

Can you also modify necessary files so that make passes?

For me make runs without problems. What do you mean by 'necessary files'?

Piotr Niełacny Allow to use require_relative from eval and irb environment
Ruby also can recognize path through current thread control frame
d2b02da
Urabe, Shyouhei
Owner

For me make runs without problems. What do you mean by 'necessary files'?

I suspect that's because you're using a preexisting build directory. Create another folder elsewhere and start from cloning your repo into it.

Piotr Niełacny
LTe commented July 05, 2012
lite@LTE-RB ~> git clone git@github.com:LTe/ruby.git
Cloning into 'ruby'...
remote: Counting objects: 229291, done.
remote: Compressing objects: 100% (45946/45946), done.
remote: Total 229291 (delta 182177), reused 227095 (delta 181540)
Receiving objects: 100% (229291/229291), 77.43 MiB | 2.90 MiB/s, done.
Resolving deltas: 100% (182177/182177), done.

lite@LTE-RB ~> cd ruby/
(trunk=85bb4) lite@LTE-RB ~/ruby> git checkout require_relative 
Branch require_relative set up to track remote branch require_relative from origin.
Switched to a new branch 'require_relative'
(require_relative=d2b02) lite@LTE-RB ~/ruby> autoconf
(require_relative=d2b02) lite@LTE-RB ~/ruby> ./configure
*** stuff ***
config.status: creating Makefile
config.status: creating ruby-2.0.pc
(require_relative=d2b02) lite@LTE-RB ~/ruby> make -j3
*** stuff ***
done without error
(require_relative=d2b02) lite@LTE-RB ~/ruby> sudo make install
(require_relative=d2b02) lite@LTE-RB ~/ruby> /usr/local/bin/ruby -v
ruby 2.0.0dev (2012-07-05 trunk 36321) [x86_64-linux]
Nobuyoshi Nakada
Collaborator

no needs to call realpath here

LTe replied July 05, 2012

Removed

Urabe, Shyouhei
Owner

OK so when I checked your repo at first (was LTe@99392d9), it broke the compilation. But now (LTe@f58d7c6) it compiles cleanly.

load.c
@@ -497,7 +497,10 @@ struct loaded_feature_searching {
497 497
 {
498 498
     VALUE base = rb_current_realfilepath();
499 499
     if (NIL_P(base)) {
500  
-	rb_loaderror("cannot infer basepath");
  500
+      VALUE path = rb_find_file(FilePathValue(fname));
2
Nobuyoshi Nakada Collaborator
nobu added a note July 06, 2012

also rb_find_file() is not needed, since rb_require_safe() calls it.

Piotr Niełacny
LTe added a note July 06, 2012

Updated, thanks for feedback :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
load.c
@@ -497,7 +497,10 @@ struct loaded_feature_searching {
497 497
 {
498 498
     VALUE base = rb_current_realfilepath();
499 499
     if (NIL_P(base)) {
500  
-	rb_loaderror("cannot infer basepath");
  500
+      VALUE path = FilePathValue(fname);
4
Nobuyoshi Nakada Collaborator
nobu added a note July 06, 2012

sorry to be unclear, ditto for FilePathValue(), and, of course, succeeding if statement.

Piotr Niełacny
LTe added a note July 06, 2012

@nobu so we don't need FilePathValue(fname) to?

if(!NIL_P(fname))
  return rb_require_safe(fname, rb_safe_level());

This is ok?

Nobuyoshi Nakada Collaborator
nobu added a note July 06, 2012

yes, but fname.

Piotr Niełacny
LTe added a note July 06, 2012

Sure, updated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Zachary Scott
Collaborator

I'm closing this, please refer to Bug #7391 in redmine

@shyouhei Could you please review the ticket in redmine?

Thank you!

Zachary Scott zzak closed this November 18, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 2 additions and 1 deletion. Show diff stats Hide diff stats

  1. 3  load.c
3  load.c
@@ -497,7 +497,8 @@ rb_f_require_relative(VALUE obj, VALUE fname)
497 497
 {
498 498
     VALUE base = rb_current_realfilepath();
499 499
     if (NIL_P(base)) {
500  
-	rb_loaderror("cannot infer basepath");
  500
+      if(!NIL_P(fname))
  501
+        return rb_require_safe(fname, rb_safe_level());
501 502
     }
502 503
     base = rb_file_dirname(base);
503 504
     return rb_require_safe(rb_file_absolute_path(fname, base), rb_safe_level());
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.