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

Piotr Niełacny Urabe, Shyouhei Zachary Scott Nobuyoshi Nakada
Piotr Niełacny
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 
Urabe, Shyouhei
Owner

Can you also modify necessary files so that make passes?

Piotr Niełacny
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'?

Piotr Niełacny LTe 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
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

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

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

Piotr Niełacny
LTe added a note

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

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

Piotr Niełacny
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?

Nobuyoshi Nakada Collaborator
nobu added a note

yes, but fname.

Piotr Niełacny
LTe added a note

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 5, 2012
  1. Piotr Niełacny

    Allow to use require_relative from eval and irb environment

    LTe authored
    Ruby also can recognize path through current thread control frame
  2. Piotr Niełacny
Commits on Jul 6, 2012
  1. Piotr Niełacny
  2. Piotr Niełacny
This page is out of date. Refresh to see the latest.
Showing with 2 additions and 1 deletion.
  1. +2 −1  load.c
3  load.c
View
@@ -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.