Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita6f27ab

Browse files
committed
fix memory access error when iteration breaks
in the middle of the list before reaching end.
1 parent8e8c3f3 commita6f27ab

File tree

1 file changed

+41
-37
lines changed

1 file changed

+41
-37
lines changed
Lines changed: 41 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,46 @@
1-
usingSystem;
2-
usingSystem.Collections.Generic;
3-
usingSystem.Collections;
4-
5-
namespacePython.Runtime.CollectionWrappers
6-
{
7-
internalclassIterableWrapper<T>:IEnumerable<T>
8-
{
9-
protectedreadonlyPyObjectpyObject;
10-
11-
publicIterableWrapper(PyObjectpyObj)
12-
{
13-
if(pyObj==null)
14-
thrownewArgumentNullException();
15-
pyObject=newPyObject(pyObj.Reference);
16-
}
17-
18-
IEnumeratorIEnumerable.GetEnumerator()=>GetEnumerator();
19-
20-
publicIEnumerator<T>GetEnumerator()
21-
{
22-
PyIteriterObject;
23-
using(Py.GIL())
24-
{
25-
iterObject=PyIter.GetIter(pyObject);
1+
usingSystem;
2+
usingSystem.Collections.Generic;
3+
usingSystem.Collections;
4+
5+
namespacePython.Runtime.CollectionWrappers
6+
{
7+
internalclassIterableWrapper<T>:IEnumerable<T>
8+
{
9+
protectedreadonlyPyObjectpyObject;
10+
11+
publicIterableWrapper(PyObjectpyObj)
12+
{
13+
if(pyObj==null)
14+
thrownewArgumentNullException();
15+
pyObject=newPyObject(pyObj.Reference);
16+
}
17+
18+
IEnumeratorIEnumerable.GetEnumerator()=>GetEnumerator();
19+
20+
publicIEnumerator<T>GetEnumerator()
21+
{
22+
PyIteriterObject;
23+
using(Py.GIL())
24+
{
25+
iterObject=PyIter.GetIter(pyObject);
2626
}
27-
28-
usingvar_=iterObject;
29-
while(true)
27+
try
3028
{
31-
usingvarGIL=Py.GIL();
32-
33-
if(!iterObject.MoveNext())
29+
while(true)
3430
{
35-
iterObject.Dispose();
36-
break;
31+
usingvar_=Py.GIL();
32+
if(!iterObject.MoveNext())
33+
{
34+
break;
35+
}
36+
yieldreturniterObject.Current.As<T>()!;
3737
}
38-
yieldreturniterObject.Current.As<T>()!;
3938
}
40-
}
41-
}
42-
}
39+
finally
40+
{
41+
usingvar_=Py.GIL();
42+
iterObject.Dispose();
43+
}
44+
}
45+
}
46+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp