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)
1919
2020 public IEnumerator < T > GetEnumerator ( )
2121 {
22- PyObject iterObject ;
22+ PyIter iterObject ;
2323 using ( Py . GIL ( ) )
2424 {
25- var iter = Runtime . PyObject_GetIter ( pyObject . Reference ) ;
26- PythonException . ThrowIfIsNull ( iter ) ;
27- iterObject = iter . MoveToPyObject ( ) ;
25+ iterObject = PyIter . GetIter ( pyObject ) ;
2826 }
2927
30- using ( iterObject )
28+ using var _ = iterObject ;
3129 while ( true )
3230 {
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 ( ) ;
4232
43- yield return item . MoveToPyObject ( ) . As < T > ( ) ;
33+ if ( ! iterObject . MoveNext ( ) )
34+ {
35+ iterObject . Dispose ( ) ;
36+ break ;
4437 }
38+ yield return iterObject . Current . As < T > ( ) ;
4539 }
4640 }
4741 }
Original file line number Diff line number Diff line change @@ -134,12 +134,12 @@ public static IEnumerable<IntPtr> PyGCGetObjects()
134134 {
135135 using var gc = PyModule . Import ( "gc" ) ;
136136 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 ) ;
139139 if ( length < 0 ) throw PythonException . ThrowLastAsClrException ( ) ;
140140 for ( nint i = 0 ; i < length ; i ++ )
141141 {
142- var obj = PyList_GetItem ( objs . Borrow ( ) , i ) ;
142+ BorrowedReference obj = PyList_GetItem ( objs , i ) ;
143143 yield return obj . DangerousGetAddress ( ) ;
144144 }
145145 }
You can’t perform that action at this time.
0 commit comments