LOADED_FEATURES check should do .rb files and .so files separately
------------------------------------------------------------------

                 Key: JRUBY-4985
                 URL: http://jira.codehaus.org/browse/JRUBY-4985
             Project: JRuby
          Issue Type: Bug
          Components: Core Classes/Modules
    Affects Versions: JRuby 1.5.1
            Reporter: Charles Oliver Nutter
             Fix For: JRuby 1.6


In working on the C ext support for JRuby, Tim Felgentreff discovered that we 
now fail a set of RubySpecs of the following form:

{noformat}
    it "loads a .rb extensioned file when a complex-extensioned C-extension 
file of the same name is loaded" do
      $LOADED_FEATURES << File.expand_path("load_fixture.ext.bundle", 
CODE_LOADING_DIR)
      $LOADED_FEATURES << File.expand_path("load_fixture.ext.dylib", 
CODE_LOADING_DIR)
      $LOADED_FEATURES << File.expand_path("load_fixture.ext.so", 
CODE_LOADING_DIR)
      $LOADED_FEATURES << File.expand_path("load_fixture.ext.dll", 
CODE_LOADING_DIR)
      path = File.expand_path "load_fixture.ext", CODE_LOADING_DIR
      @object.require(path).should be_true
      ScratchPad.recorded.should == [:loaded]
    end
{noformat}

The basic idea is that if you have already required x.bundle, you should be 
able to require x and have it locate a .rb file. This fails in JRuby, but only 
if there's an extension in LOADED_FEATURES that we support; the spec uses 
bundle, dylib, so, and dll, none of which are supported in JRuby 1.5.1 so this 
failure is hidden.

The problem is that in BailoutSearcher, which runs as an early phase of 
LoadService searching, we try *all* extensions to see if any exist in 
LOADED_FEATURES. Because on the cext branch we now support "bundle" and 
friends, the specs fail; we see that there's a "load_fixture.ext.bundle" 
already loaded and don't try to find a .rb file.

{noformat}
    public class BailoutSearcher implements LoadSearcher {
        public boolean shouldTrySearch(SearchState state) {
            return true;
        }
    
        public void trySearch(SearchState state) throws AlreadyLoaded {
            for (String suffix : state.suffixType.getSuffixes()) {
                String searchName = state.searchFile + suffix;
                RubyString searchNameString = RubyString.newString(runtime, 
searchName);
                if (featureAlreadyLoaded(searchNameString)) {
                    throw new AlreadyLoaded(searchNameString);
                }
            }
        }
    }
{noformat}

The correct behavior, it seems, would be to have the same two-phase searching 
for LOADED_FEATURES that we do already for source versus extension-based 
libraries. So we'd follow this sequence:

# check whether the file has been loaded already as a .rb form
# if not, try loading it as a .rb file
# if that fails, check whether the file has been loaded already as an extension
# if not, try loading that extension

This will probably affect actual applications once we land cext support, so 
I've marked it for 1.6.

-- 
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


Reply via email to