Skip to content

Commit

Permalink
[Truffle] Load the Ruby API implementation before loading any C exten…
Browse files Browse the repository at this point in the history
…sions.
  • Loading branch information
chrisseaton committed Apr 25, 2016
1 parent 168b208 commit 66ba6d0
Showing 1 changed file with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,12 @@
public class FeatureLoader {

private final RubyContext context;

private final ConcurrentHashMap<String, ReentrantLock> fileLocks = new ConcurrentHashMap<>();

private final Object cextImplementationLock = new Object();
private boolean cextImplementationLoaded = false;

public FeatureLoader(RubyContext context) {
this.context = context;
}
Expand Down Expand Up @@ -194,6 +198,8 @@ public Boolean block() throws InterruptedException {
} break;

case RubyLanguage.CEXT_MIME_TYPE: {
ensureCExtImplementationLoaded(frame, callNode);

final CallTarget callTarget;

try {
Expand Down Expand Up @@ -244,6 +250,26 @@ public Boolean block() throws InterruptedException {

}

private void ensureCExtImplementationLoaded(VirtualFrame frame, IndirectCallNode callNode) {
synchronized (cextImplementationLock) {
if (cextImplementationLoaded) {
return;
}

final CallTarget callTarget;

try {
callTarget = context.getEnv().parse(Source.fromFileName(context.getJRubyRuntime().getJRubyHome() + "/lib/ruby/truffle/cext/ruby.su"));
} catch (IOException e) {
throw new RuntimeException(e);
}

callNode.call(frame, callTarget, new Object[]{});

cextImplementationLoaded = true;
}
}

private String getBaseName(String path) {
final String name = new File(path).getName();

Expand Down

0 comments on commit 66ba6d0

Please sign in to comment.