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: f7491ac839f0^
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: ffc510f3b1b1
Choose a head ref
  • 15 commits
  • 57 files changed
  • 1 contributor

Commits on Jan 4, 2018

  1. Doco.

    headius committed Jan 4, 2018
    Copy the full SHA
    f7491ac View commit details
  2. Copy the full SHA
    45e1b37 View commit details
  3. Another fixed typo in specs.

    headius committed Jan 4, 2018
    Copy the full SHA
    6cd8f64 View commit details
  4. Copy the full SHA
    2b8b819 View commit details

Commits on Jan 5, 2018

  1. Align logic across all binders.

    The populators generateed by AnnotationBinder are usually the ones
    executed at startup, but when --debug is passed, we fall back on
    a generic populator. This logic did not have appropriate code to
    update the method frame reads and writes in MethodIndex, and as a
    result our --debug test runs (test:mri, spec:ruby) failed to set
    up frames for methods that needed them.
    
    This change re-aligns AnnotationBinder and the logic in RubyModule
    as well as IndyBinder, but there's still a lot of duplication here
    and potential for mistakes.
    headius committed Jan 5, 2018
    Copy the full SHA
    3602f90 View commit details
  2. Copy the full SHA
    4ad5569 View commit details
  3. Copy the full SHA
    7130fac View commit details
  4. Copy the full SHA
    825c755 View commit details
  5. Fix File.readlink encoding.

    headius committed Jan 5, 2018
    Copy the full SHA
    239c726 View commit details
  6. Copy the full SHA
    6e2b700 View commit details
  7. Copy the full SHA
    13a277c View commit details
  8. Copy the full SHA
    c575281 View commit details
  9. Another spec typo.

    headius committed Jan 5, 2018
    Copy the full SHA
    464f9fb View commit details
  10. Copy the full SHA
    bc56ff9 View commit details
  11. Copy the full SHA
    ffc510f View commit details
Showing with 271 additions and 298 deletions.
  1. +1 −1 core/pom.rb
  2. +1 −1 core/pom.xml
  3. +6 −1 core/src/main/java/org/jruby/CompatVersion.java
  4. +20 −2 core/src/main/java/org/jruby/Ruby.java
  5. +15 −3 core/src/main/java/org/jruby/RubyComplex.java
  6. +1 −1 core/src/main/java/org/jruby/RubyFile.java
  7. +19 −24 core/src/main/java/org/jruby/RubyIO.java
  8. +9 −9 core/src/main/java/org/jruby/RubyInstanceConfig.java
  9. +1 −1 core/src/main/java/org/jruby/RubyKernel.java
  10. +11 −50 core/src/main/java/org/jruby/RubyModule.java
  11. +1 −2 core/src/main/java/org/jruby/RubyNumeric.java
  12. +41 −31 core/src/main/java/org/jruby/anno/AnnotationBinder.java
  13. +11 −50 core/src/main/java/org/jruby/anno/IndyBinder.java
  14. +14 −15 core/src/main/java/org/jruby/anno/JRubyMethod.java
  15. +7 −0 core/src/main/java/org/jruby/anno/TypePopulator.java
  16. +6 −5 core/src/main/java/org/jruby/embed/EmbedRubyInstanceConfigAdapter.java
  17. +9 −12 core/src/main/java/org/jruby/embed/ScriptingContainer.java
  18. +0 −1 core/src/main/java/org/jruby/ext/thread/Mutex.java
  19. +0 −2 core/src/main/java/org/jruby/ext/zlib/RubyZlib.java
  20. +14 −0 core/src/main/java/org/jruby/ir/IRFlags.java
  21. +4 −0 core/src/main/java/org/jruby/ir/instructions/BlockGivenInstr.java
  22. +21 −12 core/src/main/java/org/jruby/ir/instructions/CallBase.java
  23. +1 −2 core/src/main/java/org/jruby/management/Config.java
  24. +29 −25 core/src/main/java/org/jruby/runtime/MethodIndex.java
  25. +1 −11 core/src/main/java/org/jruby/runtime/encoding/EncodingService.java
  26. +0 −3 core/src/main/java/org/jruby/util/cli/OutputStrings.java
  27. +0 −2 core/src/test/java/org/jruby/test/TestEncodingAPI.java
  28. +0 −21 core/src/test/java/org/jruby/test/TestMethodFactories.java
  29. +0 −2 core/src/test/java/org/jruby/test/TestRecursiveCheck.java
  30. +0 −2 core/src/test/java/org/jruby/test/TestRubyBase.java
  31. +0 −5 core/src/test/java/org/jruby/test/TestRubyRational.java
  32. +1 −0 spec/tags/ruby/core/float/divide_tags.txt
  33. +1 −0 spec/tags/ruby/core/float/minus_tags.txt
  34. +1 −0 spec/tags/ruby/core/float/multiply_tags.txt
  35. +1 −0 spec/tags/ruby/core/float/plus_tags.txt
  36. +1 −0 spec/tags/ruby/core/integer/divide_tags.txt
  37. +1 −0 spec/tags/ruby/core/integer/minus_tags.txt
  38. +1 −0 spec/tags/ruby/core/integer/multiply_tags.txt
  39. +1 −0 spec/tags/ruby/core/integer/plus_tags.txt
  40. +3 −0 spec/tags/ruby/core/module/refine_tags.txt
  41. +1 −0 spec/tags/ruby/core/module/using_tags.txt
  42. +1 −0 spec/tags/ruby/core/rational/comparison_tags.txt
  43. +1 −0 spec/tags/ruby/core/rational/divide_tags.txt
  44. +1 −0 spec/tags/ruby/core/rational/minus_tags.txt
  45. +1 −0 spec/tags/ruby/core/rational/multiply_tags.txt
  46. +1 −0 spec/tags/ruby/core/rational/plus_tags.txt
  47. +1 −0 spec/tags/ruby/core/rational/round_tags.txt
  48. +1 −0 spec/tags/ruby/language/magic_comment_tags.txt
  49. +1 −0 spec/tags/ruby/language/regexp/character_classes_tags.txt
  50. +1 −0 spec/tags/ruby/language/regexp/modifiers_tags.txt
  51. +1 −0 spec/tags/ruby/language/send_tags.txt
  52. +1 −0 spec/tags/ruby/language/string_tags.txt
  53. +1 −0 spec/tags/ruby/language/symbol_tags.txt
  54. +1 −0 spec/tags/ruby/library/set/compare_by_identity_tags.txt
  55. +1 −0 spec/tags/ruby/library/socket/ipsocket/peeraddr_tags.txt
  56. +1 −1 spec/tags/ruby/library/socket/unixsocket/peeraddr_tags.txt
  57. +1 −1 spec/tags/ruby/library/yaml/to_yaml_tags.txt
2 changes: 1 addition & 1 deletion core/pom.rb
Original file line number Diff line number Diff line change
@@ -46,7 +46,7 @@
jar 'com.github.jnr:jnr-enxio:0.16', :exclusions => ['com.github.jnr:jnr-ffi']
jar 'com.github.jnr:jnr-x86asm:1.0.2', :exclusions => ['com.github.jnr:jnr-ffi']
jar 'com.github.jnr:jnr-unixsocket:0.17', :exclusions => ['com.github.jnr:jnr-ffi']
jar 'com.github.jnr:jnr-posix:3.0.42', :exclusions => ['com.github.jnr:jnr-ffi']
jar 'com.github.jnr:jnr-posix:3.0.43', :exclusions => ['com.github.jnr:jnr-ffi']
jar 'com.github.jnr:jnr-constants:0.9.9', :exclusions => ['com.github.jnr:jnr-ffi']
jar 'com.github.jnr:jnr-ffi:2.1.7'
jar 'com.github.jnr:jffi:${jffi.version}'
2 changes: 1 addition & 1 deletion core/pom.xml
Original file line number Diff line number Diff line change
@@ -135,7 +135,7 @@ DO NOT MODIFIY - GENERATED CODE
<dependency>
<groupId>com.github.jnr</groupId>
<artifactId>jnr-posix</artifactId>
<version>3.0.42</version>
<version>3.0.43</version>
<exclusions>
<exclusion>
<artifactId>jnr-ffi</artifactId>
7 changes: 6 additions & 1 deletion core/src/main/java/org/jruby/CompatVersion.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.jruby;

@Deprecated
public enum CompatVersion {

@Deprecated RUBY1_8,
@@ -8,14 +9,17 @@ public enum CompatVersion {
@Deprecated RUBY2_1,
@Deprecated BOTH;

@Deprecated
public boolean is1_9() {
return this == RUBY1_9 || this == RUBY2_0 || this == RUBY2_1;
}

@Deprecated
public boolean is2_0() {
return this == RUBY2_0 || this == RUBY2_1;
}

@Deprecated
public static CompatVersion getVersionFromString(String compatString) {
if (compatString.equalsIgnoreCase("RUBY1_8")) {
return CompatVersion.RUBY1_8;
@@ -37,7 +41,8 @@ public static CompatVersion getVersionFromString(String compatString) {
return null;
}
}


@Deprecated
public static boolean shouldBindMethod(CompatVersion runtimeVersion, CompatVersion methodVersion) {
if (runtimeVersion == RUBY1_8) return methodVersion == RUBY1_8 || methodVersion == BOTH;
if (runtimeVersion == RUBY1_9) return methodVersion == RUBY1_9 || methodVersion == BOTH;
22 changes: 20 additions & 2 deletions core/src/main/java/org/jruby/Ruby.java
Original file line number Diff line number Diff line change
@@ -1439,6 +1439,16 @@ private void initCore() {
setDefaultExternalEncoding(availableEncoding);
}

// Filesystem should always have a value
if (Platform.IS_WINDOWS) {
encoding = SafePropertyAccessor.getProperty("file.encoding", "UTF-8");
Encoding filesystemEncoding = encodingService.loadEncoding(ByteList.create(encoding));
if (filesystemEncoding == null) throw new MainExitException(1, "unknown encoding name - " + encoding);
setDefaultFilesystemEncoding(filesystemEncoding);
} else {
setDefaultFilesystemEncoding(getDefaultExternalEncoding());
}

encoding = config.getInternalEncoding();
if (encoding != null && !encoding.equals("")) {
Encoding loadedEncoding = encodingService.loadEncoding(ByteList.create(encoding));
@@ -1596,7 +1606,7 @@ private void initExceptions() {
syntaxError = defineClassIfAllowed("SyntaxError", scriptError);
loadError = defineClassIfAllowed("LoadError", scriptError);
notImplementedError = defineClassIfAllowed("NotImplementedError", scriptError);
securityError = defineClassIfAllowed("SecurityError", standardError);
securityError = defineClassIfAllowed("SecurityError", exceptionClass);
noMemoryError = defineClassIfAllowed("NoMemoryError", exceptionClass);
regexpError = defineClassIfAllowed("RegexpError", standardError);
interruptedRegexpError = defineClassIfAllowed("InterruptedRegexpError", regexpError); // Proposal to RubyCommons for interrupting Regexps
@@ -2799,6 +2809,14 @@ public void setDefaultExternalEncoding(Encoding defaultExternalEncoding) {
this.defaultExternalEncoding = defaultExternalEncoding;
}

public Encoding getDefaultFilesystemEncoding() {
return defaultFilesystemEncoding;
}

public void setDefaultFilesystemEncoding(Encoding defaultFilesystemEncoding) {
this.defaultFilesystemEncoding = defaultFilesystemEncoding;
}

/**
* Get the default java.nio.charset.Charset for the current default internal encoding.
*/
@@ -5006,7 +5024,7 @@ private MRIRecursionGuard oldRecursionGuard() {

private LoadService loadService;

private Encoding defaultInternalEncoding, defaultExternalEncoding;
private Encoding defaultInternalEncoding, defaultExternalEncoding, defaultFilesystemEncoding;
private EncodingService encodingService;

private GlobalVariables globalVariables = new GlobalVariables(this);
18 changes: 15 additions & 3 deletions core/src/main/java/org/jruby/RubyComplex.java
Original file line number Diff line number Diff line change
@@ -988,17 +988,29 @@ public IRubyObject rationalize(ThreadContext context, IRubyObject[] args) {
@JRubyMethod(name = "finite?")
@Override
public IRubyObject finite_p(ThreadContext context) {
if (checkFinite(context, real) && checkFinite(context, image)) {
return context.tru;
}
return context.fals;
}

// MRI: f_finite_p
public boolean checkFinite(ThreadContext context, IRubyObject value) {
IRubyObject magnitude = magnitude(context);

if (magnitude instanceof RubyInteger || magnitude instanceof RubyRational) {
return context.runtime.getTrue();
return true;
}

if (magnitude instanceof RubyFloat) {
return context.runtime.newBoolean(!((RubyFloat) magnitude).infinite_p().isTrue());
return ((RubyFloat) magnitude).finite_p().isTrue();
}

if (magnitude instanceof RubyRational) {
return true;
}

return sites(context).finite.call(context, magnitude, magnitude);
return sites(context).finite.call(context, magnitude, magnitude).isTrue();
}

@JRubyMethod(name = "infinite?")
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/RubyFile.java
Original file line number Diff line number Diff line change
@@ -1114,7 +1114,7 @@ public static IRubyObject readlink(ThreadContext context, IRubyObject recv, IRub
throw runtime.newErrnoFromLastPOSIXErrno();
}

return runtime.newString(realPath);
return RubyString.newString(runtime, realPath, runtime.getEncodingService().getFileSystemEncoding());
} catch (IOException e) {
throw runtime.newIOError(e.getMessage());
}
43 changes: 19 additions & 24 deletions core/src/main/java/org/jruby/RubyIO.java
Original file line number Diff line number Diff line change
@@ -3459,20 +3459,31 @@ private static IRubyObject foreachInternal19(ThreadContext context, IRubyObject
Ruby runtime = context.runtime;

IRubyObject opt = ArgsUtil.getOptionsArg(context.runtime, args);
IRubyObject io = openKeyArgs(context, recv, args, opt);
RubyIO io = (RubyIO) openKeyArgs(context, recv, args, opt);
if (io.isNil()) return io;

// io_s_foreach

IRubyObject[] methodArguments = processReadlinesMethodArguments(context, args);
// replace arg with coerced opts
if (!opt.isNil()) args[args.length - 1] = opt;

// io_s_foreach, roughly
try {
IRubyObject str;
while (!(str = ((RubyIO)io).gets(context, methodArguments)).isNil()) {
block.yield(context, str);
switch (args.length) {
case 1:
Getline.getlineCall(context, GETLINE_YIELD, io, io.getReadEncoding(context), block);
break;
case 2:
Getline.getlineCall(context, GETLINE_YIELD, io, io.getReadEncoding(context), args[1], block);
break;
case 3:
Getline.getlineCall(context, GETLINE_YIELD, io, io.getReadEncoding(context), args[1], args[2], block);
break;
case 4:
Getline.getlineCall(context, GETLINE_YIELD, io, io.getReadEncoding(context), args[1], args[2], args[3], block);
break;
}
} finally {
((RubyIO)io).close();
io.close();
context.setLastLine(context.nil);
runtime.getGlobalVariables().clear("$_");
}

@@ -3821,22 +3832,6 @@ public static IRubyObject readlines(ThreadContext context, IRubyObject recv, IRu
return readlinesCommon(context, (RubyIO) io, methodArguments);
}

private static IRubyObject[] processReadlinesMethodArguments(ThreadContext context, IRubyObject[] args) {
int count = args.length;
IRubyObject[] methodArguments = IRubyObject.NULL_ARRAY;

RespondToCallSite respond_to_to_int = sites(context).respond_to_to_int;
if(count >= 3 && (args[2] instanceof RubyFixnum || respond_to_to_int.respondsTo(context, args[2], args[2]))) {
methodArguments = new IRubyObject[]{args[1], args[2]};
} else if (count >= 2 && (args[1] instanceof RubyFixnum || respond_to_to_int.respondsTo(context, args[1], args[1]))) {
methodArguments = new IRubyObject[]{args[1]};
} else if (count >= 2 && !(args[1] instanceof RubyHash)) {
methodArguments = new IRubyObject[]{args[1]};
}

return methodArguments;
}

private static RubyArray readlinesCommon(ThreadContext context, RubyIO file, IRubyObject[] newArguments) {
try {
return file.readlines(context, newArguments);
18 changes: 9 additions & 9 deletions core/src/main/java/org/jruby/RubyInstanceConfig.java
Original file line number Diff line number Diff line change
@@ -608,15 +608,6 @@ public InputStream getInput() {
return input;
}

@Deprecated
public CompatVersion getCompatVersion() {
return CompatVersion.RUBY2_1;
}

@Deprecated
public void setCompatVersion(CompatVersion compatVersion) {
}

public void setOutput(PrintStream newOutput) {
output = newOutput;
}
@@ -2034,4 +2025,13 @@ public boolean isCextEnabled() {
public boolean getIPv4Preferred() {
return Options.PREFER_IPV4.load();
}

@Deprecated
public CompatVersion getCompatVersion() {
return CompatVersion.RUBY2_1;
}

@Deprecated
public void setCompatVersion(CompatVersion compatVersion) {
}
}
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/RubyKernel.java
Original file line number Diff line number Diff line change
@@ -763,7 +763,7 @@ public static RubyArray local_variables(ThreadContext context, IRubyObject recv)
return local_variables19(context, recv);
}

@JRubyMethod(name = "local_variables", module = true, visibility = PRIVATE)
@JRubyMethod(name = "local_variables", module = true, visibility = PRIVATE, reads = SCOPE)
public static RubyArray local_variables19(ThreadContext context, IRubyObject recv) {
final Ruby runtime = context.runtime;
HashSet<String> encounteredLocalVariables = new HashSet<String>();
61 changes: 11 additions & 50 deletions core/src/main/java/org/jruby/RubyModule.java
Original file line number Diff line number Diff line change
@@ -59,6 +59,7 @@
import org.jcodings.Encoding;
import org.jruby.anno.AnnotationBinder;
import org.jruby.anno.AnnotationHelper;
import org.jruby.anno.FrameField;
import org.jruby.anno.JRubyClass;
import org.jruby.anno.JRubyConstant;
import org.jruby.anno.JRubyMethod;
@@ -71,14 +72,11 @@
import org.jruby.internal.runtime.methods.AttrReaderMethod;
import org.jruby.internal.runtime.methods.AttrWriterMethod;
import org.jruby.internal.runtime.methods.CacheableMethod;
import org.jruby.internal.runtime.methods.CallConfiguration;
import org.jruby.internal.runtime.methods.DefineMethodMethod;
import org.jruby.internal.runtime.methods.DynamicMethod;
import org.jruby.internal.runtime.methods.Framing;
import org.jruby.internal.runtime.methods.JavaMethod;
import org.jruby.internal.runtime.methods.NativeCallMethod;
import org.jruby.internal.runtime.methods.ProcMethod;
import org.jruby.internal.runtime.methods.Scoping;
import org.jruby.internal.runtime.methods.SynchronizedDynamicMethod;
import org.jruby.internal.runtime.methods.UndefinedMethod;
import org.jruby.internal.runtime.methods.WrapperMethod;
@@ -973,7 +971,9 @@ public void defineAnnotatedMethods(Class clazz) {
public static final class MethodClumper {
private HashMap<String, List<JavaMethodDescriptor>> annotatedMethods;
private HashMap<String, List<JavaMethodDescriptor>> staticAnnotatedMethods;
// final HashMap<String, List<JavaMethodDescriptor>> allAnnotatedMethods = new HashMap<>();

public Map<Set<FrameField>, List<String>> readGroups = Collections.EMPTY_MAP;
public Map<Set<FrameField>, List<String>> writeGroups = Collections.EMPTY_MAP;

public void clump(final Class cls) {
Method[] declaredMethods = Initializer.DECLARED_METHODS.get(cls);
@@ -989,7 +989,6 @@ public void clump(final Class cls) {

String name = anno.name().length == 0 ? method.getName() : anno.name()[0];

List<JavaMethodDescriptor> methodDescs;
Map<String, List<JavaMethodDescriptor>> methodsHash;
if (desc.isStatic) {
if ( (methodsHash = staticAnnotatedMethods) == null ) {
@@ -1001,43 +1000,18 @@ public void clump(final Class cls) {
}
}

// add to specific
methodDescs = methodsHash.get(name);
List<JavaMethodDescriptor> methodDescs = methodsHash.get(name);
if (methodDescs == null) {
// optimize for most methods mapping to one method for a given name :
methodsHash.put(name, Collections.singletonList(desc));
methodsHash.put(name, methodDescs = new ArrayList(4));
}
else {
CompatVersion oldCompat = methodDescs.get(0).anno.compat();
CompatVersion newCompat = desc.anno.compat();

int comparison = newCompat.compareTo(oldCompat);
if (comparison == 1) {
// new method's compat is higher than old method's, so we throw old one away
methodsHash.put(name, methodDescs = new ArrayList<>(2));
} else if (comparison == 0) {
// same compat version, proceed to adding additional method
} else {
// lower compat, skip this method
continue;
}

if (methodDescs.getClass() != ArrayList.class) { // due singletonList
ArrayList<JavaMethodDescriptor> newDescs = new ArrayList<>(4);
newDescs.addAll(methodDescs);
methodsHash.put(name, methodDescs = newDescs);
}
methodDescs.add(desc);

methodDescs.add(desc);
}
// check for frame field reads or writes
if (anno.reads().length > 0 && readGroups == Collections.EMPTY_MAP) readGroups = new HashMap<>();
if (anno.writes().length > 0 && writeGroups == Collections.EMPTY_MAP) writeGroups = new HashMap<>();

// add to general
//methodDescs = allAnnotatedMethods.get(name);
//if (methodDescs == null) {
// methodDescs = new ArrayList<JavaMethodDescriptor>();
// allAnnotatedMethods.put(name, methodDescs);
//}
//methodDescs.add(desc);
AnnotationHelper.groupFrameFields(readGroups, writeGroups, anno, method.getName().toString());
}
}

@@ -4480,19 +4454,6 @@ private static void define(RubyModule module, JavaMethodDescriptor desc, final S
JRubyMethod jrubyMethod = desc.anno;
final String[] names = jrubyMethod.name();
final String[] aliases = jrubyMethod.alias();
// check for frame field reads or writes
CallConfiguration needs = CallConfiguration.valueOf(AnnotationHelper.getCallerCallConfigNameByAnno(jrubyMethod));

if (needs.framing() == Framing.Full) {
Map<String, JRubyMethod> frameAwareMethods = new HashMap<>(4); // added to a Set - thus no need for another Set
AnnotationHelper.addMethodNamesToMap(frameAwareMethods, null, simpleName, names, aliases);
MethodIndex.FRAME_AWARE_METHODS.addAll(frameAwareMethods.keySet());
}
if (needs.scoping() == Scoping.Full) {
Map<String, JRubyMethod> scopeAwareMethods = new HashMap<>(4); // added to a Set - thus no need for another Set
AnnotationHelper.addMethodNamesToMap(scopeAwareMethods, null, simpleName, names, aliases);
MethodIndex.SCOPE_AWARE_METHODS.addAll(scopeAwareMethods.keySet());
}

RubyModule singletonClass;

3 changes: 1 addition & 2 deletions core/src/main/java/org/jruby/RubyNumeric.java
Original file line number Diff line number Diff line change
@@ -476,8 +476,7 @@ protected final RubyArray doCoerce(ThreadContext context, IRubyObject other, boo
final IRubyObject result;
try {
result = coerceBody(context, other);
}
catch (RaiseException e) { // e.g. NoMethodError: undefined method `coerce'
} catch (RaiseException e) { // e.g. NoMethodError: undefined method `coerce'
if (context.runtime.getStandardError().isInstance( e.getException() )) {
context.setErrorInfo($ex); // restore $!
RubyWarnings warnings = context.runtime.getWarnings();
Loading