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)
2525 {
2626 }
2727
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-
4328 /// <summary>
4429 /// PyIter factory function.
4530 /// </summary>
@@ -52,13 +37,10 @@ public static PyIter GetIter(PyObject iterable)
5237 {
5338 if ( iterable == null )
5439 {
55- throw new NullReferenceException ( ) ;
40+ throw new ArgumentNullException ( ) ;
5641 }
5742 IntPtr val = Runtime . PyObject_GetIter ( iterable . obj ) ;
58- if ( val == IntPtr . Zero )
59- {
60- throw new PythonException ( ) ;
61- }
43+ PythonException . ThrowIfIsNull ( val ) ;
6244 return new PyIter ( val ) ;
6345 }
6446
Original file line number Diff line number Diff line change @@ -261,10 +261,11 @@ internal static void ThrowIfIsNull(BorrowedReference reference)
261261 }
262262 }
263263
264- public static void ThrowIfIsNotZero ( int value )
264+ public static void ThrowIfIsNotZero ( int value , Action onBeforeThrow = null )
265265 {
266266 if ( value != 0 )
267267 {
268+ onBeforeThrow ? . Invoke ( ) ;
268269 throw new PythonException ( ) ;
269270 }
270271 }
Original file line number Diff line number Diff line change @@ -74,7 +74,7 @@ private static IntPtr FromArray(PyObject[] items)
7474 IntPtr ptr = items [ i ] . obj ;
7575 Runtime . XIncref ( ptr ) ;
7676 int res = Runtime . PyTuple_SetItem ( val , i , ptr ) ;
77- PythonException . ThrowIfIsNotZero ( res ) ;
77+ PythonException . ThrowIfIsNotZero ( res , ( ) => Runtime . Py_DecRef ( val ) ) ;
7878 }
7979 return val ;
8080 }
You can’t perform that action at this time.
0 commit comments