Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/jruby-1_7'
Browse files Browse the repository at this point in the history
Conflicts:
	core/src/main/java/org/jruby/RubyIO.java
	core/src/main/java/org/jruby/runtime/ThreadContext.java
	core/src/main/java/org/jruby/runtime/load/LoadService.java
	core/src/main/java/org/jruby/util/TypeConverter.java
	lib/pom.rb
  • Loading branch information
headius committed Apr 22, 2015
2 parents eab2354 + ab3b1d5 commit 0b01058
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 76 deletions.
100 changes: 47 additions & 53 deletions core/src/main/java/org/jruby/RubyIO.java
Expand Up @@ -3432,7 +3432,7 @@ private static IRubyObject openKeyArgs(ThreadContext context, IRubyObject recv,
IRubyObject path, v;

path = StringSupport.checkEmbeddedNulls(runtime, RubyFile.get_path(context, argv[0]));
failIfDirectory(runtime, (RubyString)path); // only in JRuby
failIfDirectory(runtime, (RubyString) path); // only in JRuby
// MRI increments args past 0 now, so remaining uses of args only see non-path args

if (opt.isNil()) {
Expand Down Expand Up @@ -3762,61 +3762,53 @@ private static class Ruby19POpen {

public Ruby19POpen(Ruby runtime, IRubyObject[] args) {
IRubyObject[] _cmdPlusArgs = null;
RubyHash _env = null;
IRubyObject _env = null;
IRubyObject _cmd;
IRubyObject arg0 = args[0].checkArrayType();

if (args[0] instanceof RubyHash) {
// use leading hash as env
if (args.length > 1) {
_env = (RubyHash)args[0];
} else {
Arity.raiseArgumentError(runtime, 0, 1, 2);
}
int firstArg = 0;
int argc = args.length;

if (Platform.IS_WINDOWS) {
String[] tokens = args[1].convertToString().toString().split(" ", 2);
String commandString = tokens[0].replace('/', '\\') +
(tokens.length > 1 ? ' ' + tokens[1] : "");
_cmd = runtime.newString(commandString);
} else {
_cmd = args[1].convertToString();
if (argc > 0 && !(_env = TypeConverter.checkHashType(runtime, args[0])).isNil()) {
if (argc < 2) throw runtime.newArgumentError(1, 2);
firstArg++;
argc--;
} else {
_env = null;
}

IRubyObject arg0 = args[firstArg].checkArrayType();

if (arg0.isNil()) {
if ((arg0 = TypeConverter.checkStringType(runtime, args[firstArg])).isNil()) {
throw runtime.newTypeError(args[firstArg], runtime.getString());
}
} else if (args[0] instanceof RubyArray) {
RubyArray arg0Ary = (RubyArray)arg0;
_cmdPlusArgs = new IRubyObject[]{arg0};
} else {
RubyArray arg0Ary = (RubyArray) arg0;
if (arg0Ary.isEmpty()) throw runtime.newArgumentError("wrong number of arguments");
if (arg0Ary.eltOk(0) instanceof RubyHash) {
// leading hash, use for env
_env = (RubyHash)arg0Ary.delete_at(0);
_env = arg0Ary.delete_at(0);
}
if (arg0Ary.isEmpty()) throw runtime.newArgumentError("wrong number of arguments");
if (arg0Ary.size() > 1 && arg0Ary.eltOk(arg0Ary.size() - 1) instanceof RubyHash) {
// trailing hash, use for opts
_env = (RubyHash)arg0Ary.eltOk(arg0Ary.size() - 1);
_env = arg0Ary.eltOk(arg0Ary.size() - 1);
}
_cmdPlusArgs = (IRubyObject[])arg0Ary.toJavaArray();
_cmdPlusArgs = arg0Ary.toJavaArray();
}

if (Platform.IS_WINDOWS) {
String commandString = _cmdPlusArgs[0].convertToString().toString().replace('/', '\\');
_cmdPlusArgs[0] = runtime.newString(commandString);
} else {
_cmdPlusArgs[0] = _cmdPlusArgs[0].convertToString();
}
_cmd = _cmdPlusArgs[0];
if (Platform.IS_WINDOWS) {
String commandString = _cmdPlusArgs[0].convertToString().toString().replace('/', '\\');
_cmdPlusArgs[0] = runtime.newString(commandString);
} else {
if (Platform.IS_WINDOWS) {
String[] tokens = args[0].convertToString().toString().split(" ", 2);
String commandString = tokens[0].replace('/', '\\') +
(tokens.length > 1 ? ' ' + tokens[1] : "");
_cmd = runtime.newString(commandString);
} else {
_cmd = args[0].convertToString();
}
_cmdPlusArgs[0] = _cmdPlusArgs[0].convertToString();
}
_cmd = _cmdPlusArgs[0];

this.cmd = (RubyString)_cmd;
this.cmdPlusArgs = _cmdPlusArgs;
this.env = _env;
this.env = (RubyHash)_env;
}
}

Expand All @@ -3832,21 +3824,23 @@ public static IRubyObject popen(ThreadContext context, IRubyObject recv, IRubyOb
// old JDK popen logic
IRubyObject pmode = null;
RubyHash options = null;

switch(args.length) {
case 1:
break;
case 2:
if (args[1] instanceof RubyHash) {
options = (RubyHash) args[1];
} else {
pmode = args[1];
}
break;
case 3:
options = args[2].convertToHash();
pmode = args[1];
break;
IRubyObject tmp;

int firstArg = 0;
int argc = args.length;

if (argc > 0 && !TypeConverter.checkHashType(runtime, args[0]).isNil()) {
firstArg++;
argc--;
}

if (argc > 0 && !(tmp = TypeConverter.checkHashType(runtime, args[args.length - 1])).isNil()) {
options = (RubyHash)tmp;
argc--;
}

if (argc > 1) {
pmode = args[firstArg + 1];
}

RubyIO io = new RubyIO(runtime, (RubyClass) recv);
Expand Down
5 changes: 2 additions & 3 deletions core/src/main/java/org/jruby/RubyModule.java
Expand Up @@ -3151,11 +3151,10 @@ public Collection<String> constantsCommon(Ruby runtime, boolean replaceModule, b
return constantsCommon(runtime, replaceModule, allConstants, true);
}


public Collection<String> constantsCommon(Ruby runtime, boolean replaceModule, boolean allConstants, boolean includePrivate) {
RubyModule objectClass = runtime.getObject();
final RubyModule objectClass = runtime.getObject();

Collection<String> constantNames = new HashSet<String>();
final Collection<String> constantNames;
if (allConstants) {
if ((replaceModule && runtime.getModule() == this) || objectClass == this) {
constantNames = objectClass.getConstantNames(includePrivate);
Expand Down
20 changes: 10 additions & 10 deletions core/src/main/java/org/jruby/runtime/backtrace/TraceType.java
Expand Up @@ -68,20 +68,20 @@ public static void logBacktrace(RubyStackTraceElement[] trace) {
LOG.info(" " + element.getFileName() + ":" + element.getLineNumber() + " in " + element.getMethodName());
}
}

public static void dumpException(RubyException exception) {
LOG.info("Exception raised: {} : {}", exception.getMetaClass(), exception);
}

public static void dumpBacktrace(RubyException exception) {
Ruby runtime = exception.getRuntime();
System.err.println("Backtrace generated:\n" + Format.JRUBY.printBacktrace(exception, runtime.getPosix().isatty(FileDescriptor.err)));
}

public static void dumpCaller(RubyArray trace) {
LOG.info("Caller backtrace generated:\n" + trace);
}

public static void dumpCaller(RubyStackTraceElement[] trace) {
LOG.info("Caller backtrace generated:\n" + Arrays.toString(trace));
}
Expand All @@ -94,13 +94,13 @@ public static TraceType traceTypeFor(String style) {
if (style.equalsIgnoreCase("raw")) return new TraceType(Gather.RAW, Format.JRUBY);
else if (style.equalsIgnoreCase("ruby_framed")) return new TraceType(Gather.NORMAL, Format.JRUBY);
else if (style.equalsIgnoreCase("normal")) return new TraceType(Gather.NORMAL, Format.JRUBY);
// deprecated, just uses jruby format now
// deprecated, just uses jruby format now
else if (style.equalsIgnoreCase("rubinius")) return new TraceType(Gather.NORMAL, Format.JRUBY);
else if (style.equalsIgnoreCase("full")) return new TraceType(Gather.FULL, Format.JRUBY);
else if (style.equalsIgnoreCase("mri")) return new TraceType(Gather.NORMAL, Format.MRI);
else return new TraceType(Gather.NORMAL, Format.JRUBY);
}

public enum Gather {
/**
* Full raw backtraces with all Java frames included.
Expand All @@ -121,7 +121,7 @@ public BacktraceData getBacktraceData(ThreadContext context, StackTraceElement[]
*/
FULL {
public BacktraceData getBacktraceData(ThreadContext context, StackTraceElement[] javaTrace, boolean nativeException) {
return new BacktraceData(
return new BacktraceData(
javaTrace,
context.createBacktrace2(0, nativeException),
true,
Expand Down Expand Up @@ -191,7 +191,7 @@ public BacktraceData getBacktraceData(ThreadContext context, boolean nativeExcep
/**
* Gather backtrace data for an integrated trace if the current gather type is "NORMAL", otherwise use the
* current gather type.
*
*
* @param context
* @param javaTrace
* @return
Expand All @@ -202,7 +202,7 @@ public BacktraceData getIntegratedBacktraceData(ThreadContext context, StackTrac
if (useGather == NORMAL) {
useGather = INTEGRATED;
}

BacktraceData data = useGather.getBacktraceData(context, javaTrace, false);

context.runtime.incrementBacktraceCount();
Expand All @@ -213,7 +213,7 @@ public BacktraceData getIntegratedBacktraceData(ThreadContext context, StackTrac

public abstract BacktraceData getBacktraceData(ThreadContext context, StackTraceElement[] javaTrace, boolean nativeException);
}

public enum Format {
/**
* Formatting like C Ruby
Expand Down
31 changes: 22 additions & 9 deletions core/src/main/java/org/jruby/runtime/load/LoadService.java
Expand Up @@ -393,19 +393,32 @@ private enum RequireState {
LOADED, ALREADY_LOADED, CIRCULAR
};

private RequireState requireCommon(String requireName, boolean circularRequireWarning) {
// check for requiredName without extension.
if (featureAlreadyLoaded(requireName)) {
private RequireState requireCommon(String file, boolean circularRequireWarning) {
checkEmptyLoad(file);

// check with short name
if (featureAlreadyLoaded(file)) {
return RequireState.ALREADY_LOADED;
}

SearchState state = findFileForLoad(file);

if (state.library == null) {
throw runtime.newLoadError("no such file to load -- " + state.searchFile, state.searchFile);
}

// check with long name
if (featureAlreadyLoaded(state.loadName)) {
return RequireState.ALREADY_LOADED;
}

if (!runtime.getProfile().allowRequire(requireName)) {
throw runtime.newLoadError("no such file to load -- " + requireName, requireName);
if (!runtime.getProfile().allowRequire(file)) {
throw runtime.newLoadError("no such file to load -- " + file, file);
}

return smartLoadInternal(requireName, circularRequireWarning);
return smartLoadInternal(file, circularRequireWarning);
}

protected final RequireLocks requireLocks = new RequireLocks();

private class RequireLocks {
Expand All @@ -422,7 +435,7 @@ private RequireLocks() {
* Get exclusive lock for the specified requireName. Acquire sync object
* for the requireName from the pool, then try to lock it. NOTE: This
* lock is not fair for now.
*
*
* @param requireName
* just a name for the lock.
* @return If the sync object already locked by current thread, it just
Expand All @@ -446,7 +459,7 @@ private boolean lock(String requireName) {

/**
* Unlock the lock for the specified requireName.
*
*
* @param requireName
* name of the lock to be unlocked.
*/
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/util/ShellLauncher.java
Expand Up @@ -783,7 +783,7 @@ private static Process popenShared(Ruby runtime, IRubyObject[] strings, Map env,

String[] args = parseCommandLine(runtime.getCurrentContext(), runtime, strings);
LaunchConfig lc = new LaunchConfig(runtime, strings, false);
boolean useShell = Platform.IS_WINDOWS ? lc.shouldRunInShell() : false;
boolean useShell = lc.shouldRunInShell();
if (addShell) for (String arg : args) useShell |= shouldUseShell(arg);

// CON: popen is a case where I think we should just always shell out.
Expand Down

0 comments on commit 0b01058

Please sign in to comment.