Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Allow to use require_relative from eval and irb environment #139

Closed
wants to merge 4 commits into from

4 participants

@LTe
LTe commented

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 
@shyouhei
Owner

Can you also modify necessary files so that make passes?

@LTe
LTe commented

Can you also modify necessary files so that make passes?

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

@LTe LTe Allow to use require_relative from eval and irb environment
Ruby also can recognize path through current thread control frame
d2b02da
@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.

@LTe
LTe commented
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]
@nobu
Collaborator

no needs to call realpath here

Removed

@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 {
{
VALUE base = rb_current_realfilepath();
if (NIL_P(base)) {
- rb_loaderror("cannot infer basepath");
+ VALUE path = rb_find_file(FilePathValue(fname));
@nobu Collaborator
nobu added a note

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

@LTe
LTe added a note

Updated, thanks for feedback :)

@nobu Collaborator
nobu added a note

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

@LTe
LTe added a note

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

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

This is ok?

@nobu Collaborator
nobu added a note

yes, but fname.

@LTe
LTe added a note

Sure, updated

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

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

@shyouhei Could you please review the ticket in redmine?

Thank you!

@zzak zzak closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 5, 2012
  1. @LTe

    Allow to use require_relative from eval and irb environment

    LTe authored
    Ruby also can recognize path through current thread control frame
  2. @LTe
Commits on Jul 6, 2012
  1. @LTe
  2. @LTe
This page is out of date. Refresh to see the latest.
Showing with 2 additions and 1 deletion.
  1. +2 −1  load.c
View
3  load.c
@@ -497,7 +497,8 @@ rb_f_require_relative(VALUE obj, VALUE fname)
{
VALUE base = rb_current_realfilepath();
if (NIL_P(base)) {
- rb_loaderror("cannot infer basepath");
+ if(!NIL_P(fname))
+ return rb_require_safe(fname, rb_safe_level());
}
base = rb_file_dirname(base);
return rb_require_safe(rb_file_absolute_path(fname, base), rb_safe_level());
Something went wrong with that request. Please try again.