Skip to content

Commit 0b01058

Browse files
committed
Merge remote-tracking branch 'origin/jruby-1_7'
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
2 parents eab2354 + ab3b1d5 commit 0b01058

File tree

5 files changed

+82
-76
lines changed

5 files changed

+82
-76
lines changed

core/src/main/java/org/jruby/RubyIO.java

Lines changed: 47 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -3432,7 +3432,7 @@ private static IRubyObject openKeyArgs(ThreadContext context, IRubyObject recv,
34323432
IRubyObject path, v;
34333433

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

34383438
if (opt.isNil()) {
@@ -3762,61 +3762,53 @@ private static class Ruby19POpen {
37623762

37633763
public Ruby19POpen(Ruby runtime, IRubyObject[] args) {
37643764
IRubyObject[] _cmdPlusArgs = null;
3765-
RubyHash _env = null;
3765+
IRubyObject _env = null;
37663766
IRubyObject _cmd;
3767-
IRubyObject arg0 = args[0].checkArrayType();
37683767

3769-
if (args[0] instanceof RubyHash) {
3770-
// use leading hash as env
3771-
if (args.length > 1) {
3772-
_env = (RubyHash)args[0];
3773-
} else {
3774-
Arity.raiseArgumentError(runtime, 0, 1, 2);
3775-
}
3768+
int firstArg = 0;
3769+
int argc = args.length;
37763770

3777-
if (Platform.IS_WINDOWS) {
3778-
String[] tokens = args[1].convertToString().toString().split(" ", 2);
3779-
String commandString = tokens[0].replace('/', '\\') +
3780-
(tokens.length > 1 ? ' ' + tokens[1] : "");
3781-
_cmd = runtime.newString(commandString);
3782-
} else {
3783-
_cmd = args[1].convertToString();
3771+
if (argc > 0 && !(_env = TypeConverter.checkHashType(runtime, args[0])).isNil()) {
3772+
if (argc < 2) throw runtime.newArgumentError(1, 2);
3773+
firstArg++;
3774+
argc--;
3775+
} else {
3776+
_env = null;
3777+
}
3778+
3779+
IRubyObject arg0 = args[firstArg].checkArrayType();
3780+
3781+
if (arg0.isNil()) {
3782+
if ((arg0 = TypeConverter.checkStringType(runtime, args[firstArg])).isNil()) {
3783+
throw runtime.newTypeError(args[firstArg], runtime.getString());
37843784
}
3785-
} else if (args[0] instanceof RubyArray) {
3786-
RubyArray arg0Ary = (RubyArray)arg0;
3785+
_cmdPlusArgs = new IRubyObject[]{arg0};
3786+
} else {
3787+
RubyArray arg0Ary = (RubyArray) arg0;
37873788
if (arg0Ary.isEmpty()) throw runtime.newArgumentError("wrong number of arguments");
37883789
if (arg0Ary.eltOk(0) instanceof RubyHash) {
37893790
// leading hash, use for env
3790-
_env = (RubyHash)arg0Ary.delete_at(0);
3791+
_env = arg0Ary.delete_at(0);
37913792
}
37923793
if (arg0Ary.isEmpty()) throw runtime.newArgumentError("wrong number of arguments");
37933794
if (arg0Ary.size() > 1 && arg0Ary.eltOk(arg0Ary.size() - 1) instanceof RubyHash) {
37943795
// trailing hash, use for opts
3795-
_env = (RubyHash)arg0Ary.eltOk(arg0Ary.size() - 1);
3796+
_env = arg0Ary.eltOk(arg0Ary.size() - 1);
37963797
}
3797-
_cmdPlusArgs = (IRubyObject[])arg0Ary.toJavaArray();
3798+
_cmdPlusArgs = arg0Ary.toJavaArray();
3799+
}
37983800

3799-
if (Platform.IS_WINDOWS) {
3800-
String commandString = _cmdPlusArgs[0].convertToString().toString().replace('/', '\\');
3801-
_cmdPlusArgs[0] = runtime.newString(commandString);
3802-
} else {
3803-
_cmdPlusArgs[0] = _cmdPlusArgs[0].convertToString();
3804-
}
3805-
_cmd = _cmdPlusArgs[0];
3801+
if (Platform.IS_WINDOWS) {
3802+
String commandString = _cmdPlusArgs[0].convertToString().toString().replace('/', '\\');
3803+
_cmdPlusArgs[0] = runtime.newString(commandString);
38063804
} else {
3807-
if (Platform.IS_WINDOWS) {
3808-
String[] tokens = args[0].convertToString().toString().split(" ", 2);
3809-
String commandString = tokens[0].replace('/', '\\') +
3810-
(tokens.length > 1 ? ' ' + tokens[1] : "");
3811-
_cmd = runtime.newString(commandString);
3812-
} else {
3813-
_cmd = args[0].convertToString();
3814-
}
3805+
_cmdPlusArgs[0] = _cmdPlusArgs[0].convertToString();
38153806
}
3807+
_cmd = _cmdPlusArgs[0];
38163808

38173809
this.cmd = (RubyString)_cmd;
38183810
this.cmdPlusArgs = _cmdPlusArgs;
3819-
this.env = _env;
3811+
this.env = (RubyHash)_env;
38203812
}
38213813
}
38223814

@@ -3832,21 +3824,23 @@ public static IRubyObject popen(ThreadContext context, IRubyObject recv, IRubyOb
38323824
// old JDK popen logic
38333825
IRubyObject pmode = null;
38343826
RubyHash options = null;
3835-
3836-
switch(args.length) {
3837-
case 1:
3838-
break;
3839-
case 2:
3840-
if (args[1] instanceof RubyHash) {
3841-
options = (RubyHash) args[1];
3842-
} else {
3843-
pmode = args[1];
3844-
}
3845-
break;
3846-
case 3:
3847-
options = args[2].convertToHash();
3848-
pmode = args[1];
3849-
break;
3827+
IRubyObject tmp;
3828+
3829+
int firstArg = 0;
3830+
int argc = args.length;
3831+
3832+
if (argc > 0 && !TypeConverter.checkHashType(runtime, args[0]).isNil()) {
3833+
firstArg++;
3834+
argc--;
3835+
}
3836+
3837+
if (argc > 0 && !(tmp = TypeConverter.checkHashType(runtime, args[args.length - 1])).isNil()) {
3838+
options = (RubyHash)tmp;
3839+
argc--;
3840+
}
3841+
3842+
if (argc > 1) {
3843+
pmode = args[firstArg + 1];
38503844
}
38513845

38523846
RubyIO io = new RubyIO(runtime, (RubyClass) recv);

core/src/main/java/org/jruby/RubyModule.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3151,11 +3151,10 @@ public Collection<String> constantsCommon(Ruby runtime, boolean replaceModule, b
31513151
return constantsCommon(runtime, replaceModule, allConstants, true);
31523152
}
31533153

3154-
31553154
public Collection<String> constantsCommon(Ruby runtime, boolean replaceModule, boolean allConstants, boolean includePrivate) {
3156-
RubyModule objectClass = runtime.getObject();
3155+
final RubyModule objectClass = runtime.getObject();
31573156

3158-
Collection<String> constantNames = new HashSet<String>();
3157+
final Collection<String> constantNames;
31593158
if (allConstants) {
31603159
if ((replaceModule && runtime.getModule() == this) || objectClass == this) {
31613160
constantNames = objectClass.getConstantNames(includePrivate);

core/src/main/java/org/jruby/runtime/backtrace/TraceType.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,20 +68,20 @@ public static void logBacktrace(RubyStackTraceElement[] trace) {
6868
LOG.info(" " + element.getFileName() + ":" + element.getLineNumber() + " in " + element.getMethodName());
6969
}
7070
}
71-
71+
7272
public static void dumpException(RubyException exception) {
7373
LOG.info("Exception raised: {} : {}", exception.getMetaClass(), exception);
7474
}
75-
75+
7676
public static void dumpBacktrace(RubyException exception) {
7777
Ruby runtime = exception.getRuntime();
7878
System.err.println("Backtrace generated:\n" + Format.JRUBY.printBacktrace(exception, runtime.getPosix().isatty(FileDescriptor.err)));
7979
}
80-
80+
8181
public static void dumpCaller(RubyArray trace) {
8282
LOG.info("Caller backtrace generated:\n" + trace);
8383
}
84-
84+
8585
public static void dumpCaller(RubyStackTraceElement[] trace) {
8686
LOG.info("Caller backtrace generated:\n" + Arrays.toString(trace));
8787
}
@@ -94,13 +94,13 @@ public static TraceType traceTypeFor(String style) {
9494
if (style.equalsIgnoreCase("raw")) return new TraceType(Gather.RAW, Format.JRUBY);
9595
else if (style.equalsIgnoreCase("ruby_framed")) return new TraceType(Gather.NORMAL, Format.JRUBY);
9696
else if (style.equalsIgnoreCase("normal")) return new TraceType(Gather.NORMAL, Format.JRUBY);
97-
// deprecated, just uses jruby format now
97+
// deprecated, just uses jruby format now
9898
else if (style.equalsIgnoreCase("rubinius")) return new TraceType(Gather.NORMAL, Format.JRUBY);
9999
else if (style.equalsIgnoreCase("full")) return new TraceType(Gather.FULL, Format.JRUBY);
100100
else if (style.equalsIgnoreCase("mri")) return new TraceType(Gather.NORMAL, Format.MRI);
101101
else return new TraceType(Gather.NORMAL, Format.JRUBY);
102102
}
103-
103+
104104
public enum Gather {
105105
/**
106106
* Full raw backtraces with all Java frames included.
@@ -121,7 +121,7 @@ public BacktraceData getBacktraceData(ThreadContext context, StackTraceElement[]
121121
*/
122122
FULL {
123123
public BacktraceData getBacktraceData(ThreadContext context, StackTraceElement[] javaTrace, boolean nativeException) {
124-
return new BacktraceData(
124+
return new BacktraceData(
125125
javaTrace,
126126
context.createBacktrace2(0, nativeException),
127127
true,
@@ -191,7 +191,7 @@ public BacktraceData getBacktraceData(ThreadContext context, boolean nativeExcep
191191
/**
192192
* Gather backtrace data for an integrated trace if the current gather type is "NORMAL", otherwise use the
193193
* current gather type.
194-
*
194+
*
195195
* @param context
196196
* @param javaTrace
197197
* @return
@@ -202,7 +202,7 @@ public BacktraceData getIntegratedBacktraceData(ThreadContext context, StackTrac
202202
if (useGather == NORMAL) {
203203
useGather = INTEGRATED;
204204
}
205-
205+
206206
BacktraceData data = useGather.getBacktraceData(context, javaTrace, false);
207207

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

214214
public abstract BacktraceData getBacktraceData(ThreadContext context, StackTraceElement[] javaTrace, boolean nativeException);
215215
}
216-
216+
217217
public enum Format {
218218
/**
219219
* Formatting like C Ruby

core/src/main/java/org/jruby/runtime/load/LoadService.java

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -393,19 +393,32 @@ private enum RequireState {
393393
LOADED, ALREADY_LOADED, CIRCULAR
394394
};
395395

396-
private RequireState requireCommon(String requireName, boolean circularRequireWarning) {
397-
// check for requiredName without extension.
398-
if (featureAlreadyLoaded(requireName)) {
396+
private RequireState requireCommon(String file, boolean circularRequireWarning) {
397+
checkEmptyLoad(file);
398+
399+
// check with short name
400+
if (featureAlreadyLoaded(file)) {
401+
return RequireState.ALREADY_LOADED;
402+
}
403+
404+
SearchState state = findFileForLoad(file);
405+
406+
if (state.library == null) {
407+
throw runtime.newLoadError("no such file to load -- " + state.searchFile, state.searchFile);
408+
}
409+
410+
// check with long name
411+
if (featureAlreadyLoaded(state.loadName)) {
399412
return RequireState.ALREADY_LOADED;
400413
}
401414

402-
if (!runtime.getProfile().allowRequire(requireName)) {
403-
throw runtime.newLoadError("no such file to load -- " + requireName, requireName);
415+
if (!runtime.getProfile().allowRequire(file)) {
416+
throw runtime.newLoadError("no such file to load -- " + file, file);
404417
}
405418

406-
return smartLoadInternal(requireName, circularRequireWarning);
419+
return smartLoadInternal(file, circularRequireWarning);
407420
}
408-
421+
409422
protected final RequireLocks requireLocks = new RequireLocks();
410423

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

447460
/**
448461
* Unlock the lock for the specified requireName.
449-
*
462+
*
450463
* @param requireName
451464
* name of the lock to be unlocked.
452465
*/

core/src/main/java/org/jruby/util/ShellLauncher.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -783,7 +783,7 @@ private static Process popenShared(Ruby runtime, IRubyObject[] strings, Map env,
783783

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

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

0 commit comments

Comments
 (0)