Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 0aeab1f9eeea
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 2bafa0965a2f
Choose a head ref
  • 6 commits
  • 6 files changed
  • 3 contributors

Commits on Mar 14, 2016

  1. Copy the full SHA
    1ecc79c View commit details
  2. Copy the full SHA
    7d6fa84 View commit details
  3. Fix up how our 223 engine encodes input and decodes output.

    * Incoming scripts should be decoded from String to byte[] using
      default internal encoding, rather than trusting JDK's
      file.encoding to be appropriate.
    * Outgoing streams wrapping writers should decode strings based
      on current default internal encoding.
    
    Fixes #2403
    headius committed Mar 14, 2016
    Copy the full SHA
    af965d1 View commit details
  4. Copy the full SHA
    da42f62 View commit details
  5. Copy the full SHA
    1e09cda View commit details
  6. Copy the full SHA
    2bafa09 View commit details
30 changes: 27 additions & 3 deletions core/src/main/java/org/jruby/Ruby.java
Original file line number Diff line number Diff line change
@@ -173,6 +173,7 @@
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.channels.ClosedChannelException;
import java.nio.charset.Charset;
import java.security.AccessControlException;
import java.security.SecureRandom;
import java.util.ArrayList;
@@ -490,7 +491,7 @@ public IRubyObject evalScriptlet(String script, DynamicScope scope) {
* @return The last value of the script
*/
public IRubyObject executeScript(String script, String filename) {
byte[] bytes = script.getBytes();
byte[] bytes = encodeToBytes(script);

RootNode root = (RootNode) parseInline(new ByteArrayInputStream(bytes), filename, null);
ThreadContext context = getCurrentContext();
@@ -691,7 +692,7 @@ public IRubyObject runWithGetsLoop(RootNode scriptNode, boolean printing, boolea
private RootNode addGetsLoop(RootNode oldRoot, boolean printing, boolean processLineEndings, boolean split) {
ISourcePosition pos = oldRoot.getPosition();
BlockNode newBody = new BlockNode(pos);
newBody.add(new GlobalAsgnNode(pos, "$/", new StrNode(pos, new ByteList(getInstanceConfig().getRecordSeparator().getBytes()))));
newBody.add(new GlobalAsgnNode(pos, "$/", new StrNode(pos, ((RubyString) globalVariables.get("$/")).getByteList())));

if (processLineEndings) newBody.add(new GlobalAsgnNode(pos, "$\\", new GlobalVarNode(pos, "$/")));

@@ -2785,7 +2786,16 @@ private void setupSourceEncoding(ParserConfiguration parserConfig, Encoding defa

public Node parseEval(String content, String file, DynamicScope scope, int lineNumber) {
addEvalParseToStats();
return parser.parse(file, content.getBytes(), scope, new ParserConfiguration(this, lineNumber, false, false, config));

return parser.parse(file, encodeToBytes(content), scope, new ParserConfiguration(this, lineNumber, false, false, config));
}

private byte[] encodeToBytes(String string) {
Charset charset = getDefaultCharset();

byte[] bytes = charset == null ? string.getBytes() : string.getBytes(charset);

return bytes;
}

@Deprecated
@@ -2847,6 +2857,20 @@ public void setDefaultExternalEncoding(Encoding defaultExternalEncoding) {
this.defaultExternalEncoding = defaultExternalEncoding;
}

/**
* Get the default java.nio.charset.Charset for the current default internal encoding.
*/
public Charset getDefaultCharset() {
Encoding enc = getDefaultInternalEncoding();
if (enc == null) {
enc = UTF8Encoding.INSTANCE;
}

Charset charset = enc.getCharset();

return charset;
}

public EncodingService getEncodingService() {
return encodingService;
}
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/embed/jsr223/Utils.java
Original file line number Diff line number Diff line change
@@ -175,7 +175,7 @@ private static void setErrorWriter(ScriptingContainer container, Writer writer)
}

private static RubyIO getRubyIO(Ruby runtime, Writer writer) throws IOException, BadDescriptorException {
PrintStream pstream = new PrintStream(new WriterOutputStream(writer), true);
PrintStream pstream = new PrintStream(new WriterOutputStream(writer, runtime.getDefaultCharset().name()), true);
RubyIO io = new RubyIO(runtime, pstream, false);
boolean locked = io.getOpenFile().lock();
try {
Original file line number Diff line number Diff line change
@@ -32,6 +32,8 @@
import javax.script.Invocable;
import javax.script.Compilable;
import java.io.*;
import java.lang.reflect.Field;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
23 changes: 23 additions & 0 deletions spec/jrubyc/java/files/hashy_kwargs.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module HashyKwargs

DEFAULT_ARGS = { 'str' => 1, sym: 2 }
private_constant :DEFAULT_ARGS

def generic(*args, **kwargs, &block)
[ args, kwargs, block ]
end

def self.kwargs1(sym: 1, sec: 2)
sym || DEFAULT_ARGS[:sym]
end

def self.kwargs2(req:, **opts); [ req, opts ] end

DEFAULT_ARGS['foo'] || DEFAULT_ARGS['str']

Hash.new.tap do |hash|
hash['one'] = 11 / 10; hash['two'] = 22 / 10
@@hash_one = hash['tri'] || hash['one']
end

end
25 changes: 22 additions & 3 deletions spec/jrubyc/java/loading_spec.rb
Original file line number Diff line number Diff line change
@@ -25,7 +25,7 @@ def compile_files(files)
it "loads double_rescue.class" do
load File.join(FILES_DIR, 'double_rescue.class')

expect( defined?(DoubleRescue) ).to be_truthy
expect( Object.const_defined?(:DoubleRescue) ).to be true
DoubleRescue.new._call

expect( DoubleRescue.re_raise_return ).to be_a LoadError
@@ -35,15 +35,34 @@ def compile_files(files)
it "loads sample_block.class" do
load File.join(FILES_DIR, 'sample_block.class')

expect( defined?(SampleBlock) ).to be_truthy
expect( Object.const_defined?(:SampleBlock) ).to be true
expect( SampleBlock.class_variable_get :@@func ).to eql '11'
end

it "deserializes symbol_proc.class" do
load File.join(FILES_DIR, 'symbol_proc.class')

expect( $symbol_proc_result ).to be_truthy
expect( $symbol_proc_result ).to_not be nil
expect( $symbol_proc_result ).to eql [ 1, 2, 3 ]
end

it "compiles hashy_kwargs.class correctly" do
load File.join(FILES_DIR, 'hashy_kwargs.class')

expect( Object.const_defined?(:HashyKwargs) ).to be true
klass = Class.new { include HashyKwargs }
res = klass.new.generic('0', 111, arg: 1) { 'block' }
pending 'FIXME if you wonder!'
expect( res[0] ).to eql [ '0', 111 ]
expect( res[1] ).to eql({ :arg => 1 })
expect( res[2].call ).to eql 'block'
expect( res.size ).to be 3

expect( HashyKwargs.kwargs1(sec: '2') ).to eql 1
expect( HashyKwargs.kwargs1(sym: false) ).to eql 2

res = HashyKwargs.kwargs2(foo: :bar, baz: 0, req: true)
expect( res ).to eql [ true, { :foo => :bar, :baz => 0 }]
end

end
10 changes: 7 additions & 3 deletions tool/jt.rb
Original file line number Diff line number Diff line change
@@ -275,7 +275,7 @@ def help
puts 'jt test spec/ruby/language/while_spec.rb run specs in this file'
puts 'jt test compiler run compiler tests (uses the same logic as --graal to find Graal)'
puts ' --no-java-cmd don\'t set JAVACMD - rely on bin/jruby or RUBY_BIN to have Graal already'
puts 'jt test integration runs bigger integration tests'
puts 'jt test integration [fast] runs bigger integration tests'
puts ' --no-gems don\'t run tests that install gems'
puts 'jt tag spec/ruby/language tag failing specs in this directory'
puts 'jt tag spec/ruby/language/while_spec.rb tag failing specs in this file'
@@ -352,7 +352,7 @@ def run(*args)

if args.delete('--graal')
env_vars["JAVACMD"] = Utilities.find_graal
jruby_args << '-J-server'
jruby_args << '-J-Djvmci.Compiler=graal'
end

if args.delete('--js')
@@ -448,6 +448,7 @@ def test_mri(*args)
def test_compiler(*args)
env_vars = {}
env_vars["JAVACMD"] = Utilities.find_graal unless args.delete('--no-java-cmd')
env_vars["JRUBY_OPTS"] = '-J-Djvmci.Compiler=graal'
env_vars["PATH"] = "#{Utilities.find_jruby_bin_dir}:#{ENV["PATH"]}"
Dir["#{JRUBY_DIR}/test/truffle/compiler/*.sh"].each do |test_script|
sh env_vars, test_script
@@ -457,6 +458,7 @@ def test_compiler(*args)

def test_integration(*args)
no_gems = args.delete('--no-gems')
fast = args.delete('fast')
env_vars = {}
env_vars["PATH"] = "#{Utilities.find_jruby_bin_dir}:#{ENV["PATH"]}"

@@ -465,9 +467,11 @@ def test_integration(*args)
else
'{' + args.join(',') + '}'
end

Dir["#{JRUBY_DIR}/test/truffle/integration/#{test_names}.sh"].each do |test_script|
next if no_gems && File.read(test_script).include?('gem install')
next if fast && test_script.end_with?('integration/gem-testing.sh')
next if fast && test_script.end_with?('integration/rails.sh')
sh env_vars, test_script
end
end