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: 3b2fc4103ae7
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: a2eec06723ee
Choose a head ref
  • 6 commits
  • 21 files changed
  • 1 contributor

Commits on May 10, 2016

  1. Copy the full SHA
    cf3a292 View commit details
  2. Copy the full SHA
    9d86769 View commit details
  3. Copy the full SHA
    3ebc198 View commit details
  4. Copy the full SHA
    e86ad04 View commit details
  5. Copy the full SHA
    79d008f View commit details
  6. Fix unchecked warning.

    headius committed May 10, 2016
    Copy the full SHA
    a2eec06 View commit details
5 changes: 1 addition & 4 deletions core/src/main/java/org/jruby/RubyThread.java
Original file line number Diff line number Diff line change
@@ -876,11 +876,8 @@ private IRubyObject getSymbolKey(IRubyObject originalKey) {
return originalKey;
} else if (originalKey instanceof RubyString) {
return getRuntime().newSymbol(originalKey.asJavaString());
} else if (originalKey instanceof RubyFixnum) {
getRuntime().getWarnings().warn(ID.FIXNUMS_NOT_SYMBOLS, "Do not use Fixnums as Symbols");
throw getRuntime().newArgumentError(originalKey + " is not a symbol");
} else {
throw getRuntime().newTypeError(originalKey + " is not a symbol");
throw getRuntime().newTypeError(originalKey + " is not a symbol nor a string");
}
}

8 changes: 5 additions & 3 deletions core/src/main/java/org/jruby/parser/ParserSupport.java
Original file line number Diff line number Diff line change
@@ -1303,14 +1303,16 @@ private List<Integer> allocateNamedLocals(RegexpNode regexpNode) {

for (int i = 0; i < length; i++) {
// TODO: Pass by non-local-varnamed things but make sure consistent with list we get from regexp

if (RubyLexer.getKeyword(names[i]) == null && !Character.isUpperCase(names[i].charAt(0))) {
int slot = scope.isDefined(names[i]);
if (slot >= 0) {
if (warnings.isVerbose()) warn(ID.AMBIGUOUS_ARGUMENT, getPosition(regexpNode), "named capture conflicts a local variable - " + names[i]);
// If verbose and the variable is not just another named capture, warn
if (warnings.isVerbose() && !scope.isNamedCapture(slot)) {
warn(ID.AMBIGUOUS_ARGUMENT, getPosition(regexpNode), "named capture conflicts a local variable - " + names[i]);
}
locals.add(slot);
} else {
locals.add(getCurrentScope().addVariableThisScope(names[i]));
locals.add(getCurrentScope().addNamedCaptureVariable(names[i]));
}
}
}
37 changes: 36 additions & 1 deletion core/src/main/java/org/jruby/parser/StaticScope.java
Original file line number Diff line number Diff line change
@@ -76,6 +76,9 @@ public class StaticScope implements Serializable {
// Our name holder (offsets are assigned as variables are added)
private String[] variableNames;

// A list of booleans indicating which variables are named captures from regexp
private boolean[] namedCaptures;

// Arity of this scope if there is one
private Signature signature;

@@ -185,7 +188,7 @@ private static boolean namesAreInterned(String[] names) {
* current scope.
*
* @param name of new variable
* @return index+depth merged location of scope
* @return index of variable
*/
public int addVariableThisScope(String name) {
// Ignore duplicate "_" args in blocks
@@ -206,6 +209,20 @@ public int addVariableThisScope(String name) {
return variableNames.length - 1;
}

/**
* Add a new named capture variable to this (current) scope.
*
* @param name name of variable.
* @return index of variable
*/
public int addNamedCaptureVariable(String name) {
int index = addVariableThisScope(name);

growNamedCaptures(index);

return index;
}

/**
* Add a new variable to this (current) scope unless it is already defined in any
* reachable scope.
@@ -509,6 +526,24 @@ private void growVariableNames(String name) {
variableNames[variableNames.length - 1] = name;
}

private void growNamedCaptures(int index) {
boolean[] namedCaptures = this.namedCaptures;
boolean[] newNamedCaptures;
if (namedCaptures != null) {
newNamedCaptures = new boolean[Math.max(index + 1, namedCaptures.length)];
System.arraycopy(namedCaptures, 0, newNamedCaptures, 0, namedCaptures.length);
} else {
newNamedCaptures = new boolean[index + 1];
}
newNamedCaptures[index] = true;
this.namedCaptures = newNamedCaptures;
}

public boolean isNamedCapture(int index) {
boolean[] namedCaptures = this.namedCaptures;
return namedCaptures != null && index < namedCaptures.length && namedCaptures[index];
}

@Override
public String toString() {
// FIXME: Do we need to persist cref as well?
4 changes: 4 additions & 0 deletions core/src/main/java/org/jruby/util/io/FilenoUtil.java
Original file line number Diff line number Diff line change
@@ -65,6 +65,10 @@ public void unregisterWrapper(int fileno) {
filenoMap.remove(fileno);
}

public int getNumberOfWrappers() {
return filenoMap.size();
}

public int getNewFileno() {
return internalFilenoIndex.getAndIncrement();
}
2 changes: 1 addition & 1 deletion spec/java_integration/fixtures/Reflector.java
Original file line number Diff line number Diff line change
@@ -27,7 +27,7 @@ public static Object invoke(final Object obj, final Method method, Object arg) t
return method.invoke(obj, arg);
}

public static Object invoke(final Object obj, final Class klass, final String method) throws Exception {
public static Object invoke(final Object obj, final Class<?> klass, final String method) throws Exception {
Method instanceMethod = klass.getMethod(method, (Class[]) null);
return instanceMethod.invoke(obj, (Object[]) null);
}
28 changes: 14 additions & 14 deletions test/jruby/test_backquote.rb
Original file line number Diff line number Diff line change
@@ -13,20 +13,20 @@ def test_backquote_special_commands
end
end

def test_backquote_special_commands_and_cwd_inside_classloader
# not sure why it fails with java-1.6 - assume it is rare feature
# and works for java-1.7+
if File.exists?("/bin/echo") and not ENV_JAVA['java.version'].start_with?("1.6.")
begin
cwd = Dir.pwd
Dir.chdir('uri:classloader:/')
output = `/bin/echo hello`
assert_equal("hello\n", output)
ensure
Dir.chdir(cwd)
end
end
end
# def test_backquote_special_commands_and_cwd_inside_classloader
# # not sure why it fails with java-1.6 - assume it is rare feature
# # and works for java-1.7+
# if File.exists?("/bin/echo") and not ENV_JAVA['java.version'].start_with?("1.6.")
# begin
# cwd = Dir.pwd
# Dir.chdir('uri:classloader:/')
# output = `/bin/echo hello`
# assert_equal("hello\n", output)
# ensure
# Dir.chdir(cwd)
# end
# end
# end

def test_system_special_commands
if File.exists?("/bin/true")
2 changes: 1 addition & 1 deletion test/jruby/test_helper.rb
Original file line number Diff line number Diff line change
@@ -82,7 +82,7 @@ def jruby_with_pipe(pipe, *args)
end

def sh(cmd)
puts cmd if $VERBOSE
puts cmd if $DEBUG
return `#{cmd}`
end
private :sh
3 changes: 2 additions & 1 deletion test/jruby/test_higher_javasupport.rb
Original file line number Diff line number Diff line change
@@ -1394,7 +1394,8 @@ def test_java_methods_have_arity

# JRUBY-3476
def test_object_with_singleton_returns_java_class
x = java.lang.Object.new
java.util.ArrayList.__persistent__ = true
x = java.util.ArrayList.new
def x.foo; end
assert(x.java_class.kind_of?Java::JavaClass)
end
26 changes: 18 additions & 8 deletions test/jruby/test_io.rb
Original file line number Diff line number Diff line change
@@ -70,7 +70,13 @@ def test_premature_close_raises_appropriate_errors
assert_nothing_raised { g.write "" }
assert_nothing_raised { g.puts "" }
assert_nothing_raised { g.putc 'c' }
assert_raises(Errno::EBADF) { g.syswrite "" }
begin
# silence "syswrite for buffered IO" warning
verbose, $VERBOSE = $VERBOSE, nil
assert_raises(Errno::EBADF) { g.syswrite "" }
ensure
$VERBOSE = verbose
end

f = File.open(@file, "w")
@to_close << g = IO.new(f.fileno)
@@ -483,16 +489,20 @@ def test_stringio_gets_separator
end

# JRUBY-6137
def test_rubyio_fileno_mapping_leak; require 'jruby'
pend "TODO: refactor JRuby.runtime.fileno_int_map_size"
starting_count = JRuby.runtime.fileno_int_map_size
io = org.jruby.RubyIO.new(JRuby.runtime, org.jruby.util.io.STDIO::ERR)
open_io_count = JRuby.runtime.fileno_int_map_size
def test_rubyio_fileno_mapping_leak
fileno_util = JRuby.runtime.fileno_util
starting_count = fileno_util.number_of_wrappers

# use a non-channel stream to ensure we use our mapping
io = org.jruby.RubyIO.new(JRuby.runtime, java.io.ByteArrayOutputStream.new)

open_io_count = fileno_util.number_of_wrappers
assert_equal(starting_count + 1, open_io_count)

io.close
closed_io_count = JRuby.runtime.fileno_int_map_size
closed_io_count = fileno_util.number_of_wrappers
assert_equal(starting_count, closed_io_count)
end if defined? JRUBY_VERSION
end if RUBY_ENGINE == 'jruby'

# JRUBY-1222
def test_stringio_gets_utf8
7 changes: 3 additions & 4 deletions test/jruby/test_ivar_table_integrity.rb
Original file line number Diff line number Diff line change
@@ -3,11 +3,10 @@
class TestIvarTableIntegrity < Test::Unit::TestCase
def test_ivar_table_integrity
cls = Class.new do
def foo=(a); @foo = a; end
def initialize; @foo = nil; end
attr_accessor :foo
attr_accessor :bar
def remove_foo; remove_instance_variable :@foo; end
def foo; @foo; end
def bar=(a); @bar = a; end
def bar; @bar; end
end

obj = cls.new
6 changes: 3 additions & 3 deletions test/jruby/test_java_extension.rb
Original file line number Diff line number Diff line change
@@ -310,9 +310,9 @@ def protected_method; "HELLO!" end
end

def test_calling_abstract_method_in_java_constructor
return skip('this leaking in super constructor (calling Ruby implemented methods)')
a = CallAbstractInConstructor.new
assert_equal "HELLO!", a.result
skip('this leaking in super constructor (calling Ruby implemented methods)')
#a = CallAbstractInConstructor.new
#assert_equal "HELLO!", a.result
end

def test_map_interface_to_array
50 changes: 22 additions & 28 deletions test/jruby/test_kernel.rb
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ class TestKernel < Test::Unit::TestCase
include TestHelper

def log(msg)
$stderr.puts msg if $VERBOSE
$stderr.puts msg if $DEBUG
end

TESTAPP_DIR = File.expand_path(File.join(File.dirname(__FILE__), 'testapp'))
@@ -432,42 +432,36 @@ def test_system_empty
assert !system('')
end

unless false # FIXME figure out why this doesn't pass in 1.9+
def test_system_existing
quiet do
if (WINDOWS)
res = system('cd')
else
res = system('pwd')
end
assert_equal true, res
def test_system_existing
quiet do
if (WINDOWS)
res = system('cd')
else
res = system('true')
end
assert_equal true, res
end
end

unless false # FIXME figure out why this doesn't pass in 1.9+
def test_system_existing_with_leading_space
quiet do
if (WINDOWS)
res = system(' cd')
else
res = system(' pwd')
end
assert_equal true, res
def test_system_existing_with_leading_space
quiet do
if (WINDOWS)
res = system(' cd')
else
res = system(' true')
end
assert_equal true, res
end
end

unless false # FIXME figure out why this doesn't pass in 1.9+
def test_system_existing_with_trailing_space
quiet do
if (WINDOWS)
res = system('cd ')
else
res = system('pwd ')
end
assert_equal true, res
def test_system_existing_with_trailing_space
quiet do
if (WINDOWS)
res = system('cd ')
else
res = system('true ')
end
assert_equal true, res
end
end

3 changes: 2 additions & 1 deletion test/jruby/test_load.rb
Original file line number Diff line number Diff line change
@@ -319,8 +319,9 @@ def test_symlinked_jar
end

def test_load_wrapped
pend 'TODO: fix load module wrapping'
load(File.expand_path('hello_dummy.rb', File.dirname(__FILE__)), true)
assert !defined?(::Hello)
assert !defined?(::Dummy)
end

end
4 changes: 2 additions & 2 deletions test/jruby/test_load_compiled_ruby_class_from_classpath.rb
Original file line number Diff line number Diff line change
@@ -75,7 +75,7 @@ def test_loading_compiled_ruby_class_from_jar

javac = ENV['JAVA_HOME'] ? "#{ENV['JAVA_HOME']}/bin/javac" : "javac"
javac_cmd = "#{javac} -cp #{jruby_jar} #{StarterSource}"
puts javac_cmd if $VERBOSE; `#{javac_cmd}`
`#{javac_cmd}`
assert_equal 0, $?.exitstatus, "javac failed to compile #{StarterSource}"

jar = ENV['JAVA_HOME'] ? "#{ENV['JAVA_HOME']}/bin/jar" : "jar"
@@ -86,7 +86,7 @@ def test_loading_compiled_ruby_class_from_jar

java = ENV['JAVA_HOME'] ? "#{ENV['JAVA_HOME']}/bin/java" : "java"
java_cmd = "#{java} -jar -Djruby.aot.loadClasses=true #{JarFile}"
puts java_cmd if $VERBOSE; result = `#{java_cmd}`
result = `#{java_cmd}`
assert_equal 0, $?.exitstatus, "did not get 0 for exit status from running java against the jar"
assert_equal "hello from runner", result, "wrong text from runner"
end
1 change: 1 addition & 0 deletions test/jruby/test_method_missing.rb
Original file line number Diff line number Diff line change
@@ -103,6 +103,7 @@ def inspect
end

def test_inspect_not_called_on_method_missing
$inspect_not_called = nil
TestInspectNotCalled.new.foo rescue nil
assert_equal nil, $inspect_not_called
end
6 changes: 3 additions & 3 deletions test/jruby/test_socket.rb
Original file line number Diff line number Diff line change
@@ -224,10 +224,10 @@ def test_udp_socket_bind

def test_tcp_socket_errors
begin
TCPSocket.new('127.0.0.10', 42)
TCPSocket.new('0.0.0.0', 42)
rescue Errno::ECONNREFUSED => e
# Connection refused - connect(2) for "127.0.0.1" port 42
assert_equal 'Connection refused - connect(2) for "127.0.0.10" port 42', e.message
# Connection refused - connect(2) for "0.0.0.0" port 42
assert_equal 'Connection refused - connect(2) for "0.0.0.0" port 42', e.message
else; fail 'not raised'
end

10 changes: 8 additions & 2 deletions test/jruby/test_system.rb
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@

require 'test/unit'
require 'rbconfig'
require 'open3'

class TestSystem < Test::Unit::TestCase
# JRUBY-5110
@@ -15,10 +16,15 @@ def test_system_on_windows
# JRUBY-6960
def test_system_with_conflicting_dir
FileUtils.mkdir_p 'extra_path/java'
ENV['PATH'] = "extra_path#{File::PATH_SEPARATOR}#{ENV['PATH']}"
assert(system 'java -version')
path = ENV['PATH']
ENV['PATH'] = "extra_path#{File::PATH_SEPARATOR}#{path}"
Open3.popen3('java -version') do |i, o, e, t|
assert_match(/java/, e.read)
assert_equal(t.value, 0)
end
ensure
FileUtils.rm_rf 'extra_path'
ENV['PATH'] = path
end

end
Loading