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

Commit61bd107

Browse files
committed
cleanup
1 parent6987cc6 commit61bd107

File tree

3 files changed

+7
-68
lines changed

3 files changed

+7
-68
lines changed

‎src/runtime/CollectionWrappers/IterableWrapper.cs

Lines changed: 2 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -11,55 +11,11 @@ internal class IterableWrapper<T> : IEnumerable<T>
1111
publicIterableWrapper(PyObjectpyObj)
1212
{
1313
if(pyObj==null)
14-
thrownewPythonException();
14+
thrownewArgumentNullException();
1515
pyObject=pyObj;
1616
}
1717

18-
privatevoidpropagateIterationException()
19-
{
20-
varerr=Runtime.PyErr_Occurred();
21-
if(err==null)return;
22-
23-
//remove StopIteration exceptions
24-
if(0!=Runtime.PyErr_ExceptionMatches(Exceptions.StopIteration))
25-
{
26-
Runtime.PyErr_Clear();
27-
return;
28-
}
29-
30-
Runtime.CheckExceptionOccurred();
31-
}
32-
33-
IEnumeratorIEnumerable.GetEnumerator()
34-
{
35-
PyObjectiterObject=null;
36-
using(Py.GIL())
37-
{
38-
iterObject=newPyObject(Runtime.PyObject_GetIter(pyObject.Handle));
39-
}
40-
41-
while(true)
42-
{
43-
IntPtritem=IntPtr.Zero;
44-
using(Py.GIL())
45-
{
46-
item=Runtime.PyIter_Next(iterObject.Handle);
47-
}
48-
if(item==IntPtr.Zero)break;
49-
50-
objectobj=null;
51-
if(!Converter.ToManaged(item,typeof(object),outobj,true))
52-
{
53-
Runtime.XDecref(item);
54-
Runtime.CheckExceptionOccurred();
55-
}
56-
57-
Runtime.XDecref(item);
58-
yieldreturnobj;
59-
}
60-
61-
propagateIterationException();
62-
}
18+
IEnumeratorIEnumerable.GetEnumerator()=>GetEnumerator();
6319

6420
publicIEnumerator<T>GetEnumerator()
6521
{
@@ -88,8 +44,6 @@ public IEnumerator<T> GetEnumerator()
8844
Runtime.XDecref(item);
8945
yieldreturn(T)obj;
9046
}
91-
92-
propagateIterationException();
9347
}
9448
}
9549
}

‎src/runtime/CollectionWrappers/ListWrapper.cs

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,12 @@ public T this[int index]
1616
{
1717
varitem=Runtime.PyList_GetItem(pyObject.Reference,index);
1818
varpyItem=newPyObject(item);
19-
20-
if(!Converter.ToManaged(pyItem.Handle,typeof(T),outobjectobj,true))
21-
Runtime.CheckExceptionOccurred();
22-
23-
return(T)obj;
19+
returnpyItem.As<T>();
2420
}
2521
set
2622
{
27-
IntPtrpyItem=Converter.ToPython(value,typeof(T));
28-
if(pyItem==IntPtr.Zero)
29-
{
30-
thrownewInvalidCastException(
31-
"cannot cast "+value.ToString()+"to type: "+typeof(T).ToString(),
32-
newPythonException());
33-
}
34-
35-
varresult=Runtime.PyList_SetItem(pyObject.Handle,index,pyItem);
23+
varpyItem=value.ToPython();
24+
varresult=Runtime.PyList_SetItem(pyObject.Handle,index,pyItem.Handle);
3625
if(result==-1)
3726
Runtime.CheckExceptionOccurred();
3827
}
@@ -48,12 +37,9 @@ public void Insert(int index, T item)
4837
if(IsReadOnly)
4938
thrownewInvalidOperationException("Collection is read-only");
5039

51-
IntPtrpyItem=Converter.ToPython(item,typeof(T));
52-
if(pyItem==IntPtr.Zero)
53-
thrownewPythonException();
40+
varpyItem=item.ToPython();
5441

55-
varresult=Runtime.PyList_Insert(pyObject.Reference,index,pyItem);
56-
Runtime.XDecref(pyItem);
42+
varresult=Runtime.PyList_Insert(pyObject.Reference,index,pyItem.Handle);
5743
if(result==-1)
5844
Runtime.CheckExceptionOccurred();
5945
}

‎src/runtime/CollectionWrappers/SequenceWrapper.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ public int Count
1818
if(size==-1)
1919
{
2020
Runtime.CheckExceptionOccurred();
21-
thrownewException("Unable to get sequence size!");
2221
}
2322

2423
return(int)size;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp