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: 87c106c267c1
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 9ed7c3198a11
Choose a head ref

Commits on Aug 9, 2015

  1. Fix Digest bubblebabble incorrect output on empty string

    Before:
    
    bin/jruby -rdigest -e "p Digest.bubblebabble ''"
    "xx"
    
    After:
    
    bin/jruby -rdigest -e "p Digest.bubblebabble ''"
    "xexax"
    kubum committed Aug 9, 2015
    Copy the full SHA
    de1293d View commit details

Commits on Aug 10, 2015

  1. Copy the full SHA
    aff8cc3 View commit details
  2. add missing file

    mkristian committed Aug 10, 2015
    Copy the full SHA
    1b29283 View commit details
  3. cleanup JRubyFile

    kares committed Aug 10, 2015
    Copy the full SHA
    a239875 View commit details
  4. Copy the full SHA
    bb3693d View commit details
  5. Copy the full SHA
    6130a8d View commit details
  6. save an interim builder+string with mangleStringForCleanJavaIdentifier

    + guess string builder length for possibly less internal array resizing
    kares committed Aug 10, 2015
    Copy the full SHA
    5cdf16e View commit details
  7. cleanup test_backtraces

    kares committed Aug 10, 2015
    Copy the full SHA
    fef67b8 View commit details
  8. Copy the full SHA
    d00e10c View commit details
  9. Copy the full SHA
    75d7ae6 View commit details
  10. improve backtrace rewriting when native exception is re-thrown (fixes #…

    …3177)
    
    ... some parts e.g. Java based core-methods had their filename part incorrect when re-thrown (adding package prefix path twice)
    kares committed Aug 10, 2015
    Copy the full SHA
    b62957b View commit details
  11. Copy the full SHA
    add39cb View commit details
  12. toArray one-liner

    kares committed Aug 10, 2015
    Copy the full SHA
    b348070 View commit details
  13. Copy the full SHA
    7745f10 View commit details
  14. Copy the full SHA
    96094b2 View commit details
  15. Copy the full SHA
    9c636bf View commit details
  16. FrameType's INTERPRETER_ constants are a leaky abstraction - deprecate

    ... also on 9K we can do better by doing swith (String) statement(s)
    kares committed Aug 10, 2015
    Copy the full SHA
    6a8d8cc View commit details
  17. Merge branch 'jruby-1_7'

    * jruby-1_7:
      FrameType's INTERPRETER_ constants are a leaky abstraction - deprecate
      for now we do not care about duplicate .rb frames in re-thrown Java exception
      occupy less space with FrameType's static collections
      deprecate no longer used Helpers.invokeMethodMissing method
      toArray one-liner
      add a test reproducing backtrace issue #3177
      improve backtrace rewriting when native exception is re-thrown (fixes #3177)
      more test_backtraces TODO left-overs ... these are passing just fine as well
      removed TODOs in test_backtraces - they seem to be all passing
      cleanup test_backtraces
      save an interim builder+string with mangleStringForCleanJavaIdentifier + guess string builder length for possibly less internal array resizing
      avoid 'too much' of try-catch IOException - throw runtime error directly
      minor name mangler cleanup + "micro opts" - slightly less code to execute
      cleanup JRubyFile
    
    Conflicts:
    	core/src/main/java/org/jruby/runtime/backtrace/BacktraceData.java
    	core/src/main/java/org/jruby/runtime/backtrace/FrameType.java
    	core/src/main/java/org/jruby/util/JRubyFile.java
    	test/test_backtraces.rb
    kares committed Aug 10, 2015
    Copy the full SHA
    c9e67b3 View commit details
  18. Copy the full SHA
    e883d65 View commit details
  19. add missing file

    mkristian committed Aug 10, 2015
    Copy the full SHA
    fb9a1ae View commit details
  20. Copy the full SHA
    e7599a1 View commit details
  21. Copy the full SHA
    e355e11 View commit details

Commits on Aug 11, 2015

  1. Copy the full SHA
    9927bde View commit details
  2. make sure package modules (at leat) respond_to? :name

    ... they still won't correctly return a String name, due compatibility that likely will only happen on 9K
    
    fixes #2468
    kares committed Aug 11, 2015
    Copy the full SHA
    0d452ee View commit details
  3. facelift some JI specs a bit

    kares committed Aug 11, 2015
    Copy the full SHA
    e585b48 View commit details
  4. Copy the full SHA
    903cd96 View commit details
  5. JavaPackageModuleTemplate should handle respond_to? :name as well

    ... since its counted among `ObjectSpace.each_object(Module)` (#2468)
    kares committed Aug 11, 2015
    Copy the full SHA
    ce8c075 View commit details
  6. Copy the full SHA
    a35930a View commit details
  7. Unbreak indy

    enebo committed Aug 11, 2015
    Copy the full SHA
    a373306 View commit details
  8. Copy the full SHA
    62d513e View commit details
  9. Copy the full SHA
    7b3547e View commit details
  10. Copy the full SHA
    df1a4f2 View commit details
  11. [Truffle] Convert int-fitting long values back to ints when predefine…

    …d int property is being assigned
    
    Only for few ivars in IOBuffer and IO class.
    pitr-ch committed Aug 11, 2015
    Copy the full SHA
    38fd1c9 View commit details
  12. Copy the full SHA
    03ea799 View commit details
  13. Copy the full SHA
    48ad16e View commit details
  14. Revert "[Truffle] skip mri test ruby/test_not.rb which causes parsing…

    … error"
    
    This reverts commit 03ea799.
    pitr-ch committed Aug 11, 2015
    Copy the full SHA
    488cf2e View commit details

Commits on Aug 12, 2015

  1. Merge branch 'jruby-1_7'

    * jruby-1_7:
      more specs - as package_name actually works as is with Java proxy modules
      JavaPackageModuleTemplate should handle respond_to? :name as well
      allow object_id to work correctly for Java package modules
      facelift some JI specs a bit
      make sure package modules (at leat) respond_to? :name
      missing hashCode to go along equals in RespondToMissingMethod
      [build] no more torquebox repo
      add missing file
    
    Conflicts:
    	core/src/main/java/org/jruby/RubyModule.java
    	core/src/main/java/org/jruby/java/util/BlankSlateWrapper.java
    	lib/pom.rb
    	lib/pom.xml
    	maven/jruby-complete/pom.rb
    	maven/jruby-complete/pom.xml
    	maven/jruby-complete/src/templates/osgi_many_bundles_with_embedded_gems/gems-bundle/pom.xml
    	maven/jruby-dist/pom.xml
    	maven/jruby-jars/pom.xml
    	maven/jruby/src/it/j2ee_jetty/pom.xml
    	maven/jruby/src/it/j2ee_jetty_rack/pom.xml
    	maven/jruby/src/it/j2ee_tomcat/pom.xml
    	maven/jruby/src/it/j2ee_tomcat_rack/pom.xml
    	maven/jruby/src/it/j2ee_wildfly/pom.xml
    	maven/jruby/src/it/jetty/pom.xml
    	maven/jruby/src/it/many_jars_with_embedded_gems/zip_gem/pom.xml
    	maven/jruby/src/it/many_jars_with_embedded_gems_ng/gem1/pom.xml
    	maven/jruby/src/it/many_jars_with_embedded_gems_ng/gem2/pom.xml
    	maven/jruby/src/it/runnable/pom.xml
    	maven/jruby/src/it/tomcat/pom.xml
    	maven/jruby/src/templates/j2ee_wlp/pom.xml
    	maven/jruby/src/templates/osgi_all_inclusive/pom.xml
    	spec/java_integration/packages/access_spec.rb
    	test/pom.rb
    	test/pom.xml
    kares committed Aug 12, 2015
    Copy the full SHA
    a14c8b8 View commit details
  2. Copy the full SHA
    35aa6dd View commit details
  3. Copy the full SHA
    cc1b48f View commit details
  4. Merge pull request #3238 from kubum/bubblebabble

    Fix Digest bubblebabble incorrect output on empty string
    chrisseaton committed Aug 12, 2015
    Copy the full SHA
    5e3e186 View commit details
  5. Add missing license header

    pitr-ch committed Aug 12, 2015
    Copy the full SHA
    eb6f35d View commit details

Commits on Aug 13, 2015

  1. Copy the full SHA
    3adbb68 View commit details
  2. Merge pull request #3250 from frsyuki/fix-jruby-jars-url

    Fix homepage of jruby-jars.gemspec
    mkristian committed Aug 13, 2015
    Copy the full SHA
    af7f58f View commit details

Commits on Aug 14, 2015

  1. manually filter out matching callables with non-matching arguments le…

    …ngth
    
    ... this is necessary as the find logic matches argument by argument possibly leaving matches with arity > args.length
    
    fixes #2923
    
    p.s. possibly we still do not handle var-args well
    kares committed Aug 14, 2015
    Copy the full SHA
    bb98593 View commit details
  2. Add direct BubbleBabble power from OpenSSH

    cheald authored and kares committed Aug 14, 2015
    Copy the full SHA
    679b2e3 View commit details
  3. Copy the full SHA
    80c3599 View commit details
  4. Fix Digest bubblebabble incorrect output on empty string

    Before:
    
    bin/jruby -rdigest -e "p Digest.bubblebabble ''"
    "xx"
    
    After:
    
    bin/jruby -rdigest -e "p Digest.bubblebabble ''"
    "xexax"
    kubum authored and kares committed Aug 14, 2015
    Copy the full SHA
    532fa14 View commit details
  5. make require 'digest/bubblebabble' work (MRI compatibility)

    ... Digest.bubblebabble is being defined on require 'digest'
    kares committed Aug 14, 2015
    Copy the full SHA
    79a9581 View commit details

Commits on Aug 15, 2015

  1. Copy the full SHA
    f05e55d View commit details
  2. Copy the full SHA
    236bfb3 View commit details
Showing with 924 additions and 670 deletions.
  1. +11 −4 core/src/main/java/org/jruby/RubyModule.java
  2. +7 −0 core/src/main/java/org/jruby/ext/digest/BubbleBabble.java
  3. +79 −74 core/src/main/java/org/jruby/ext/digest/RubyDigest.java
  4. +1 −1 core/src/main/java/org/jruby/ir/targets/Bootstrap.java
  5. +14 −1 core/src/main/java/org/jruby/java/dispatch/CallableSelector.java
  6. +1 −1 core/src/main/java/org/jruby/java/proxies/JavaInterfaceTemplate.java
  7. +147 −6 core/src/main/java/org/jruby/java/proxies/JavaProxy.java
  8. +6 −5 core/src/main/java/org/jruby/java/util/BlankSlateWrapper.java
  9. +11 −160 core/src/main/java/org/jruby/javasupport/Java.java
  10. +9 −0 core/src/main/java/org/jruby/javasupport/JavaConstructor.java
  11. +2 −0 core/src/main/java/org/jruby/parser/ParserSupport.java
  12. +1 −1 core/src/main/java/org/jruby/runtime/Helpers.java
  13. +19 −31 core/src/main/java/org/jruby/runtime/backtrace/BacktraceData.java
  14. +20 −13 core/src/main/java/org/jruby/runtime/backtrace/FrameType.java
  15. +36 −43 core/src/main/java/org/jruby/util/JRubyFile.java
  16. +141 −133 core/src/main/java/org/jruby/util/JavaNameMangler.java
  17. +6 −2 core/src/main/ruby/jruby/java/java_package_module_template.rb
  18. +1 −0 lib/ruby/stdlib/digest/digest/bubblebabble.rb
  19. +8 −0 lib/ruby/truffle/truffle/bigdecimal.rb
  20. +7 −3 maven/jruby-complete/pom.rb
  21. +1 −0 maven/jruby-complete/src/it/integrity/bin/me
  22. +2 −3 maven/jruby-complete/src/templates/osgi_many_bundles_with_embedded_gems/gems-bundle/pom.rb
  23. +1 −1 maven/jruby-jars/jruby-jars.gemspec
  24. +1 −1 maven/jruby/src/it/jetty/Mavenfile
  25. +2 −3 maven/jruby/src/it/many_jars_with_embedded_gems/zip_gem/pom.rb
  26. +1 −1 maven/jruby/src/it/many_jars_with_embedded_gems_ng/gem1/pom.rb
  27. +1 −1 maven/jruby/src/it/many_jars_with_embedded_gems_ng/gem2/pom.rb
  28. +2 −3 maven/jruby/src/it/runnable/Mavenfile
  29. +2 −3 maven/jruby/src/templates/osgi_all_inclusive/pom.rb
  30. +79 −0 spec/java_integration/interfaces/java8_methods_spec.rb
  31. +0 −37 spec/java_integration/interfaces/static_methods_spec.rb
  32. +8 −0 spec/java_integration/methods/java_send_spec.rb
  33. +7 −6 spec/java_integration/packages/access_spec.rb
  34. +1 −1 spec/java_integration/packages/include_spec.rb
  35. +53 −0 spec/java_integration/packages/name_spec.rb
  36. +3 −3 spec/java_integration/rubygems/rubygems_spec.rb
  37. +5 −0 spec/java_integration/types/array_spec.rb
  38. +4 −0 spec/ruby/core/module/const_get_spec.rb
  39. +3 −0 spec/ruby/fixtures/constants.rb
  40. +1 −1 spec/ruby/library/socket/tcpserver/new_spec.rb
  41. +0 −3 spec/truffle/tags/core/thread/list_tags.txt
  42. +0 −4 spec/truffle/tags/language/yield_tags.txt
  43. +98 −75 test/jruby/test_backtraces.rb
  44. +1 −0 test/mri.index
  45. +21 −0 test/org/jruby/javasupport/test/ThrowingRunnable.java
  46. +4 −4 test/pom.rb
  47. +1 −1 truffle/pom.rb
  48. +3 −3 truffle/pom.xml
  49. +16 −9 truffle/src/main/java/org/jruby/truffle/nodes/constants/LookupConstantNode.java
  50. +2 −2 truffle/src/main/java/org/jruby/truffle/nodes/constants/ReadConstantNode.java
  51. +1 −2 truffle/src/main/java/org/jruby/truffle/nodes/constants/ReadLiteralConstantNode.java
  52. +4 −5 truffle/src/main/java/org/jruby/truffle/nodes/core/ModuleNodes.java
  53. +14 −0 truffle/src/main/java/org/jruby/truffle/nodes/core/ThreadNodes.java
  54. +36 −17 truffle/src/main/java/org/jruby/truffle/nodes/core/array/ArrayBuilderNode.java
  55. +1 −1 truffle/src/main/java/org/jruby/truffle/nodes/ext/BigDecimalNodes.java
  56. +4 −0 truffle/src/main/java/org/jruby/truffle/runtime/subsystems/ThreadManager.java
  57. +14 −2 truffle/src/main/java/org/jruby/truffle/translator/BodyTranslator.java
15 changes: 11 additions & 4 deletions core/src/main/java/org/jruby/RubyModule.java
Original file line number Diff line number Diff line change
@@ -1703,14 +1703,21 @@ public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule claz
return site.call(context, self, self, args, block);
}

@Override
public boolean equals(Object other) {
if (!(other instanceof RespondToMissingMethod)) return false;
if ( ! (other instanceof RespondToMissingMethod) ) return false;

RespondToMissingMethod rtmm = (RespondToMissingMethod)other;
RespondToMissingMethod that = (RespondToMissingMethod) other;

return this.site.methodName.equals(rtmm.site.methodName) &&
isImplementedBy(rtmm.getImplementationClass());
return this.site.methodName.equals(that.site.methodName) &&
isImplementedBy(that.getImplementationClass());
}

@Override
public int hashCode() {
return /* getImplementationClass().hashCode() + */ 7 * this.site.methodName.hashCode();
}

}

public IRubyObject newMethod(IRubyObject receiver, final String methodName, boolean bound, Visibility visibility, boolean respondToMissing, boolean priv) {
7 changes: 7 additions & 0 deletions core/src/main/java/org/jruby/ext/digest/BubbleBabble.java
Original file line number Diff line number Diff line change
@@ -65,6 +65,13 @@ public static ByteList bubblebabble(byte[] message, int begin, int length) {
((((int) (message[begin + 2 * i])) * 7) +
((int) (message[begin + (2 * i) + 1])))) % 36;
}
} else {
idx0 = seed % 6;
idx1 = 16;
idx2 = seed / 6;
retval.append(vowels[idx0]);
retval.append(consonants[idx1]);
retval.append(vowels[idx2]);
}
}
retval.append('x');
153 changes: 79 additions & 74 deletions core/src/main/java/org/jruby/ext/digest/RubyDigest.java
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@
* Copyright (C) 2007 Nick Sieger <nicksieger@gmail.com>
* Copyright (C) 2008 Vladimir Sizikov <vsizikov@gmail.com>
* Copyright (C) 2009 Joseph LaFata <joe@quibb.org>
*
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
@@ -50,48 +50,47 @@
import org.jruby.anno.JRubyClass;
import org.jruby.anno.JRubyMethod;
import org.jruby.anno.JRubyModule;
import org.jruby.exceptions.RaiseException;
import org.jruby.runtime.Block;
import org.jruby.runtime.ObjectAllocator;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.Visibility;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.util.ByteList;
import org.jruby.util.log.Logger;
import org.jruby.util.log.LoggerFactory;

/**
* @author <a href="mailto:ola.bini@ki.se">Ola Bini</a>
*/
@JRubyModule(name="Digest")
public class RubyDigest {
private static Provider provider = null;
private static final Map<String, MessageDigest> CLONEABLE_DIGESTS = new HashMap<String, MessageDigest>();

private static final Map<String, MessageDigest> CLONEABLE_DIGESTS = new HashMap<String, MessageDigest>(8, 1);
static {
// standard digests from JCA specification; if we can retrieve and clone, save them
for (String name : new String[] {"MD2", "MD5", "SHA-1", "SHA-256", "SHA-384", "SHA-512"})
try {
MessageDigest digest = MessageDigest.getInstance(name);
digest.clone();
CLONEABLE_DIGESTS.put(name, digest);
} catch (Exception e) {
e.printStackTrace();
// ignore; go to next iteration
for (String name : new String[] {"MD2", "MD5", "SHA-1", "SHA-256", "SHA-384", "SHA-512"}) {
try {
MessageDigest digest = MessageDigest.getInstance(name);
digest.clone();
CLONEABLE_DIGESTS.put(name, digest);
}
catch (Exception e) {
logger().debug(name + " not clonable", e);
}
}
}

private static Logger logger() { return LoggerFactory.getLogger("RubyDigest"); }

private static final String PROVIDER = "org.bouncycastle.jce.provider.BouncyCastleProvider";
private static Provider provider = null;

public static void createDigest(Ruby runtime) {
// We're not setting the provider or anything, but it seems that BouncyCastle does some internal things in its
// provider's constructor which require it to be executed in a secure context.
// Ideally this hack should be removed. See JRUBY-3919 and this BC bug:
// http://www.bouncycastle.org/jira/browse/BJA-227
provider = (Provider) AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
try {
return Class.forName("org.bouncycastle.jce.provider.BouncyCastleProvider").newInstance();
} catch(Throwable t) {
// provider is not available
return null;
}
}
});
try {
provider = (Provider) Class.forName(PROVIDER).newInstance();
}
catch (Throwable t) { /* provider is not available */ }

RubyModule mDigest = runtime.defineModule("Digest");
mDigest.defineAnnotatedMethods(RubyDigest.class);
@@ -104,27 +103,29 @@ public Object run() {
cDigestBase.defineAnnotatedMethods(DigestBase.class);
}

private static MessageDigest createMessageDigest(Ruby runtime, String providerName) throws NoSuchAlgorithmException {
MessageDigest cloneable = CLONEABLE_DIGESTS.get(providerName);
private static MessageDigest createMessageDigest(final String name) throws NoSuchAlgorithmException {
MessageDigest cloneable = CLONEABLE_DIGESTS.get(name);
if (cloneable != null) {
try {
return (MessageDigest)cloneable.clone();
} catch (CloneNotSupportedException cnse) {
return (MessageDigest) cloneable.clone();
}
catch (CloneNotSupportedException e) {
// should never happen, since we tested it in static init
}
}

// fall back on JCA mechanisms for getting a digest
if(provider != null) {
if (provider != null) {
try {
return MessageDigest.getInstance(providerName, provider);
} catch(NoSuchAlgorithmException e) {
return MessageDigest.getInstance(name, provider);
}
catch (NoSuchAlgorithmException e) {
// bouncy castle doesn't support algorithm
}
}

// fall back to default JCA providers
return MessageDigest.getInstance(providerName);
return MessageDigest.getInstance(name);
}

private final static byte[] digits = {
@@ -146,17 +147,17 @@ private static ByteList toHex(byte[] val) {
return byteList;
}

private static IRubyObject toHexString(Ruby runtime, byte[] val) {
private static RubyString toHexString(Ruby runtime, byte[] val) {
return RubyString.newStringNoCopy(runtime, new ByteList(ByteList.plain(toHex(val)), USASCIIEncoding.INSTANCE));
}

@JRubyMethod(name = "hexencode", required = 1, meta = true)
public static IRubyObject s_hexencode(IRubyObject recv, IRubyObject arg) {
return toHexString(recv.getRuntime(), arg.convertToString().getBytes());
public static RubyString hexencode(IRubyObject self, IRubyObject arg) {
return toHexString(self.getRuntime(), arg.convertToString().getBytes());
}

@JRubyMethod(name = "bubblebabble", required = 1, meta = true)
public static IRubyObject bubblebabble(IRubyObject recv, IRubyObject arg) {
public static RubyString bubblebabble(IRubyObject recv, IRubyObject arg) {
final ByteList bytes = arg.convertToString().getByteList();
return RubyString.newString(recv.getRuntime(), BubbleBabble.bubblebabble(bytes.unsafeBytes(), bytes.begin(), bytes.length()));
}
@@ -196,47 +197,49 @@ public static class SHA512 {}

public static void createDigestMD5(Ruby runtime) {
runtime.getLoadService().require("digest");
RubyModule mDigest = runtime.getModule("Digest");
RubyClass cDigestBase = mDigest.getClass("Base");
RubyClass cDigest_MD5 = mDigest.defineClassUnder("MD5",cDigestBase,cDigestBase.getAllocator());
cDigest_MD5.setInternalVariable("metadata", new Metadata("MD5", 64));
RubyModule Digest = runtime.getModule("Digest");
RubyClass Base = Digest.getClass("Base");
RubyClass MD5 = Digest.defineClassUnder("MD5", Base, Base.getAllocator());
MD5.setInternalVariable("metadata", new Metadata("MD5", 64));
}

public static void createDigestRMD160(Ruby runtime) {
runtime.getLoadService().require("digest");
if(provider == null) {
throw runtime.newLoadError("RMD160 not supported without BouncyCastle");
}
RubyModule mDigest = runtime.getModule("Digest");
RubyClass cDigestBase = mDigest.getClass("Base");
RubyClass cDigest_RMD160 = mDigest.defineClassUnder("RMD160",cDigestBase,cDigestBase.getAllocator());
cDigest_RMD160.setInternalVariable("metadata", new Metadata("RIPEMD160", 64));
RubyModule Digest = runtime.getModule("Digest");
RubyClass Base = Digest.getClass("Base");
RubyClass RMD160 = Digest.defineClassUnder("RMD160", Base, Base.getAllocator());
RMD160.setInternalVariable("metadata", new Metadata("RIPEMD160", 64));
}

public static void createDigestSHA1(Ruby runtime) {
runtime.getLoadService().require("digest");
RubyModule mDigest = runtime.getModule("Digest");
RubyClass cDigestBase = mDigest.getClass("Base");
RubyClass cDigest_SHA1 = mDigest.defineClassUnder("SHA1",cDigestBase,cDigestBase.getAllocator());
cDigest_SHA1.setInternalVariable("metadata", new Metadata("SHA1", 64));
RubyModule Digest = runtime.getModule("Digest");
RubyClass Base = Digest.getClass("Base");
RubyClass SHA1 = Digest.defineClassUnder("SHA1", Base, Base.getAllocator());
SHA1.setInternalVariable("metadata", new Metadata("SHA1", 64));
}

public static void createDigestSHA2(Ruby runtime) {
runtime.getLoadService().require("digest");
try {
createMessageDigest(runtime, "SHA-256");
} catch(NoSuchAlgorithmException e) {
throw runtime.newLoadError("SHA2 not supported");
}
RubyModule mDigest = runtime.getModule("Digest");
RubyClass cDigestBase = mDigest.getClass("Base");
RubyClass cDigest_SHA2_256 = mDigest.defineClassUnder("SHA256",cDigestBase,cDigestBase.getAllocator());
Metadata sha256Metadata = new Metadata("SHA-256", 64);
cDigest_SHA2_256.setInternalVariable("metadata", sha256Metadata);
RubyClass cDigest_SHA2_384 = mDigest.defineClassUnder("SHA384",cDigestBase,cDigestBase.getAllocator());
cDigest_SHA2_384.setInternalVariable("metadata", new Metadata("SHA-384", 128));
RubyClass cDigest_SHA2_512 = mDigest.defineClassUnder("SHA512",cDigestBase,cDigestBase.getAllocator());
cDigest_SHA2_512.setInternalVariable("metadata", new Metadata("SHA-512", 128));
createMessageDigest("SHA-256");
}
catch (NoSuchAlgorithmException e) {
RaiseException ex = runtime.newLoadError("SHA2 not supported");
ex.initCause(e);
throw ex;
}
final RubyModule Digest = runtime.getModule("Digest");
final RubyClass Base = Digest.getClass("Base");
RubyClass SHA256 = Digest.defineClassUnder("SHA256", Base, Base.getAllocator());
SHA256.setInternalVariable("metadata", new Metadata("SHA-256", 64));
RubyClass SHA384 = Digest.defineClassUnder("SHA384", Base, Base.getAllocator());
SHA384.setInternalVariable("metadata", new Metadata("SHA-384", 128));
RubyClass SHA512 = Digest.defineClassUnder("SHA512", Base, Base.getAllocator());
SHA512.setInternalVariable("metadata", new Metadata("SHA-512", 128));
}

@JRubyModule(name = "Digest::Instance")
@@ -303,7 +306,7 @@ public static IRubyObject newObject(ThreadContext context, IRubyObject self) {

@JRubyMethod(optional = 1)
public static IRubyObject digest(ThreadContext context, IRubyObject self, IRubyObject[] args) {
IRubyObject value = null;
final IRubyObject value;
if (args != null && args.length > 0) {
self.callMethod(context, "reset");
self.callMethod(context, "update", args[0]);
@@ -363,7 +366,7 @@ public IRubyObject allocate(Ruby runtime, RubyClass klass) {
public DigestClass(Ruby runtime, RubyClass type) {
super(runtime, type);
}

@JRubyMethod(name = "digest", required = 1, rest = true, meta = true)
public static IRubyObject s_digest(ThreadContext context, IRubyObject recv, IRubyObject[] args, Block unusedBlock) {
Ruby runtime = recv.getRuntime();
@@ -408,7 +411,7 @@ public DigestBase(Ruby runtime, RubyClass type) {
if(metadata == null) {
throw runtime.newNotImplementedError("the " + type + "() function is unimplemented on this machine");
}

try {
setAlgorithm(metadata);
} catch(NoSuchAlgorithmException e) {
@@ -431,15 +434,16 @@ private Metadata getMetadata(RubyModule type) {
@JRubyMethod(required = 1, visibility = Visibility.PRIVATE)
@Override
public IRubyObject initialize_copy(IRubyObject obj) {
if(this == obj) {
return this;
}
((RubyObject)obj).checkFrozen();
if (this == obj) return this;

DigestBase from = (DigestBase) obj;
from.checkFrozen();

String name = ((DigestBase)obj).algo.getAlgorithm();
try {
algo = (MessageDigest)((DigestBase)obj).algo.clone();
} catch(CloneNotSupportedException e) {
this.algo = (MessageDigest) from.algo.clone();
}
catch (CloneNotSupportedException e) {
String name = from.algo.getAlgorithm();
throw getRuntime().newTypeError("Could not initialize copy of digest (" + name + ")");
}
return this;
@@ -458,7 +462,7 @@ public IRubyObject finish() {
algo.reset();
return digest;
}

@JRubyMethod()
public IRubyObject digest_length() {
return RubyFixnum.newFixnum(getRuntime(), algo.getDigestLength());
@@ -486,8 +490,9 @@ public IRubyObject bubblebabble(ThreadContext context) {
}

private void setAlgorithm(Metadata metadata) throws NoSuchAlgorithmException {
this.algo = createMessageDigest(getRuntime(), metadata.getName());
this.algo = createMessageDigest(metadata.getName());
this.blockLength = metadata.getBlockLength();
}

}
}// RubyDigest
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/ir/targets/Bootstrap.java
Original file line number Diff line number Diff line change
@@ -422,7 +422,7 @@ static MethodHandle buildNativeHandle(InvokeSite site, DynamicMethod method, boo
MethodHandle mh = null;
SmartBinder binder = null;

if (method instanceof NativeCallMethod) {
if (method instanceof NativeCallMethod && ((NativeCallMethod) method).getNativeCall() != null) {
NativeCallMethod nativeMethod = (NativeCallMethod)method;
DynamicMethod.NativeCall nativeCall = nativeMethod.getNativeCall();

15 changes: 14 additions & 1 deletion core/src/main/java/org/jruby/java/dispatch/CallableSelector.java
Original file line number Diff line number Diff line change
@@ -185,6 +185,7 @@ private static <T extends ParameterTypes> T findMatchingCallableForArgs(final Ru
final T candidate = candidates.get(c);
final Class<?>[] cTypes = candidate.getParameterTypes();

// TODO still need to handle var-args better Class<?> lastType;
for ( int i = 0; i < msTypes.length; i++ ) {
final Class<?> msType = msTypes[i], cType = cTypes[i];
if ( msType != cType && msType.isAssignableFrom(cType) ) {
@@ -375,7 +376,19 @@ private static <T extends ParameterTypes> List<T> findCallableCandidates(final T
incoming = retained.toArray( new ParameterTypes[retained.size()] );
}

return retained;
// final step rule out argument length mismatch :
int j = 0; for ( int i = 0; i < retained.size(); i++ ) {
T callable = retained.get(i);
if ( callable.isVarArgs() ) {
if ( callable.getArity() > args.length - 1 ) continue;
}
else {
if ( callable.getArity() != args.length ) continue;
}
retained.set(j++, callable);
}

return j < retained.size() ? retained.subList(0, j) : retained;
}

private static int calcExactnessScore(final ParameterTypes callable, final IRubyObject[] args) {
Original file line number Diff line number Diff line change
@@ -37,7 +37,7 @@ public static RubyModule createJavaInterfaceTemplateModule(ThreadContext context
singleton.addReadAttribute(context, "java_class");
singleton.defineAnnotatedMethods(JavaInterfaceTemplate.class);

JavaInterfaceTemplate.defineAnnotatedMethods(Java.JavaProxyClassMethods.class);
JavaInterfaceTemplate.defineAnnotatedMethods(JavaProxy.ClassMethods.class);

return JavaInterfaceTemplate;
}
Loading