From d0fbabf3c0c91e7d874d080ef5736bb6e94f3c63 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 1c871d283..ef463c8e6 100644 --- a/src/core/IronPython/Runtime/Operations/PythonOps.cs +++ b/src/core/IronPython/Runtime/Operations/PythonOps.cs @@ -2505,16 +2505,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 a7d0252126a093ff3654679fc8480d9a3bfb0dd2 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 ef463c8e6..8cf2983fc 100644 --- a/src/core/IronPython/Runtime/Operations/PythonOps.cs +++ b/src/core/IronPython/Runtime/Operations/PythonOps.cs @@ -2504,10 +2504,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) {