Skip to content

Commit

Permalink
Merge branch 'master' into truffle-head
Browse files Browse the repository at this point in the history
Conflicts:
	truffle/src/main/java/org/jruby/truffle/nodes/RubyNode.java
	truffle/src/main/java/org/jruby/truffle/nodes/core/BasicObjectNodes.java
  • Loading branch information
chrisseaton committed Feb 15, 2015
2 parents 1c4eb81 + 93b3757 commit b9af305
Show file tree
Hide file tree
Showing 139 changed files with 910 additions and 1,144 deletions.
2 changes: 2 additions & 0 deletions core/src/main/java/org/jruby/Main.java
Expand Up @@ -438,6 +438,7 @@ private boolean checkFileSyntax(Ruby runtime, String filename) {
}

private boolean checkStreamSyntax(Ruby runtime, InputStream in, String filename) {
IRubyObject oldExc = runtime.getGlobalVariables().get("$!"); // Save $!
try {
runtime.parseFromMain(in, filename);
config.getOutput().println("Syntax OK");
Expand All @@ -448,6 +449,7 @@ private boolean checkStreamSyntax(Ruby runtime, InputStream in, String filename)
} else {
throw re;
}
runtime.getGlobalVariables().set("$!", oldExc); // Restore $!
return false;
}
}
Expand Down
3 changes: 3 additions & 0 deletions core/src/main/java/org/jruby/Ruby.java
Expand Up @@ -3228,6 +3228,7 @@ public void tearDown(boolean systemExit) {

while (!atExitBlocks.empty()) {
RubyProc proc = atExitBlocks.pop();
// IRubyObject oldExc = context.runtime.getGlobalVariables().get("$!"); // Save $!
try {
proc.call(getCurrentContext(), IRubyObject.NULL_ARRAY);
} catch (RaiseException rj) {
Expand All @@ -3242,6 +3243,8 @@ public void tearDown(boolean systemExit) {
status = RubyNumeric.fix2int(statusObj);
}
}
// Reset $! now that rj has been handled
// context.runtime.getGlobalVariables().set("$!", oldExc);
}
}

Expand Down
5 changes: 2 additions & 3 deletions core/src/main/java/org/jruby/RubyBasicObject.java
Expand Up @@ -1150,8 +1150,7 @@ public IRubyObject op_not_equal(ThreadContext context, IRubyObject other) {
*/
@Override
public int compareTo(IRubyObject other) {
// SSS FIXME: How do we get access to the runtime here?
// IRubyObject oldExc = runtime.getGlobalVariables().get("$!");
IRubyObject oldExc = getRuntime().getGlobalVariables().get("$!");
try {
IRubyObject cmp = invokedynamic(getRuntime().getCurrentContext(),
this, OP_CMP, other);
Expand All @@ -1161,7 +1160,7 @@ public int compareTo(IRubyObject other) {
return (int) cmp.convertToInteger().getLongValue();
}
} catch (RaiseException ex) {
// runtime.getGlobalVariables().set("$!", oldExc);
getRuntime().getGlobalVariables().set("$!", oldExc);
}

/* We used to raise an error if two IRubyObject were not comparable, but
Expand Down
7 changes: 4 additions & 3 deletions core/src/main/java/org/jruby/RubyClass.java
Expand Up @@ -684,12 +684,13 @@ private static IRubyObject checkFuncallMissing(ThreadContext context, RubyClass
return null;
}
else {
IRubyObject oldExc = runtime.getGlobalVariables().get("$!"); // Save $!
try {
return checkFuncallExec(context, self, method, args);
} catch (RaiseException e) {
// clear $!
context.setErrorInfo(context.nil);
return checkFuncallFailed(context, self, method, runtime.getNoMethodError(), args);
IRubyObject ret = checkFuncallFailed(context, self, method, runtime.getNoMethodError(), args);
runtime.getGlobalVariables().set("$!", oldExc); // restore $!
return ret;
}
}
}
Expand Down
1 change: 0 additions & 1 deletion core/src/main/java/org/jruby/RubyComparable.java
Expand Up @@ -149,7 +149,6 @@ private static IRubyObject callCmpMethod(ThreadContext context, IRubyObject recv
if (e.getException().kind_of_p(context, runtime.getStandardError()).isTrue()) {
// clear error info resulting from failure to compare (JRUBY-3292)
runtime.getGlobalVariables().set("$!", savedError);
context.setErrorInfo(runtime.getNil()); // SSS FIXME: Is this correct?
return returnValueOnError;
} else {
throw e;
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/RubyEnumerator.java
Expand Up @@ -756,7 +756,7 @@ public void run() {
IRubyObject finalObject = NEVER;

try {
IRubyObject oldExc = runtime.getGlobalVariables().get("$!");
IRubyObject oldExc = runtime.getGlobalVariables().get("$!"); // Save $!
final TerminateEnumeration terminateEnumeration = new TerminateEnumeration();
try {
object.callMethod(context, method, methodArgs, CallBlock.newCallClosure(object, object.getMetaClass(), Arity.OPTIONAL, new BlockCallback() {
Expand Down Expand Up @@ -784,9 +784,9 @@ public IRubyObject call(ThreadContext context, IRubyObject[] args, Block block)
}
// ignore, we're shutting down
} catch (RaiseException re) {
runtime.getGlobalVariables().set("$!", oldExc);
if (DEBUG) System.out.println(Thread.currentThread().getName() + ": exception at toplevel: " + re.getException());
finalObject = re.getException();
runtime.getGlobalVariables().set("$!", oldExc); // Restore $!
} catch (Throwable t) {
if (DEBUG) {
System.out.println(Thread.currentThread().getName() + ": exception at toplevel: " + t);
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/RubyFileTest.java
Expand Up @@ -277,7 +277,7 @@ public static IRubyObject sticky_p(IRubyObject recv, IRubyObject filename) {
@JRubyMethod(name = "symlink?", required = 1, module = true)
public static RubyBoolean symlink_p(IRubyObject recv, IRubyObject filename) {
Ruby runtime = recv.getRuntime();
IRubyObject oldExc = runtime.getGlobalVariables().get("$!");
IRubyObject oldExc = runtime.getGlobalVariables().get("$!"); // Save $!

try {
// Note: We can't use file.exists() to check whether the symlink
Expand All @@ -291,7 +291,7 @@ public static RubyBoolean symlink_p(IRubyObject recv, IRubyObject filename) {
} catch (SecurityException re) {
return runtime.getFalse();
} catch (RaiseException re) {
runtime.getGlobalVariables().set("$!", oldExc);
runtime.getGlobalVariables().set("$!", oldExc); // Restore $!
return runtime.getFalse();
}
}
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/RubyIO.java
Expand Up @@ -1942,13 +1942,13 @@ protected static IRubyObject ioClose(Ruby runtime, IRubyObject io) {
ThreadContext context = runtime.getCurrentContext();
IRubyObject closed = io.checkCallMethod(context, "closed?");
if (closed != null && closed.isTrue()) return io;
IRubyObject oldExc = context.getErrorInfo();
IRubyObject oldExc = runtime.getGlobalVariables().get("$!"); // Save $!
try {
return io.checkCallMethod(context, "close");
} catch (RaiseException re) {
if (re.getMessage().contains(CLOSED_STREAM_MSG)) {
// ignore
context.setErrorInfo(oldExc);
runtime.getGlobalVariables().set("$!", oldExc); // Restore $!
return context.nil;
} else {
throw re;
Expand Down
8 changes: 4 additions & 4 deletions core/src/main/java/org/jruby/RubyKernel.java
Expand Up @@ -1309,7 +1309,7 @@ public static IRubyObject loop(ThreadContext context, IRubyObject recv, Block bl
}
IRubyObject nil = runtime.getNil();
RubyClass stopIteration = runtime.getStopIteration();
IRubyObject oldExc = runtime.getGlobalVariables().get("$!");
IRubyObject oldExc = runtime.getGlobalVariables().get("$!"); // Save $!
try {
while (true) {
block.yieldSpecific(context);
Expand All @@ -1320,7 +1320,7 @@ public static IRubyObject loop(ThreadContext context, IRubyObject recv, Block bl
if (!stopIteration.op_eqq(context, ex.getException()).isTrue()) {
throw ex;
} else {
runtime.getGlobalVariables().set("$!", oldExc);
runtime.getGlobalVariables().set("$!", oldExc); // Restore $!
}
}
return nil;
Expand Down Expand Up @@ -1678,7 +1678,7 @@ private static IRubyObject execCommon(Ruby runtime, IRubyObject env, IRubyObject
System.setProperty("user.dir", runtime.getCurrentDirectory());

if (nativeExec) {
IRubyObject oldExc = runtime.getGlobalVariables().get("$!");
IRubyObject oldExc = runtime.getGlobalVariables().get("$!"); // Save $!
try {
ShellLauncher.LaunchConfig cfg = new ShellLauncher.LaunchConfig(runtime, args, true);

Expand Down Expand Up @@ -1716,7 +1716,7 @@ private static IRubyObject execCommon(Ruby runtime, IRubyObject env, IRubyObject
// Only here because native exec could not exec (always -1)
nativeFailed = true;
} catch (RaiseException e) {
runtime.getGlobalVariables().set("$!", oldExc);
runtime.getGlobalVariables().set("$!", oldExc); // Restore $!
} catch (Exception e) {
throw runtime.newErrnoENOENTError("cannot execute: " + e.getLocalizedMessage());
}
Expand Down
6 changes: 4 additions & 2 deletions core/src/main/java/org/jruby/RubyModule.java
Expand Up @@ -859,12 +859,14 @@ public void undef(ThreadContext context, String name) {
}

if (name.equals("method_missing")) {

IRubyObject oldExc = runtime.getGlobalVariables().get("$!"); // Save $!
try {
removeMethod(context, name);
} catch (RaiseException t) {
if(!(t.getException() instanceof RubyNameError)) {
if (!(t.getException() instanceof RubyNameError)) {
throw t;
} else {
runtime.getGlobalVariables().set("$!", oldExc); // Restore $!
}
}
return;
Expand Down
9 changes: 4 additions & 5 deletions core/src/main/java/org/jruby/RubyNumeric.java
Expand Up @@ -409,15 +409,15 @@ public double yield(RubyString arg, boolean strict) {
protected IRubyObject[] getCoerced(ThreadContext context, IRubyObject other, boolean error) {
IRubyObject result;

IRubyObject savedError = context.runtime.getGlobalVariables().get("$!");
IRubyObject savedError = context.runtime.getGlobalVariables().get("$!"); // Save $!
try {
result = other.callMethod(context, "coerce", this);
} catch (RaiseException e) {
if (error) {
throw getRuntime().newTypeError(
other.getMetaClass().getName() + " can't be coerced into " + getMetaClass().getName());
} else {
context.runtime.getGlobalVariables().set("$!", savedError);
context.runtime.getGlobalVariables().set("$!", savedError); // Restore $!
}

return null;
Expand Down Expand Up @@ -461,7 +461,7 @@ protected final IRubyObject coerceBody(ThreadContext context, IRubyObject other)
protected final RubyArray doCoerce(ThreadContext context, IRubyObject other, boolean err) {
IRubyObject result;

IRubyObject savedError = context.runtime.getGlobalVariables().get("$!");
IRubyObject savedError = context.runtime.getGlobalVariables().get("$!"); // Svae $!
try {
result = coerceBody(context, other);
} catch (RaiseException e) {
Expand All @@ -470,9 +470,8 @@ protected final RubyArray doCoerce(ThreadContext context, IRubyObject other, boo
warnings.warn("in the next release. Return nil in #coerce if the coercion is impossible.");
if (err) {
coerceFailed(context, other);
} else {
context.runtime.getGlobalVariables().set("$!", savedError);
}
context.runtime.getGlobalVariables().set("$!", savedError); // Restore $!
return null;
}

Expand Down
22 changes: 15 additions & 7 deletions core/src/main/java/org/jruby/RubyTime.java
Expand Up @@ -832,17 +832,21 @@ public RubyBoolean isdst() {

@JRubyMethod
public IRubyObject zone() {
Ruby runtime = getRuntime();
if (isTzRelative) return runtime.getNil();

String envTZ = getEnvTimeZone(runtime).toString();
final String zone = RubyTime.zoneHelper(getEnvTimeZone(getRuntime()).toString(), dt, isTzRelative);
if (zone == null) return getRuntime().getNil();
return getRuntime().newString(zone);
}

public static String zoneHelper(String envTZ, DateTime dt, boolean isTzRelative) {
if (isTzRelative) return null;

// see declaration of SHORT_TZNAME
if (SHORT_STD_TZNAME.containsKey(envTZ) && ! dt.getZone().toTimeZone().inDaylightTime(dt.toDate())) {
return runtime.newString(SHORT_STD_TZNAME.get(envTZ));
return SHORT_STD_TZNAME.get(envTZ);
}

if (SHORT_DL_TZNAME.containsKey(envTZ) && dt.getZone().toTimeZone().inDaylightTime(dt.toDate())) {
return runtime.newString(SHORT_DL_TZNAME.get(envTZ));
return SHORT_DL_TZNAME.get(envTZ);
}

String zone = dt.getZone().getShortName(dt.getMillis());
Expand All @@ -865,7 +869,7 @@ public IRubyObject zone() {
}
}

return runtime.newString(zone);
return zone;
}

public void setDateTime(DateTime dt) {
Expand Down Expand Up @@ -1216,17 +1220,21 @@ protected static RubyTime s_mload(IRubyObject recv, RubyTime time, IRubyObject f

int offset = 0;
if (offsetVar != null && offsetVar.respondsTo("to_int")) {
IRubyObject oldExc = runtime.getGlobalVariables().get("$!"); // Save $!
try {
offset = offsetVar.convertToInteger().getIntValue() * 1000;
} catch (RaiseException typeError) {
runtime.getGlobalVariables().set("$!", oldExc); // Restore $!
}
}

String zone = "";
if (zoneVar != null && zoneVar.respondsTo("to_str")) {
IRubyObject oldExc = runtime.getGlobalVariables().get("$!"); // Save $!
try {
zone = zoneVar.convertToString().toString();
} catch (RaiseException typeError) {
runtime.getGlobalVariables().set("$!", oldExc); // Restore $!
}
}

Expand Down
2 changes: 2 additions & 0 deletions core/src/main/java/org/jruby/ext/etc/RubyEtc.java
Expand Up @@ -116,6 +116,7 @@ private static IRubyObject intoStringArray(Ruby runtime, String[] members) {
public static IRubyObject getpwuid(IRubyObject recv, IRubyObject[] args) {
Ruby runtime = recv.getRuntime();
POSIX posix = runtime.getPosix();
IRubyObject oldExc = runtime.getGlobalVariables().get("$!"); // Save $!
try {
int uid = args.length == 0 ? posix.getuid() : RubyNumeric.fix2int(args[0]);
Passwd pwd = posix.getpwuid(uid);
Expand All @@ -128,6 +129,7 @@ public static IRubyObject getpwuid(IRubyObject recv, IRubyObject[] args) {
return setupPasswd(runtime, pwd);
} catch (RaiseException re) {
if (runtime.getNotImplementedError().isInstance(re.getException())) {
runtime.getGlobalVariables().set("$!", oldExc); // Restore $!
return runtime.getNil();
}
throw re;
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/java/org/jruby/ext/pathname/RubyPathname.java
Expand Up @@ -394,12 +394,14 @@ public IRubyObject each_entry(ThreadContext context, Block block) {

@JRubyMethod(name = {"unlink", "delete"})
public IRubyObject unlink(ThreadContext context) {
IRubyObject oldExc = context.runtime.getGlobalVariables().get("$!"); // Save $!
try {
return context.runtime.getDir().callMethod(context, "unlink", getPath());
} catch (RaiseException ex) {
if (!context.runtime.getErrno().getClass("ENOTDIR").isInstance(ex.getException())) {
throw ex;
}
context.runtime.getGlobalVariables().set("$!", oldExc); // Restore $!
return context.runtime.getFile().callMethod(context, "unlink", getPath());
}
}
Expand Down