Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5ea9c3c

Browse files
committed
Code review fixes
1 parent 480a549 commit 5ea9c3c

File tree

3 files changed

+8
-16
lines changed

3 files changed

+8
-16
lines changed

src/runtime/clrobject.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ protected override void OnLoad(InterDomainContext context)
106106

107107
public override string ToString()
108108
{
109-
return $"<CLRObject wrapping {inst}>";
109+
return $"<CLRObject: {inst}>";
110110
}
111111
}
112112
}

src/runtime/exceptions.cs

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ internal static Exception ToException(IntPtr ob)
8989
static void ClearOffsetHelper(IntPtr ob, int offset)
9090
{
9191
var field = Marshal.ReadIntPtr(ob, offset);
92-
Runtime.Py_CLEAR(ref field);
92+
Runtime.XDecref(field);
93+
Marshal.WriteIntPtr(ob, offset, IntPtr.Zero);
9394
}
9495

9596
// As seen in exceptions.c, every derived type must also clean the base.
@@ -200,19 +201,9 @@ internal static void SetArgsAndCause(IntPtr ob)
200201

201202
if (e.InnerException != null)
202203
{
203-
if(e.InnerException is PythonException)
204-
{
205-
// If the error is a Python exception, write the real one
206-
var pyerr = (e.InnerException as PythonException);
207-
Runtime.XIncref(pyerr.PyValue);
208-
Runtime.PyException_SetCause(ob, pyerr.PyValue);
209-
}
210-
else
211-
{
212-
// Note: For an AggregateException, InnerException is only the first of the InnerExceptions.
213-
IntPtr cause = CLRObject.GetInstHandle(e.InnerException);
214-
Runtime.PyException_SetCause(ob, cause);
215-
}
204+
// Note: For an AggregateException, InnerException is only the first of the InnerExceptions.
205+
IntPtr cause = CLRObject.GetInstHandle(e.InnerException);
206+
Runtime.PyException_SetCause(ob, cause);
216207
}
217208
}
218209

tests/test_exceptions.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,8 @@ def do_test_leak():
429429
orig_exc = {x for x in get_all_objects() if isinstance(x, Exception)}
430430
func()
431431
exc = {x for x in get_all_objects() if isinstance(x, Exception)}
432-
assert not exc - orig_exc
432+
possibly_leaked = exc - orig_exc
433+
assert not possibly_leaked
433434

434435
return do_test_leak
435436

0 commit comments

Comments
 (0)