File tree Expand file tree Collapse file tree 2 files changed +8
-12
lines changed Expand file tree Collapse file tree 2 files changed +8
-12
lines changed Original file line number Diff line number Diff line change @@ -103,15 +103,15 @@ internal NewReference GetDefaultArgs(BorrowedReference args)
103
103
MethodBase mi = methods [ 0 ] ;
104
104
ParameterInfo [ ] pi = mi . GetParameters ( ) ;
105
105
int clrnargs = pi . Length - 1 ;
106
- IntPtr defaultArgs = Runtime . PyTuple_New ( clrnargs - pynargs ) ;
106
+ var defaultArgs = Runtime . PyTuple_New ( clrnargs - pynargs ) ;
107
107
for ( var i = 0 ; i < clrnargs - pynargs ; i ++ )
108
108
{
109
109
if ( pi [ i + pynargs ] . DefaultValue == DBNull . Value )
110
110
{
111
111
continue ;
112
112
}
113
- IntPtr arg = Converter . ToPython ( pi [ i + pynargs ] . DefaultValue , pi [ i + pynargs ] . ParameterType ) ;
114
- Runtime . PyTuple_SetItem ( defaultArgs , i , arg ) ;
113
+ using var arg = Converter . ToPython ( pi [ i + pynargs ] . DefaultValue , pi [ i + pynargs ] . ParameterType ) ;
114
+ Runtime . PyTuple_SetItem ( defaultArgs . Borrow ( ) , i , arg . Steal ( ) ) ;
115
115
}
116
116
return defaultArgs ;
117
117
}
Original file line number Diff line number Diff line change @@ -22,15 +22,15 @@ public Iterator(IEnumerator e, Type elemType)
22
22
/// <summary>
23
23
/// Implements support for the Python iteration protocol.
24
24
/// </summary>
25
- public static IntPtr tp_iternext ( IntPtr ob )
25
+ public static NewReference tp_iternext ( BorrowedReference ob )
26
26
{
27
- var self = GetManagedObject ( ob ) as Iterator ;
27
+ var self = ( Iterator ) GetManagedObject ( ob ) ! ;
28
28
try
29
29
{
30
30
if ( ! self . iter . MoveNext ( ) )
31
31
{
32
32
Exceptions . SetError ( Exceptions . StopIteration , Runtime . PyNone ) ;
33
- return IntPtr . Zero ;
33
+ return default ;
34
34
}
35
35
}
36
36
catch ( Exception e )
@@ -40,16 +40,12 @@ public static IntPtr tp_iternext(IntPtr ob)
40
40
e = e . InnerException ;
41
41
}
42
42
Exceptions . SetError ( e ) ;
43
- return IntPtr . Zero ;
43
+ return default ;
44
44
}
45
45
object item = self . iter . Current ;
46
46
return Converter . ToPython ( item , self . elemType ) ;
47
47
}
48
48
49
- public static IntPtr tp_iter ( IntPtr ob )
50
- {
51
- Runtime . XIncref ( ob ) ;
52
- return ob ;
53
- }
49
+ public static NewReference tp_iter ( BorrowedReference ob ) => new ( ob ) ;
54
50
}
55
51
}
You can’t perform that action at this time.
0 commit comments