Skip to content

Commit

Permalink
Merge branch 'jruby-1_7'
Browse files Browse the repository at this point in the history
* jruby-1_7:
  test that public_send correctly dispatches native Java methods (closing #3668)
  generic JavaMethodN call with [] args should delegate to correct arity (due overriders)
  explicitly mark required arg count for RubyString squeeze impls
kares committed Feb 17, 2016
2 parents 9b3a6bb + c81b335 commit d3bfea1
Showing 3 changed files with 48 additions and 14 deletions.
25 changes: 13 additions & 12 deletions core/src/main/java/org/jruby/RubyString.java
Original file line number Diff line number Diff line change
@@ -4536,14 +4536,14 @@ public IRubyObject squeeze19(ThreadContext context) {
return str;
}

@JRubyMethod(name = "squeeze")
@JRubyMethod(name = "squeeze", required = 1)
public IRubyObject squeeze19(ThreadContext context, IRubyObject arg) {
RubyString str = strDup(context.runtime);
str.squeeze_bang19(context, arg);
return str;
}

@JRubyMethod(name = "squeeze", rest = true)
@JRubyMethod(name = "squeeze", required = 2, rest = true)
public IRubyObject squeeze19(ThreadContext context, IRubyObject[] args) {
RubyString str = strDup(context.runtime);
str.squeeze_bang19(context, args);
@@ -4552,11 +4552,12 @@ public IRubyObject squeeze19(ThreadContext context, IRubyObject[] args) {

@JRubyMethod(name = "squeeze!")
public IRubyObject squeeze_bang19(ThreadContext context) {
Ruby runtime = context.runtime;
if (value.getRealSize() == 0) {
modifyCheck();
return runtime.getNil();
return context.nil;
}
final Ruby runtime = context.runtime;

final boolean squeeze[] = new boolean[StringSupport.TRANS_SIZE];
for (int i=0; i< StringSupport.TRANS_SIZE; i++) squeeze[i] = true;

@@ -4574,9 +4575,9 @@ public IRubyObject squeeze_bang19(ThreadContext context) {
return this;
}

@JRubyMethod(name = "squeeze!")
@JRubyMethod(name = "squeeze!", required = 1)
public IRubyObject squeeze_bang19(ThreadContext context, IRubyObject arg) {
Ruby runtime = context.runtime;
final Ruby runtime = context.runtime;

RubyString otherStr = arg.convertToString();
final boolean squeeze[] = new boolean[StringSupport.TRANS_SIZE + 1];
@@ -4596,29 +4597,29 @@ public IRubyObject squeeze_bang19(ThreadContext context, IRubyObject arg) {
return this;
}

@JRubyMethod(name = "squeeze!", rest = true)
@JRubyMethod(name = "squeeze!", rest = true, required = 2)
public IRubyObject squeeze_bang19(ThreadContext context, IRubyObject[] args) {
Ruby runtime = context.runtime;
if (value.getRealSize() == 0) {
modifyCheck();
return runtime.getNil();
return context.nil;
}
final Ruby runtime = context.runtime;

RubyString otherStr = args[0].convertToString();
Encoding enc = checkEncoding(otherStr);
final boolean squeeze[] = new boolean[StringSupport.TRANS_SIZE + 1];
StringSupport.TrTables tables = StringSupport.trSetupTable(otherStr.value, runtime, squeeze, null, true, enc);

boolean singlebyte = singleByteOptimizable() && otherStr.singleByteOptimizable();
boolean singleByte = singleByteOptimizable() && otherStr.singleByteOptimizable();
for (int i=1; i<args.length; i++) {
otherStr = args[i].convertToString();
enc = checkEncoding(otherStr);
singlebyte = singlebyte && otherStr.singleByteOptimizable();
singleByte = singleByte && otherStr.singleByteOptimizable();
tables = StringSupport.trSetupTable(otherStr.value, runtime, squeeze, tables, false, enc);
}

modifyAndKeepCodeRange();
if (singlebyte) {
if (singleByte) {
if (! StringSupport.singleByteSqueeze(value, squeeze)) {
return runtime.getNil();
}
Original file line number Diff line number Diff line change
@@ -725,9 +725,21 @@ public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule claz
return call(context, self, clazz, name, new IRubyObject[] {arg0, arg1, arg2});
}

public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject[] args, Block block) {
return call(context, self, clazz, name, args);
public final IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, String name, IRubyObject[] args, Block block) {
switch (args.length) {
// still delegate to different arity calls as they might get overriden e.g. for native
// JRuby methods that use overloading for different kind arity of received arguments !
case 0:
return call(context, self, clazz, name);
case 1:
return call(context, self, clazz, name, args[0]);
case 2:
return call(context, self, clazz, name, args[0], args[1]);
default:
return call(context, self, clazz, name, args);
}
}

}


21 changes: 21 additions & 0 deletions test/jruby/test_string.rb
Original file line number Diff line number Diff line change
@@ -105,4 +105,25 @@ def do_sub buf, e1, e2, e3
assert_equal e3, buf.size
end

public

def test_try_squeeze
' '.squeeze
try ' ', :squeeze # ArrayIndexOutOfBoundsException
end

private

def try(obj, *a, &b) # ~ AS 4.2
if a.empty? && block_given?
if b.arity == 0
obj.instance_eval(&b)
else
yield obj
end
else
obj.public_send(*a, &b)
end
end

end

0 comments on commit d3bfea1

Please sign in to comment.