Skip to content

Commit

Permalink
Merge branch 'master' into 9.5-dev
Browse files Browse the repository at this point in the history
  • Loading branch information
enebo committed Jul 15, 2024
2 parents 88dc147 + 7d01a1e commit 58557fa
Show file tree
Hide file tree
Showing 75 changed files with 1,095 additions and 260 deletions.
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/RubyIO.java
Original file line number Diff line number Diff line change
Expand Up @@ -5582,7 +5582,7 @@ public final OpenFile MakeOpenFile() {

private static int rb_io_fptr_finalize(Ruby runtime, OpenFile fptr) {
if (fptr == null) return 0;
fptr.setPath(null);;
fptr.setPath(null);
if (fptr.fd() != null)
fptr.cleanup(runtime, true);
fptr.write_lock = null;
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/RubyInstanceConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -1526,7 +1526,7 @@ public static ClassLoader defaultClassLoader() {

private ProfilingMode profilingMode = Options.CLI_PROFILING_MODE.load();
private ProfileOutput profileOutput = new ProfileOutput(System.err);
private String profilingService = Options.CLI_PROFILING_SERVICE.load();;
private String profilingService = Options.CLI_PROFILING_SERVICE.load();

private ClassLoader loader = defaultClassLoader();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/
public class JavaExtensions {

private static final boolean LAZY = Options.JI_LOAD_LAZY.load();;
private static final boolean LAZY = Options.JI_LOAD_LAZY.load();

private JavaExtensions() { /* hidden */ }

Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/javasupport/ext/JavaLang.java
Original file line number Diff line number Diff line change
Expand Up @@ -913,7 +913,7 @@ static final class InspectRawValue extends JavaMethod.JavaMethodZero {

@Override
public IRubyObject call(final ThreadContext context, final IRubyObject self, final RubyModule clazz, final java.lang.String name) {
java.lang.Object val = unwrapIfJavaObject(self);;
java.lang.Object val = unwrapIfJavaObject(self);
return context.runtime.newString(val.toString());
}

Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/javasupport/ext/JavaUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ public static RubyArray to_a(final ThreadContext context, final IRubyObject self
final java.util.List list = unwrapIfJavaObject(self);
final IRubyObject[] array = new IRubyObject[ list.size() ];
int i = 0; for ( Object elem : list ) {
array[i++] = convertJavaToUsableRubyObject(runtime, elem);;
array[i++] = convertJavaToUsableRubyObject(runtime, elem);
}
return RubyArray.newArrayMayCopy(runtime, array);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.jcodings.specific.USASCIIEncoding;
import org.jruby.RubyString;
import org.jruby.util.SafePropertyAccessor;
import org.jruby.util.cli.Options;
import org.jruby.util.io.EncodingUtils;

public final class EncodingService {
Expand Down Expand Up @@ -430,7 +431,7 @@ private void checkAsciiEncodingName(ByteList name) {
}

public Encoding getWindowsFilesystemEncoding(Ruby ruby) {
String encoding = SafePropertyAccessor.getProperty("file.encoding", "UTF-8");
String encoding = Options.WINDOWS_FILESYSTEM_ENCODING.load();
Encoding filesystemEncoding = loadEncoding(ByteList.create(encoding));

// Use default external if file.encoding does not point at an encoding we recognize
Expand Down
125 changes: 76 additions & 49 deletions core/src/main/java/org/jruby/util/ShellLauncher.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import java.io.PipedOutputStream;
import java.io.PrintStream;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.util.ArrayList;
Expand Down Expand Up @@ -655,6 +656,7 @@ public static long getPidFromProcess(Process process) {
private static final Field UNIXProcess_pid;
private static final Class ProcessImpl;
private static final Field ProcessImpl_handle;
private static final Method ProcessImpl_pid;
private interface PidGetter { long getPid(Process process); }
private static final PidGetter PID_GETTER;

Expand All @@ -677,7 +679,7 @@ private interface PidGetter { long getPid(Process process); }
if (up != null) {
try {
pid = up.getDeclaredField("pid");
Java.trySetAccessible(pid);
if (!Java.trySetAccessible(pid)) pid = null;
} catch (NoSuchFieldException | SecurityException e) {
// ignore and try windows version
}
Expand All @@ -690,69 +692,43 @@ private interface PidGetter { long getPid(Process process); }
try {
pi = Class.forName("java.lang.ProcessImpl");
handle = pi.getDeclaredField("handle");
Java.trySetAccessible(handle);
if (!Java.trySetAccessible(handle)) {
handle = null;
}
} catch (Exception e) {
// ignore and use hashcode
}

Method pi_pid = null;
if (pi != null) {
try {
pi_pid = pi.getMethod("pid");
if (!Java.trySetAccessible(pi_pid)) {
pi_pid = null;
if (handle == null) pi = null;
}
} catch (Exception e) {
// ignore and use hashcode
}
}
ProcessImpl = pi;
ProcessImpl_handle = handle;
ProcessImpl_pid = pi_pid;

if (UNIXProcess_pid != null) {
if (ProcessImpl_handle != null) {
// try both
pidGetter = new PidGetter() {
public long getPid(Process process) {
try {
if (UNIXProcess.isInstance(process)) {
return (Integer)UNIXProcess_pid.get(process);
} else if (ProcessImpl.isInstance(process)) {
Long hproc = (Long) ProcessImpl_handle.get(process);
return WindowsFFI.getKernel32().GetProcessId(hproc);
}
} catch (Exception e) {
// ignore and use hashcode
}
return process.hashCode();
}
};
pidGetter = ShellLauncher::getPidBoth;
} else {
// just unix
pidGetter = new PidGetter() {
public long getPid(Process process) {
try {
if (UNIXProcess.isInstance(process)) {
return (Integer)UNIXProcess_pid.get(process);
}
} catch (Exception e) {
// ignore and use hashcode
}
return process.hashCode();
}
};
pidGetter = ShellLauncher::getPidUnix;
}
} else if (ProcessImpl_handle != null) {
} else if (ProcessImpl_handle != null || ProcessImpl_pid != null) {
// just windows
pidGetter = new PidGetter() {
public long getPid(Process process) {
try {
if (ProcessImpl.isInstance(process)) {
Long hproc = (Long) ProcessImpl_handle.get(process);
return WindowsFFI.getKernel32().GetProcessId(hproc);
}

} catch (Exception e) {
// ignore and use hashcode
}
return process.hashCode();
}
};
pidGetter = ShellLauncher::getPidWindows;
} else {
// neither - default PidGetter
pidGetter = new PidGetter() {
public long getPid(Process process) {
return process.hashCode();
}
};
pidGetter = Object::hashCode;
}
PID_GETTER = pidGetter;
}
Expand All @@ -761,6 +737,57 @@ public static long reflectPidFromProcess(Process process) {
return PID_GETTER.getPid(process);
}

private static long getPidBoth(Process process) {
try {
if (UNIXProcess.isInstance(process)) {
return getPidUnix(process);
} else if (ProcessImpl.isInstance(process)) {
return getPidWindows(process);
}
} catch (Exception e) {
// fall back on hashcode
}

return process.hashCode();
}

private static long getPidWindows(Process process) {
long pid = -1;
if (ProcessImpl_handle != null) {
try {
if (ProcessImpl.isInstance(process)) {
Long hproc = (Long) ProcessImpl_handle.get(process);
return WindowsFFI.getKernel32().GetProcessId(hproc);
}
} catch (Exception e) {
// fall back on pid logic
}
}

if (pid == -1 && ProcessImpl_pid != null) {
// JDK > 8 has a new way to look it up and also can't use "handle" field anymore
try {
return (long) ProcessImpl_pid.invoke(process);
} catch (Exception e2) {
// fall back on hashcode
}
}

return process.hashCode();
}

private static long getPidUnix(Process process) {
try {
if (UNIXProcess.isInstance(process)) {
return (Integer) UNIXProcess_pid.get(process);
}
} catch (Exception e) {
// fall back on hashcode
}

return process.hashCode();
}

public static Process run(Ruby runtime, IRubyObject string) throws IOException {
return run(runtime, new IRubyObject[] {string}, false);
}
Expand Down
1 change: 1 addition & 0 deletions core/src/main/java/org/jruby/util/cli/Options.java
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ public class Options {
public static final Option<Boolean> PACKED_ARRAYS = bool(MISCELLANEOUS, "packed.arrays", true, "Toggle whether to use \"packed\" arrays for small tuples.");
public static final Option<Boolean> REGEXP_INTERRUPTIBLE = bool(MISCELLANEOUS, "regexp.interruptible", true, "Allow regexp operations to be interruptible from Ruby.");
public static final Option<Integer> JAR_CACHE_EXPIRATION = integer(MISCELLANEOUS, "jar.cache.expiration", 750, "The time (ms) between checks if a JAR file containing resources has been updated.");
public static final Option<String> WINDOWS_FILESYSTEM_ENCODING = string(MISCELLANEOUS, "windows.filesystem.encoding", "UTF-8", "The encoding to use for filesystem names and paths on Windows.");

public static final Option<Boolean> DEBUG_LOADSERVICE = bool(DEBUG, "debug.loadService", false, "Log require/load file searches.");
public static final Option<Boolean> DEBUG_LOADSERVICE_TIMING = bool(DEBUG, "debug.loadService.timing", false, "Log require/load parse+evaluate times.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,15 +149,17 @@ private static int readIntField(ByteArrayInputStream self, Field field) {
private static Field accessibleField(final String name) {
try {
Field field = ByteArrayInputStream.class.getDeclaredField(name);
Java.trySetAccessible(field);
return field;
if (Java.trySetAccessible(field)) {
return field;
}
}
catch (NoSuchFieldException ex) {
return null; // should never happen
// should never happen
}
catch (SecurityException ex) {
return null;
}

return null;
}

}
4 changes: 2 additions & 2 deletions lib/pom.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def log(message=nil)
['irb', '1.13.0'],
['jar-dependencies', '0.4.1'],
['jruby-readline', '1.3.7'],
['jruby-openssl', '0.14.5'],
['jruby-openssl', '0.15.0'],
['json', '2.7.2'],
['logger', '1.6.0'],
['net-http', '0.4.1'],
Expand Down Expand Up @@ -120,7 +120,7 @@ def log(message=nil)
['matrix', '0.4.2'],
['minitest', '5.22.2'],
['mutex_m', '0.2.0'],
['net-ftp', '0.3.4'],
['net-ftp', '0.3.7'],
['net-imap', '0.4.10'],
['net-pop', '0.1.2'],
['net-smtp', '0.4.0.1'],
Expand Down
16 changes: 8 additions & 8 deletions lib/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ DO NOT MODIFY - GENERATED CODE
<dependency>
<groupId>rubygems</groupId>
<artifactId>jruby-openssl</artifactId>
<version>0.14.5</version>
<version>0.15.0</version>
<type>gem</type>
<scope>provided</scope>
<exclusions>
Expand Down Expand Up @@ -892,7 +892,7 @@ DO NOT MODIFY - GENERATED CODE
<dependency>
<groupId>rubygems</groupId>
<artifactId>net-ftp</artifactId>
<version>0.3.4</version>
<version>0.3.7</version>
<type>gem</type>
<scope>provided</scope>
<exclusions>
Expand Down Expand Up @@ -1126,7 +1126,7 @@ DO NOT MODIFY - GENERATED CODE
<include>specifications/irb-1.13.0*</include>
<include>specifications/jar-dependencies-0.4.1*</include>
<include>specifications/jruby-readline-1.3.7*</include>
<include>specifications/jruby-openssl-0.14.5*</include>
<include>specifications/jruby-openssl-0.15.0*</include>
<include>specifications/json-2.7.2*</include>
<include>specifications/logger-1.6.0*</include>
<include>specifications/net-http-0.4.1*</include>
Expand Down Expand Up @@ -1171,7 +1171,7 @@ DO NOT MODIFY - GENERATED CODE
<include>specifications/matrix-0.4.2*</include>
<include>specifications/minitest-5.22.2*</include>
<include>specifications/mutex_m-0.2.0*</include>
<include>specifications/net-ftp-0.3.4*</include>
<include>specifications/net-ftp-0.3.7*</include>
<include>specifications/net-imap-0.4.10*</include>
<include>specifications/net-pop-0.1.2*</include>
<include>specifications/net-smtp-0.4.0.1*</include>
Expand Down Expand Up @@ -1207,7 +1207,7 @@ DO NOT MODIFY - GENERATED CODE
<include>gems/irb-1.13.0*/**/*</include>
<include>gems/jar-dependencies-0.4.1*/**/*</include>
<include>gems/jruby-readline-1.3.7*/**/*</include>
<include>gems/jruby-openssl-0.14.5*/**/*</include>
<include>gems/jruby-openssl-0.15.0*/**/*</include>
<include>gems/json-2.7.2*/**/*</include>
<include>gems/logger-1.6.0*/**/*</include>
<include>gems/net-http-0.4.1*/**/*</include>
Expand Down Expand Up @@ -1252,7 +1252,7 @@ DO NOT MODIFY - GENERATED CODE
<include>gems/matrix-0.4.2*/**/*</include>
<include>gems/minitest-5.22.2*/**/*</include>
<include>gems/mutex_m-0.2.0*/**/*</include>
<include>gems/net-ftp-0.3.4*/**/*</include>
<include>gems/net-ftp-0.3.7*/**/*</include>
<include>gems/net-imap-0.4.10*/**/*</include>
<include>gems/net-pop-0.1.2*/**/*</include>
<include>gems/net-smtp-0.4.0.1*/**/*</include>
Expand Down Expand Up @@ -1288,7 +1288,7 @@ DO NOT MODIFY - GENERATED CODE
<include>cache/irb-1.13.0*</include>
<include>cache/jar-dependencies-0.4.1*</include>
<include>cache/jruby-readline-1.3.7*</include>
<include>cache/jruby-openssl-0.14.5*</include>
<include>cache/jruby-openssl-0.15.0*</include>
<include>cache/json-2.7.2*</include>
<include>cache/logger-1.6.0*</include>
<include>cache/net-http-0.4.1*</include>
Expand Down Expand Up @@ -1333,7 +1333,7 @@ DO NOT MODIFY - GENERATED CODE
<include>cache/matrix-0.4.2*</include>
<include>cache/minitest-5.22.2*</include>
<include>cache/mutex_m-0.2.0*</include>
<include>cache/net-ftp-0.3.4*</include>
<include>cache/net-ftp-0.3.7*</include>
<include>cache/net-imap-0.4.10*</include>
<include>cache/net-pop-0.1.2*</include>
<include>cache/net-smtp-0.4.0.1*</include>
Expand Down
15 changes: 14 additions & 1 deletion spec/mspec/lib/mspec/helpers/tmp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,20 @@
end

def tmp(name, uniquify = true)
mkdir_p SPEC_TEMP_DIR unless Dir.exist? SPEC_TEMP_DIR
if Dir.exist? SPEC_TEMP_DIR
stat = File.stat(SPEC_TEMP_DIR)
if stat.world_writable? and !stat.sticky?
raise ArgumentError, "SPEC_TEMP_DIR (#{SPEC_TEMP_DIR}) is world writable but not sticky"
end
else
platform_is_not :windows do
umask = File.umask
if (umask & 0002) == 0 # o+w
raise ArgumentError, "File.umask #=> #{umask.to_s(8)} (world-writable)"
end
end
mkdir_p SPEC_TEMP_DIR
end

if uniquify and !name.empty?
slash = name.rindex "/"
Expand Down
2 changes: 1 addition & 1 deletion spec/mspec/lib/mspec/runner/formatters/multi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ def aggregate_results(files)
end

def print_exception(exc, count)
print "\n#{count})\n#{exc}\n"
@err.print "\n#{count})\n#{exc}\n"
end
end
Loading

0 comments on commit 58557fa

Please sign in to comment.