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

Commit3e1fc2e

Browse files
authored
Merge pull request#1175 from amos402/remove-redundant-calls
* Remove unnecessary `CheckExceptionOccurred` calls* Dispose safety* Refactor Converter.ToPrimitive* str to int raises `ValueError`* Test convert error for float types* Convert error for UInt32* * Ignore package index* Install pycparser on Windows ci* BorrowedReference instead of `in NewReference`* Remove useless pip argument
2 parents2d2b297 +8ca0a62 commit3e1fc2e

File tree

13 files changed

+305
-287
lines changed

13 files changed

+305
-287
lines changed

‎src/embed_tests/TestConverter.cs

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,27 @@
11
usingSystem;
22
usingSystem.Collections.Generic;
3+
usingSystem.Linq;
4+
35
usingNUnit.Framework;
6+
47
usingPython.Runtime;
58

9+
usingPyRuntime=Python.Runtime.Runtime;
10+
611
namespacePython.EmbeddingTest
712
{
813
publicclassTestConverter
914
{
15+
staticreadonlyType[]_numTypes=newType[]
16+
{
17+
typeof(short),
18+
typeof(ushort),
19+
typeof(int),
20+
typeof(uint),
21+
typeof(long),
22+
typeof(ulong)
23+
};
24+
1025
[OneTimeSetUp]
1126
publicvoidSetUp()
1227
{
@@ -47,6 +62,60 @@ public void TestConvertDoubleToManaged(
4762
Assert.IsTrue(((double)convertedValue).Equals(testValue));
4863
}
4964

65+
[Test]
66+
publicvoidCovertTypeError()
67+
{
68+
Type[]floatTypes=newType[]
69+
{
70+
typeof(float),
71+
typeof(double)
72+
};
73+
using(vars=newPyString("abc"))
74+
{
75+
foreach(vartypein_numTypes.Union(floatTypes))
76+
{
77+
objectvalue;
78+
try
79+
{
80+
boolres=Converter.ToManaged(s.Handle,type,outvalue,true);
81+
Assert.IsFalse(res);
82+
varbo=Exceptions.ExceptionMatches(Exceptions.TypeError);
83+
Assert.IsTrue(Exceptions.ExceptionMatches(Exceptions.TypeError)
84+
||Exceptions.ExceptionMatches(Exceptions.ValueError));
85+
}
86+
finally
87+
{
88+
Exceptions.Clear();
89+
}
90+
}
91+
}
92+
}
93+
94+
[Test]
95+
publicvoidConvertOverflow()
96+
{
97+
using(varnum=newPyLong(ulong.MaxValue))
98+
{
99+
IntPtrlargeNum=PyRuntime.PyNumber_Add(num.Handle,num.Handle);
100+
try
101+
{
102+
objectvalue;
103+
foreach(vartypein_numTypes)
104+
{
105+
boolres=Converter.ToManaged(largeNum,type,outvalue,true);
106+
Assert.IsFalse(res);
107+
Assert.IsTrue(Exceptions.ExceptionMatches(Exceptions.OverflowError));
108+
Exceptions.Clear();
109+
}
110+
}
111+
finally
112+
{
113+
Exceptions.Clear();
114+
PyRuntime.XDecref(largeNum);
115+
}
116+
}
117+
}
118+
50119
[Test]
51120
publicvoidRawListProxy()
52121
{

‎src/runtime/NewReference.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,18 @@ public PyObject MoveToPyObject()
2727
this.pointer=IntPtr.Zero;
2828
returnresult;
2929
}
30+
3031
/// <summary>
3132
/// Removes this reference to a Python object, and sets it to <c>null</c>.
3233
/// </summary>
3334
publicvoidDispose()
3435
{
35-
if(!this.IsNull())
36-
Runtime.XDecref(this.pointer);
37-
this.pointer=IntPtr.Zero;
36+
if(this.IsNull())
37+
{
38+
return;
39+
}
40+
Runtime.XDecref(pointer);
41+
pointer=IntPtr.Zero;
3842
}
3943

4044
/// <summary>

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp