Skip to content

Commit

Permalink
Showing 64 changed files with 289 additions and 299 deletions.
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

0 comments on commit 2d48da9

Please sign in to comment.