File tree Expand file tree Collapse file tree 3 files changed +5
-22
lines changed Expand file tree Collapse file tree 3 files changed +5
-22
lines changed Original file line number Diff line number Diff line change @@ -25,21 +25,6 @@ public PyIter(IntPtr ptr) : base(ptr)
25
25
{
26
26
}
27
27
28
- private static IntPtr FromObject ( PyObject iterable )
29
- {
30
- if ( iterable == null )
31
- {
32
- throw new NullReferenceException ( ) ;
33
- }
34
- IntPtr val = Runtime . PyObject_GetIter ( iterable . obj ) ;
35
- if ( val == IntPtr . Zero )
36
- {
37
- throw new PythonException ( ) ;
38
- }
39
- return val ;
40
- }
41
-
42
-
43
28
/// <summary>
44
29
/// PyIter factory function.
45
30
/// </summary>
@@ -52,13 +37,10 @@ public static PyIter GetIter(PyObject iterable)
52
37
{
53
38
if ( iterable == null )
54
39
{
55
- throw new NullReferenceException ( ) ;
40
+ throw new ArgumentNullException ( ) ;
56
41
}
57
42
IntPtr val = Runtime . PyObject_GetIter ( iterable . obj ) ;
58
- if ( val == IntPtr . Zero )
59
- {
60
- throw new PythonException ( ) ;
61
- }
43
+ PythonException . ThrowIfIsNull ( val ) ;
62
44
return new PyIter ( val ) ;
63
45
}
64
46
Original file line number Diff line number Diff line change @@ -261,10 +261,11 @@ internal static void ThrowIfIsNull(BorrowedReference reference)
261
261
}
262
262
}
263
263
264
- public static void ThrowIfIsNotZero ( int value )
264
+ public static void ThrowIfIsNotZero ( int value , Action onBeforeThrow = null )
265
265
{
266
266
if ( value != 0 )
267
267
{
268
+ onBeforeThrow ? . Invoke ( ) ;
268
269
throw new PythonException ( ) ;
269
270
}
270
271
}
Original file line number Diff line number Diff line change @@ -74,7 +74,7 @@ private static IntPtr FromArray(PyObject[] items)
74
74
IntPtr ptr = items [ i ] . obj ;
75
75
Runtime . XIncref ( ptr ) ;
76
76
int res = Runtime . PyTuple_SetItem ( val , i , ptr ) ;
77
- PythonException . ThrowIfIsNotZero ( res ) ;
77
+ PythonException . ThrowIfIsNotZero ( res , ( ) => Runtime . Py_DecRef ( val ) ) ;
78
78
}
79
79
return val ;
80
80
}
You can’t perform that action at this time.
0 commit comments