Navigation Menu

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
5 changes: 3 additions & 2 deletions core/src/main/java/org/jruby/ext/tempfile/Tempfile.java
Expand Up @@ -203,17 +203,18 @@ public IRubyObject unlink(ThreadContext context) {
POSIX posix = runtime.getPosix();

if (posix.isNative() && !Platform.IS_WINDOWS) {
IRubyObject oldExc = context.runtime.getGlobalVariables().get("$!"); // Save $!
try {
RubyFile.unlink(context, this);
} catch (RaiseException re) {
RubyException excp = re.getException();
if (!(excp instanceof RubySystemCallError)) throw re;

int errno = (int)((RubySystemCallError)excp).errno().convertToInteger().getLongValue();
if (errno != Errno.ENOENT.intValue() &&
errno != Errno.EACCES.intValue()) {
if (errno != Errno.ENOENT.intValue() && errno != Errno.EACCES.intValue()) {
throw re;
}
context.runtime.getGlobalVariables().set("$!", oldExc); // Restore $!
}
openFile.setPath(null);
tmpname = context.nil;
Expand Down
Expand Up @@ -199,10 +199,7 @@ public IRubyObject interpret(ThreadContext context, IRubyObject self, Interprete
ipc = instr.interpretAndGetNewIPC(context, currDynScope, currScope, self, temp, ipc);
} else {
Object result = instr.interpret(context, currScope, currDynScope, self, temp);

if (instr instanceof ResultInstr) {
setResult(temp, currDynScope, ((ResultInstr) instr).getResult(), result);
}
setResult(temp, currDynScope, instr, result);
}
}
} catch (Throwable t) {
Expand Down
14 changes: 2 additions & 12 deletions core/src/main/java/org/jruby/ir/interpreter/InterpreterEngine.java
Expand Up @@ -496,23 +496,13 @@ private static void processOtherOp(ThreadContext context, Instr instr, Operation
}
}



/*
* If you put this code into the method above it will hard crash some production builds of C2 in Java 8. We aren't
* sure exactly which builds, but it seems to appear more often in Linux builds than Mac. - Chris Seaton
*/

private static void extractToMethodToAvoidC2Crash(ThreadContext context, Instr instr, Throwable t) {
if (!(t instanceof Unrescuable)) {
if (!instr.canRaiseException()) {
System.err.println("BUG: Got exception " + t + " but instr " + instr + " is not supposed to be raising exceptions!");
}
if ((t instanceof RaiseException) && context.runtime.getGlobalVariables().get("$!") != IRRuntimeHelpers.unwrapRubyException(t)) {
System.err.println("BUG: $! and exception are not matching up.");
System.err.println("$!: " + context.runtime.getGlobalVariables().get("$!"));
System.err.println("t : " + t);
}
if (!(t instanceof Unrescuable) && !instr.canRaiseException()) {
System.err.println("BUG: Got exception " + t + " but instr " + instr + " is not supposed to be raising exceptions!");
}
}

Expand Down
2 changes: 2 additions & 0 deletions core/src/main/java/org/jruby/java/proxies/MapJavaProxy.java
Expand Up @@ -86,10 +86,12 @@ private RubyHashMap getOrCreateRubyHashMap() {
}
// (JavaProxy)recv).getObject() might raise exception when
// wrong number of args are given to the constructor.
IRubyObject oldExc = getRuntime().getGlobalVariables().get("$!"); // Save $!
try {
wrappedMap.setSize(((Map)((JavaProxy)this).getObject()).size());
} catch (RaiseException e) {
wrappedMap.setSize(0);
getRuntime().getGlobalVariables().set("$!", oldExc); // Restore $!
}
return wrappedMap;
}
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/java/org/jruby/javasupport/Java.java
Expand Up @@ -953,6 +953,7 @@ private static RubyModule getProxyOrPackageUnderPackage(ThreadContext context, f
} catch (RaiseException re) { /* expected */
RubyException rubyEx = re.getException();
if (rubyEx.kind_of_p(context, runtime.getStandardError()).isTrue()) {
// SSS FIXME: Why is this being done conditionally??
Helpers.setErrorInfo(runtime, previousErrorInfo);
}
} catch (Exception e) { /* expected */ }
Expand Down Expand Up @@ -1019,6 +1020,7 @@ private static RubyModule getTopLevelProxyOrPackage(ThreadContext context, final
} catch (RaiseException re) { /* not primitive or lc class */
RubyException rubyEx = re.getException();
if (rubyEx.kind_of_p(context, runtime.getStandardError()).isTrue()) {
// SSS FIXME: Why is this being set to nil??
Helpers.setErrorInfo(runtime, runtime.getNil());
}
} catch (Exception e) { /* not primitive or lc class */ }
Expand Down

0 comments on commit b9af305

Please sign in to comment.