[jira] Created: (JRUBY-4218) jruby loads src/builtin/generator.rb ahead of any other file named generator

View: New views
4 Messages — Rating Filter:   Alert me  

[jira] Created: (JRUBY-4218) jruby loads src/builtin/generator.rb ahead of any other file named generator

by JIRA jira@codehaus.org :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

jruby loads src/builtin/generator.rb  ahead of any other file named generator
-----------------------------------------------------------------------------

                 Key: JRUBY-4218
                 URL: http://jira.codehaus.org/browse/JRUBY-4218
             Project: JRuby
          Issue Type: Bug
          Components: Core Classes/Modules
    Affects Versions: JRuby 1.5
         Environment: jruby 1.5.0.dev (ruby 1.8.7 patchlevel 174) (2009-11-05 6586) (Java HotSpot(TM) Client VM 1.6.0_14) [i386-java]

On Kubuntu 8.04.
            Reporter: James Britt


Example; 2 files, in the same directory.


#------- generator.rb -----------
warn "#{__FILE__} is loaded"

class MyGen
  def foo
    __FILE__
  end
end
#--------------------------------------

#--------------- test.rb -------------------
here = File.expand_path(File.dirname(__FILE__))
$:.unshift here
require 'generator.rb'

begin
  p MyGen.new.foo
rescue
  warn $!
end
#--------------------------------------


Line 2 in test.rb forces the current directory to the head of the load path, so
local files should be found and loaded first.

Execute test.rb using MRI (for example)

$ ruby test.rb
/home/james/tmp/jruby-require-bug/generator.rb is loaded
"/home/james/tmp/jruby-require-bug/generator.rb"
$

Try with jruby:

$ ruby jtest.rb
uninitialized constant MyGen

JRuby is loading sr/builtin/generator.rb despite the values in $:

(You can check this by adding a puts statement to that file to indicate when it gets loaded.)







--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

       

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



Re: [jira] Created: (JRUBY-4218) jruby loads src/builtin/generator.rb ahead of any other file named generator

by Hirotsugu Asari :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I haven't read too much into the issue, so correct me if I'm wrong.

As I understand it, by the time org.jruby.Ruby.parseFile() is called  
on test.rb, an org.jruby.Ruby.init() has already been called and  
builtins has already been loaded. By the same token, "prelude",  
"java", etc., are also susceptible to this startup logic.

On Nov 5, 2009, at 6:14 PM, James Britt (JIRA) wrote:

> jruby loads src/builtin/generator.rb  ahead of any other file named  
> generator
> -----------------------------------------------------------------------------
>
>                Key: JRUBY-4218
>                URL: http://jira.codehaus.org/browse/JRUBY-4218
>            Project: JRuby
>         Issue Type: Bug
>         Components: Core Classes/Modules
>   Affects Versions: JRuby 1.5
>        Environment: jruby 1.5.0.dev (ruby 1.8.7 patchlevel 174)  
> (2009-11-05 6586) (Java HotSpot(TM) Client VM 1.6.0_14) [i386-java]
>
> On Kubuntu 8.04.
>           Reporter: James Britt
>
>
> Example; 2 files, in the same directory.
>
>
> #------- generator.rb -----------
> warn "#{__FILE__} is loaded"
>
> class MyGen
> def foo
>   __FILE__
> end
> end
> #--------------------------------------
>
> #--------------- test.rb -------------------
> here = File.expand_path(File.dirname(__FILE__))
> $:.unshift here
> require 'generator.rb'
>
> begin
> p MyGen.new.foo
> rescue
> warn $!
> end
> #--------------------------------------
>
>
> Line 2 in test.rb forces the current directory to the head of the  
> load path, so
> local files should be found and loaded first.
>
> Execute test.rb using MRI (for example)
>
> $ ruby test.rb
> /home/james/tmp/jruby-require-bug/generator.rb is loaded
> "/home/james/tmp/jruby-require-bug/generator.rb"
> $
>
> Try with jruby:
>
> $ ruby jtest.rb
> uninitialized constant MyGen
>
> JRuby is loading sr/builtin/generator.rb despite the values in $:
>
> (You can check this by adding a puts statement to that file to  
> indicate when it gets loaded.)
>
>
>
>
>
>
>
> --
> This message is automatically generated by JIRA.
> -
> If you think it was sent incorrectly contact one of the  
> administrators: http://jira.codehaus.org/secure/Administrators.jspa
> -
> For more information on JIRA, see: http://www.atlassian.com/software/jira
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>   http://xircles.codehaus.org/manage_email
>
>


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



Re: [jira] Created: (JRUBY-4218) jruby loads src/builtin/generator.rb ahead of any other file named generator

by James Britt :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hirotsugu Asari wrote:
> I haven't read too much into the issue, so correct me if I'm wrong.
>
> As I understand it, by the time org.jruby.Ruby.parseFile() is called on
> test.rb, an org.jruby.Ruby.init() has already been called and builtins
> has already been loaded. By the same token, "prelude", "java", etc., are
> also susceptible to this startup logic.

I don't think so.

I added a puts call to to my copy of src/builtin.generator.rb to
announce when it was loaded.  I only see that if I call "require
'generator' (no matter how I arrange my $: values).

If you take test.rb, drop the call to "require 'generator'", and have it
print something and exit, src/builtin.generator.rb  does not get loaded.

So It appears to be  a load path issue.

James


--

Neurogami - Smart application development

http://www.neurogami.com

james@...





---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



Re: [jira] Created: (JRUBY-4218) jruby loads src/builtin/generator.rb ahead of any other file named generator

by Hirotsugu Asari :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On Nov 7, 2009, at 3:02 PM, James Britt wrote:

> Hirotsugu Asari wrote:
>> I haven't read too much into the issue, so correct me if I'm wrong.
>> As I understand it, by the time org.jruby.Ruby.parseFile() is  
>> called on test.rb, an org.jruby.Ruby.init() has already been called  
>> and builtins has already been loaded. By the same token, "prelude",  
>> "java", etc., are also susceptible to this startup logic.
>
> I don't think so.
>
> I added a puts call to to my copy of src/builtin.generator.rb to  
> announce when it was loaded.  I only see that if I call "require  
> 'generator' (no matter how I arrange my $: values).
>
> If you take test.rb, drop the call to "require 'generator'", and  
> have it print something and exit, src/builtin.generator.rb  does not  
> get loaded.
>
> So It appears to be  a load path issue.
>
> James

Hi, James,

You're right about what is actually loaded. Upon further reading, I  
see that JRuby won't load these builtin libraries during startup; it  
just populates builtinLibraries.

When it comes time to 'require',  
org.jruby.runtime.load.LoadService.findLibraryWithoutCWD() looks for  
built-in libraries first no matter what. There, only builtinLibraries  
is consulted to find an appropriate library.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email