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

Skip to content

Commit cf606a2

Browse files
committed
switched iterator.cs and indexer.cs to the new style references
1 parent 0d60500 commit cf606a2

File tree

2 files changed

+8
-12
lines changed

2 files changed

+8
-12
lines changed

src/runtime/indexer.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,15 @@ internal NewReference GetDefaultArgs(BorrowedReference args)
103103
MethodBase mi = methods[0];
104104
ParameterInfo[] pi = mi.GetParameters();
105105
int clrnargs = pi.Length - 1;
106-
IntPtr defaultArgs = Runtime.PyTuple_New(clrnargs - pynargs);
106+
var defaultArgs = Runtime.PyTuple_New(clrnargs - pynargs);
107107
for (var i = 0; i < clrnargs - pynargs; i++)
108108
{
109109
if (pi[i + pynargs].DefaultValue == DBNull.Value)
110110
{
111111
continue;
112112
}
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());
115115
}
116116
return defaultArgs;
117117
}

src/runtime/iterator.cs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ public Iterator(IEnumerator e, Type elemType)
2222
/// <summary>
2323
/// Implements support for the Python iteration protocol.
2424
/// </summary>
25-
public static IntPtr tp_iternext(IntPtr ob)
25+
public static NewReference tp_iternext(BorrowedReference ob)
2626
{
27-
var self = GetManagedObject(ob) as Iterator;
27+
var self = (Iterator)GetManagedObject(ob)!;
2828
try
2929
{
3030
if (!self.iter.MoveNext())
3131
{
3232
Exceptions.SetError(Exceptions.StopIteration, Runtime.PyNone);
33-
return IntPtr.Zero;
33+
return default;
3434
}
3535
}
3636
catch (Exception e)
@@ -40,16 +40,12 @@ public static IntPtr tp_iternext(IntPtr ob)
4040
e = e.InnerException;
4141
}
4242
Exceptions.SetError(e);
43-
return IntPtr.Zero;
43+
return default;
4444
}
4545
object item = self.iter.Current;
4646
return Converter.ToPython(item, self.elemType);
4747
}
4848

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);
5450
}
5551
}

0 commit comments

Comments
 (0)