From 171460613a38e2b1d29fe0c789dc89850ed054f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Lozier?= Date: Sat, 15 Feb 2020 15:35:55 -0500 Subject: [PATCH 1/2] Remove MakeRethrowExceptionWorker --- src/core/IronPython/Compiler/Ast/AstMethods.cs | 1 - src/core/IronPython/Compiler/Ast/WithStatement.cs | 4 ++-- src/core/IronPython/Runtime/Operations/PythonOps.cs | 10 ---------- 3 files changed, 2 insertions(+), 13 deletions(-) diff --git a/src/core/IronPython/Compiler/Ast/AstMethods.cs b/src/core/IronPython/Compiler/Ast/AstMethods.cs index da27a5ab0..c0275d530 100644 --- a/src/core/IronPython/Compiler/Ast/AstMethods.cs +++ b/src/core/IronPython/Compiler/Ast/AstMethods.cs @@ -37,7 +37,6 @@ internal static class AstMethods { public static readonly MethodInfo RemoveModule = GetMethod((Action)PythonOps.RemoveModule); public static readonly MethodInfo ModuleStarted = GetMethod((Action)PythonOps.ModuleStarted); public static readonly MethodInfo MakeRethrownException = GetMethod((Func)PythonOps.MakeRethrownException); - public static readonly MethodInfo MakeRethrowExceptionWorker = GetMethod((Func)PythonOps.MakeRethrowExceptionWorker); public static readonly MethodInfo MakeException = GetMethod((Func)PythonOps.MakeException); public static readonly MethodInfo MakeExceptionWithCause = GetMethod((Func)PythonOps.MakeExceptionWithCause); public static readonly MethodInfo MakeSlice = GetMethod((Func)PythonOps.MakeSlice); diff --git a/src/core/IronPython/Compiler/Ast/WithStatement.cs b/src/core/IronPython/Compiler/Ast/WithStatement.cs index 6712de29b..e21f5f69b 100644 --- a/src/core/IronPython/Compiler/Ast/WithStatement.cs +++ b/src/core/IronPython/Compiler/Ast/WithStatement.cs @@ -206,8 +206,8 @@ public override MSAst.Expression Reduce() { UpdateLineUpdated(true), Ast.Throw( Ast.Call( - AstMethods.MakeRethrowExceptionWorker, - exception + AstMethods.MakeRethrownException, + Parent.LocalContext ) ) ) diff --git a/src/core/IronPython/Runtime/Operations/PythonOps.cs b/src/core/IronPython/Runtime/Operations/PythonOps.cs index 82f0f75be..c0cf75bac 100644 --- a/src/core/IronPython/Runtime/Operations/PythonOps.cs +++ b/src/core/IronPython/Runtime/Operations/PythonOps.cs @@ -2469,16 +2469,6 @@ public static Exception MakeRethrownException(CodeContext/*!*/ context) { PythonTuple t = GetExceptionInfo(context); Debug.Assert(t[1] == GetRawContextException()); Exception e = MakeExceptionWorker(context, t[0], t[1], t[2], null, suppressContext: false, forRethrow: true); - return MakeRethrowExceptionWorker(e); - } - - /// - /// helper function for re-raised exception. - /// This entry point is used by 'raise' inside 'with' statement - /// - /// - /// - public static Exception MakeRethrowExceptionWorker(Exception e) { e.RemoveTraceBack(); ExceptionHelpers.UpdateForRethrow(e); return e; From 0d9b074e478485121c2dc67fe49c96b915aca59a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Lozier?= Date: Sat, 15 Feb 2020 16:32:22 -0500 Subject: [PATCH 2/2] Don't remove traceback on rethrow --- src/core/IronPython/Runtime/Operations/PythonOps.cs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/core/IronPython/Runtime/Operations/PythonOps.cs b/src/core/IronPython/Runtime/Operations/PythonOps.cs index c0cf75bac..961de320b 100644 --- a/src/core/IronPython/Runtime/Operations/PythonOps.cs +++ b/src/core/IronPython/Runtime/Operations/PythonOps.cs @@ -2468,10 +2468,7 @@ public static PythonTuple GetExceptionInfo(CodeContext/*!*/ context) { public static Exception MakeRethrownException(CodeContext/*!*/ context) { PythonTuple t = GetExceptionInfo(context); Debug.Assert(t[1] == GetRawContextException()); - Exception e = MakeExceptionWorker(context, t[0], t[1], t[2], null, suppressContext: false, forRethrow: true); - e.RemoveTraceBack(); - ExceptionHelpers.UpdateForRethrow(e); - return e; + return MakeExceptionWorker(context, t[0], t[1], t[2], null, suppressContext: false, forRethrow: true); } public static Exception MakeException(CodeContext/*!*/ context, object exception) {