[ruby-core:35471] MRI silently handles .so files as Ruby sources

11 views
Skip to first unread message

Simone Carletti

unread,
Mar 9, 2011, 3:59:30 PM3/9/11
to ruby...@ruby-lang.org
Hello,

today I noticed that if you have a file called filename.so.rb and you try to require it without specifying the extension, MRI silently understands that it isn't a .so file, will load the content and treat it as Ruby source.

# filename.so.rb
puts __FILE__

# somefile.rb
require 'filename.so'

# => /../../filename.so.rb

Other interpreters handle the case in a different way. 
For example, JRuby won't load the file because it looks for a Ruby extension in a file called filename.so.

I had a small chat with Charles Oliver Nutter (you can read the comments in the JIRA ticket) and I'm curious to know if the way MRI works should be considered a bug, a coincidence or a feature.

Thanks,

--
Simone Carletti
Application Developer

Skype: weppos


Charles Oliver Nutter

unread,
Mar 9, 2011, 4:35:55 PM3/9/11
to ruby...@ruby-lang.org
On Wed, Mar 9, 2011 at 2:59 PM, Simone Carletti <wep...@weppos.net> wrote:
> Hello,
> today I noticed that if you have a file called filename.so.rb and you try to
> require it without specifying the extension, MRI silently understands that
> it isn't a .so file, will load the content and treat it as Ruby source.
>>
>> # filename.so.rb
>> puts __FILE__
>> # somefile.rb
>> require 'filename.so'
>> # => /../../filename.so.rb
>
> Other interpreters handle the case in a different way.
> For example, JRuby won't load the file because it looks for a Ruby extension
> in a file called filename.so.
> See http://jira.codehaus.org/browse/JRUBY-5569
> I had a small chat with Charles Oliver Nutter (you can read the comments in
> the JIRA ticket) and I'm curious to know if the way MRI works should be
> considered a bug, a coincidence or a feature.
> Thanks,

Just when I thought I knew all load-searching oddities :)

If you look at the JRuby bug you'll see that it's a very specific case
and I show several scenarios that either work or don't work...

* Only fails over for "extension" extensions like .so or
.bundle...does not fail over for things like foo.rb.rb or foo.rb.so
* Appears to do a search for both .rb and <extension extension> if the
original filename doesn't work
* Does not fail over to "extension" extensions that are not
appropriate for current platform, like .so.so on OS X

I think it's confusing and unpredictable and would just as soon have
the logic be "if it ends with an extension extension, only search
extension extensions."

- Charlie

Reply all
Reply to author
Forward
0 new messages