File tree Expand file tree Collapse file tree 2 files changed +12
-18
lines changed Expand file tree Collapse file tree 2 files changed +12
-18
lines changed Original file line number Diff line number Diff line change @@ -19,29 +19,23 @@ public IterableWrapper(PyObject pyObj)
19
19
20
20
public IEnumerator < T > GetEnumerator ( )
21
21
{
22
- PyObject iterObject ;
22
+ PyIter iterObject ;
23
23
using ( Py . GIL ( ) )
24
24
{
25
- var iter = Runtime . PyObject_GetIter ( pyObject . Reference ) ;
26
- PythonException . ThrowIfIsNull ( iter ) ;
27
- iterObject = iter . MoveToPyObject ( ) ;
25
+ iterObject = PyIter . GetIter ( pyObject ) ;
28
26
}
29
27
30
- using ( iterObject )
28
+ using var _ = iterObject ;
31
29
while ( true )
32
30
{
33
- using ( Py . GIL ( ) )
34
- {
35
- using var item = Runtime . PyIter_Next ( iterObject ) ;
36
- if ( item . IsNull ( ) )
37
- {
38
- Runtime . CheckExceptionOccurred ( ) ;
39
- iterObject . Dispose ( ) ;
40
- break ;
41
- }
31
+ using var GIL = Py . GIL ( ) ;
42
32
43
- yield return item . MoveToPyObject ( ) . As < T > ( ) ;
33
+ if ( ! iterObject . MoveNext ( ) )
34
+ {
35
+ iterObject . Dispose ( ) ;
36
+ break ;
44
37
}
38
+ yield return iterObject . Current . As < T > ( ) ;
45
39
}
46
40
}
47
41
}
Original file line number Diff line number Diff line change @@ -134,12 +134,12 @@ public static IEnumerable<IntPtr> PyGCGetObjects()
134
134
{
135
135
using var gc = PyModule . Import ( "gc" ) ;
136
136
using var get_objects = gc . GetAttr ( "get_objects" ) ;
137
- using var objs = PyObject_CallObject ( get_objects , args : null ) ;
138
- nint length = PyList_Size ( objs . BorrowOrThrow ( ) ) ;
137
+ using var objs = new PyObject ( PyObject_CallObject ( get_objects , args : null ) . StealOrThrow ( ) ) ;
138
+ nint length = PyList_Size ( objs ) ;
139
139
if ( length < 0 ) throw PythonException . ThrowLastAsClrException ( ) ;
140
140
for ( nint i = 0 ; i < length ; i ++ )
141
141
{
142
- var obj = PyList_GetItem ( objs . Borrow ( ) , i ) ;
142
+ BorrowedReference obj = PyList_GetItem ( objs , i ) ;
143
143
yield return obj . DangerousGetAddress ( ) ;
144
144
}
145
145
}
You can’t perform that action at this time.
0 commit comments