@@ -24,27 +24,18 @@ internal ExceptionClassObject(Type tp) : base(tp)
24
24
{
25
25
}
26
26
27
- internal static Exception ToException ( IntPtr ob )
27
+ internal static Exception ToException ( BorrowedReference ob )
28
28
{
29
29
var co = GetManagedObject ( ob ) as CLRObject ;
30
- if ( co == null )
31
- {
32
- return null ;
33
- }
34
- var e = co . inst as Exception ;
35
- if ( e == null )
36
- {
37
- return null ;
38
- }
39
- return e ;
30
+ return co ? . inst as Exception ;
40
31
}
41
32
42
33
/// <summary>
43
34
/// Exception __repr__ implementation
44
35
/// </summary>
45
36
public new static IntPtr tp_repr ( IntPtr ob )
46
37
{
47
- Exception e = ToException ( ob ) ;
38
+ Exception e = ToException ( new BorrowedReference ( ob ) ) ;
48
39
if ( e == null )
49
40
{
50
41
return Exceptions . RaiseTypeError ( "invalid object" ) ;
@@ -67,7 +58,7 @@ internal static Exception ToException(IntPtr ob)
67
58
/// </summary>
68
59
public new static IntPtr tp_str ( IntPtr ob )
69
60
{
70
- Exception e = ToException ( ob ) ;
61
+ Exception e = ToException ( new BorrowedReference ( ob ) ) ;
71
62
if ( e == null )
72
63
{
73
64
return Exceptions . RaiseTypeError ( "invalid object" ) ;
@@ -157,7 +148,7 @@ internal static void Shutdown()
157
148
/// pointer.
158
149
/// </summary>
159
150
/// <param name="ob">The python object wrapping </param>
160
- internal static void SetArgsAndCause ( IntPtr ob )
151
+ internal static void SetArgsAndCause ( BorrowedReference ob )
161
152
{
162
153
// e: A CLR Exception
163
154
Exception e = ExceptionClassObject . ToException ( ob ) ;
@@ -178,13 +169,13 @@ internal static void SetArgsAndCause(IntPtr ob)
178
169
args = Runtime . PyTuple_New ( 0 ) ;
179
170
}
180
171
181
- Marshal . WriteIntPtr ( ob , ExceptionOffset . args , args ) ;
172
+ Marshal . WriteIntPtr ( ob . DangerousGetAddress ( ) , ExceptionOffset . args , args ) ;
182
173
183
174
if ( e . InnerException != null )
184
175
{
185
176
// Note: For an AggregateException, InnerException is only the first of the InnerExceptions.
186
- IntPtr cause = CLRObject . GetInstHandle ( e . InnerException ) ;
187
- Marshal . WriteIntPtr ( ob , ExceptionOffset . cause , cause ) ;
177
+ using var cause = CLRObject . GetReference ( e . InnerException ) ;
178
+ Runtime . PyException_SetCause ( ob , cause . Steal ( ) ) ;
188
179
}
189
180
}
<
3C0F
td data-grid-cell-id="diff-d8671ce7630fc9163c6732cfe4309cc3ccb1089b33d7e9809d516f809fc36eb2-190-181-0" data-selected="false" role="gridcell" style="background-color:var(--bgColor-default);text-align:center" tabindex="-1" valign="top" class="focusable-grid-cell diff-line-number position-relative diff-line-number-neutral left-side">190
181
0 commit comments