Skip to content

Commit

Permalink
Work around failure to run END blocks after exit(1) on Mono 2.6.x
Browse files Browse the repository at this point in the history
  • Loading branch information
sorear committed Jan 5, 2012
1 parent c4341fe commit 220b37b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
7 changes: 7 additions & 0 deletions lib/Builtins.cs
Expand Up @@ -2452,4 +2452,11 @@ class CrossSource: ItemSource {
from.name);
}
}

public static void exit(int code) {
// Hack - at least some versions of Mono don't fire ProcessExit
// on an explicit Exit() call
Compartment.BeforeExit(null, null);
Environment.Exit(code);
}
}
1 change: 0 additions & 1 deletion lib/CodeGen.cs
Expand Up @@ -3042,7 +3042,6 @@ class NamProcessor {
thandlers["strbuf_seal"] = Methody(null, Tokens.Object_ToString);
thandlers["say"] = Methody(null, Tokens.Console_WriteLine);
thandlers["print"] = Methody(null, Tokens.Console_Write);
thandlers["exit"] = Methody(null, Tokens.Environment_Exit);
thandlers["slurp"] = Methody(null, typeof(File).GetMethod("ReadAllText", new Type[] { Tokens.String }));
thandlers["spew"] = Methody(null, typeof(File).GetMethod("WriteAllText", new Type[] { Tokens.String, Tokens.String }));
thandlers["vvarlist_to_fvarlist"] = Methody(null, Tokens.VVarList.GetMethod("CopyAsArray"));
Expand Down
17 changes: 11 additions & 6 deletions lib/Kernel.cs
Expand Up @@ -4242,11 +4242,15 @@ class Compartment {

fieldsToSave = fields.ToArray();

AppDomain.CurrentDomain.ProcessExit +=
delegate (object sender, EventArgs args) {
while (Top.prev != null) { Pop(); }
Top.end.Run();
};
AppDomain.CurrentDomain.ProcessExit += BeforeExit;
}

[TrueGlobal] internal static bool disable_end;
internal static void BeforeExit(object sender, EventArgs args) {
if (disable_end) return;
disable_end = true;
while (Top.prev != null) { Pop(); }
Top.end.Run();
}

Compartment prev;
Expand Down Expand Up @@ -5584,7 +5588,7 @@ internal class MMDCandidate : MultiCandidate {
main_unit.RunMainline();
} catch (Exception n) {
Console.Error.WriteLine("Unhandled exception: {0}", n);
Environment.Exit(1);
Builtins.exit(1);
}
}

Expand Down Expand Up @@ -6111,6 +6115,7 @@ class LastFrameNode {
// let's try to avoid looping failure
static void Panic(string str) {
Console.Error.WriteLine("Internal error in exception dispatch: " + str);
Compartment.disable_end = true;
Environment.Exit(1);
}

Expand Down

0 comments on commit 220b37b

Please sign in to comment.