Skip to content

Commit

Permalink
Showing 10 changed files with 78 additions and 28 deletions.
24 changes: 14 additions & 10 deletions core/src/main/java/org/jruby/RubyInstanceConfig.java
Original file line number Diff line number Diff line change
@@ -165,21 +165,25 @@ public void processArguments(String[] arguments) {

public void tryProcessArgumentsWithRubyopts() {
try {
// environment defaults to System.getenv normally
Object rubyoptObj = environment.get("RUBYOPT");
String rubyopt = rubyoptObj == null ? null : rubyoptObj.toString();

if (rubyopt == null || rubyopt.length() == 0) return;

String[] rubyoptArgs = rubyopt.split("\\s+");
if (rubyoptArgs.length != 0) {
new ArgumentProcessor(rubyoptArgs, false, true, true, this).processArguments();
}
processArgumentsWithRubyopts();
} catch (SecurityException se) {
// ignore and do nothing
}
}

public void processArgumentsWithRubyopts() {
// environment defaults to System.getenv normally
Object rubyoptObj = environment.get("RUBYOPT");
String rubyopt = rubyoptObj == null ? null : rubyoptObj.toString();

if (rubyopt == null || rubyopt.length() == 0) return;

String[] rubyoptArgs = rubyopt.split("\\s+");
if (rubyoptArgs.length != 0) {
new ArgumentProcessor(rubyoptArgs, false, true, true, this).processArguments();
}
}

// This method does not work like previous version in verifying it is
// a Ruby shebang line. Looking for ruby before \n is possible to add,
// but I wanted to keep this short.
17 changes: 17 additions & 0 deletions spec/truffle/specs/truffle/interop/from_java_string_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved. This
# code is released under a tri EPL/GPL/LGPL license. You can use it,
# redistribute it and/or modify it under the terms of the:
#
# Eclipse Public License version 1.0
# GNU General Public License version 2
# GNU Lesser General Public License version 2.1

require_relative '../../../../ruby/spec_helper'

describe "Truffle::Interop.from_java_string" do

it "can be round-tripped with to_java_string" do
Truffle::Interop.from_java_string(Truffle::Interop.to_java_string("foo")).should == "foo"
end

end
17 changes: 17 additions & 0 deletions spec/truffle/specs/truffle/interop/to_java_string_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved. This
# code is released under a tri EPL/GPL/LGPL license. You can use it,
# redistribute it and/or modify it under the terms of the:
#
# Eclipse Public License version 1.0
# GNU General Public License version 2
# GNU Lesser General Public License version 2.1

require_relative '../../../../ruby/spec_helper'

describe "Truffle::Interop.to_java_string" do

it "can be round-tripped with from_java_string" do
Truffle::Interop.from_java_string(Truffle::Interop.to_java_string("foo")).should == "foo"
end

end
12 changes: 6 additions & 6 deletions spec/truffle/tags/core/kernel/spawn_tags.txt
Original file line number Diff line number Diff line change
@@ -169,9 +169,9 @@ slow:Kernel.spawn redirects STDERR to the given file descriptor if err: IO
slow:Kernel.spawn redirects STDERR to child STDOUT if :err => [:child, :out]
slow:Kernel.spawn redirects both STDERR and STDOUT to the given file descriptior
slow:Kernel.spawn redirects both STDERR and STDOUT to the given IO
fails:Kernel#spawn redirects STDOUT to the given file if out: String ERROR
fails:Kernel#spawn redirects STDOUT to the given file if out: [String name, String mode] ERROR
fails:Kernel#spawn redirects STDERR to the given file if err: String ERROR
fails:Kernel.spawn redirects STDOUT to the given file if out: String ERROR
fails:Kernel.spawn redirects STDOUT to the given file if out: [String name, String mode] ERROR
fails:Kernel.spawn redirects STDERR to the given file if err: String ERROR
fails:Kernel#spawn redirects STDOUT to the given file if out: String
fails:Kernel#spawn redirects STDOUT to the given file if out: [String name, String mode]
fails:Kernel#spawn redirects STDERR to the given file if err: String
fails:Kernel.spawn redirects STDOUT to the given file if out: String
fails:Kernel.spawn redirects STDOUT to the given file if out: [String name, String mode]
fails:Kernel.spawn redirects STDERR to the given file if err: String
6 changes: 3 additions & 3 deletions spec/truffle/tags/core/process/spawn_tags.txt
Original file line number Diff line number Diff line change
@@ -83,6 +83,6 @@ slow:Process.spawn redirects STDERR to child STDOUT if :err => [:child, :out]
slow:Process.spawn redirects both STDERR and STDOUT to the given file descriptior
slow:Process.spawn redirects both STDERR and STDOUT to the given IO
slow:Process.spawn does NOT redirect both STDERR and STDOUT at the time to the given name
fails:Process.spawn redirects STDOUT to the given file if out: String ERROR
fails:Process.spawn redirects STDOUT to the given file if out: [String name, String mode] ERROR
fails:Process.spawn redirects STDERR to the given file if err: String ERROR
fails:Process.spawn redirects STDOUT to the given file if out: String
fails:Process.spawn redirects STDOUT to the given file if out: [String name, String mode]
fails:Process.spawn redirects STDERR to the given file if err: String
1 change: 1 addition & 0 deletions truffle/src/main/java/org/jruby/truffle/RubyLanguage.java
Original file line number Diff line number Diff line change
@@ -64,6 +64,7 @@ public RubyContext createContext(Env env) {

if (runtimeWrapper == null) {
RubyInstanceConfig config = new RubyInstanceConfig();
config.processArgumentsWithRubyopts();
config.setCompileMode(RubyInstanceConfig.CompileMode.TRUFFLE);
runtime = Ruby.newInstance(config);
} else {
Original file line number Diff line number Diff line change
@@ -24,10 +24,6 @@
@NodeChild(value = "value", type = RubyNode.class)
public abstract class ForeignToRubyNode extends RubyNode {

public ForeignToRubyNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

public abstract Object executeConvert(VirtualFrame frame, Object value);

@Specialization(guards = "stringsEquals(cachedValue, value)", limit = "getLimit()")
21 changes: 18 additions & 3 deletions truffle/src/main/java/org/jruby/truffle/interop/InteropNodes.java
Original file line number Diff line number Diff line change
@@ -616,13 +616,28 @@ protected int getCacheLimit() {
@CoreMethod(names = "to_java_string", isModuleFunction = true, needsSelf = false, required = 1)
public abstract static class InteropToJavaStringNode extends CoreMethodArrayArgumentsNode {

@Child NameToJavaStringNode toJavaStringNode = NameToJavaStringNode.create();

@Specialization
public Object toJavaString(VirtualFrame frame, Object value) {
public Object toJavaString(
VirtualFrame frame, Object value,
@Cached("create()") NameToJavaStringNode toJavaStringNode) {
return toJavaStringNode.executeToJavaString(frame, value);
}

}

@CoreMethod(names = "from_java_string", isModuleFunction = true, needsSelf = false, required = 1)
public abstract static class InteropFromJavaStringNode extends CoreMethodArrayArgumentsNode {

@Specialization
public Object fromJavaString(VirtualFrame frame, Object value,
@Cached("createForeignToRubyNode()") ForeignToRubyNode foreignToRubyNode) {
return foreignToRubyNode.executeConvert(frame, value);
}

protected ForeignToRubyNode createForeignToRubyNode() {
return ForeignToRubyNodeGen.create(null);
}

}

}
2 changes: 0 additions & 2 deletions truffle/src/main/ruby/core/shims.rb
Original file line number Diff line number Diff line change
@@ -271,5 +271,3 @@ def when_splat(cases, expression)
c === expression
end
end

Truffle::Interop.export(:ruby_cext, Truffle::CExt)
2 changes: 2 additions & 0 deletions truffle/src/main/ruby/core/truffle/cext.rb
Original file line number Diff line number Diff line change
@@ -180,3 +180,5 @@ def rb_undef(mod, name)
end
end
end

Truffle::Interop.export(:ruby_cext, Truffle::CExt)

0 comments on commit 5b75da4

Please sign in to comment.