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

Commit200ba3d

Browse files
committed
Merge branch 'master' into modernize-import-hook
2 parents18844e7 +32fdc9c commit200ba3d

20 files changed

+703
-97
lines changed

‎AUTHORS.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@
6666
- Ville M. Vainio ([@vivainio](https://github.com/vivainio))
6767
- Virgil Dupras ([@hsoft](https://github.com/hsoft))
6868
- Wenguang Yang ([@yagweb](https://github.com/yagweb))
69-
- William Sardar ([@williamsardar])(https://github.com/williamsardar)
69+
- William Sardar ([@williamsardar](https://github.com/williamsardar))
7070
- Xavier Dupré ([@sdpython](https://github.com/sdpython))
7171
- Zane Purvis ([@zanedp](https://github.com/zanedp))
72-
- ([@amos402]https://github.com/amos402)
72+
- ([@amos402](https://github.com/amos402))
7373
- ([@bltribble](https://github.com/bltribble))
7474
- ([@civilx64](https://github.com/civilx64))
7575
- ([@GSPP](https://github.com/GSPP))
@@ -82,3 +82,4 @@
8282
- ([@testrunner123](https://github.com/testrunner123))
8383
- ([@DanBarzilian](https://github.com/DanBarzilian))
8484
- ([@alxnull](https://github.com/alxnull))
85+
- ([@gpetrou](https://github.com/gpetrou))

‎CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ This document follows the conventions laid out in [Keep a CHANGELOG][].
1111

1212
- Ability to instantiate new .NET arrays using`Array[T](dim1, dim2, ...)` syntax
1313
- Python operator method will call C# operator method for supported binary and unary operators ([#1324][p1324]).
14+
- Add GetPythonThreadID and Interrupt methods in PythonEngine
1415

1516
###Changed
1617
- Drop support for Python 2, 3.4, and 3.5
@@ -28,7 +29,10 @@ details about the cause of the failure
2829
to the regular method return value (unless they are passed with`ref` or`out` keyword).
2930
- BREAKING: Drop support for the long-deprecated CLR.* prefix.
3031
-`PyObject` now implements`IEnumerable<PyObject>` in addition to`IEnumerable`
32+
3133
- Replaced the old`__import__` hook hack with a PEP302-style Meta Path Loader
34+
- floating point values passed from Python are no longer silently truncated
35+
when .NET expects an integer[#1342][i1342]
3236

3337
###Fixed
3438

@@ -810,3 +814,4 @@ This version improves performance on benchmarks significantly compared to 2.3.
810814
[i755]:https://github.com/pythonnet/pythonnet/pull/755
811815
[p534]:https://github.com/pythonnet/pythonnet/pull/534
812816
[i449]:https://github.com/pythonnet/pythonnet/issues/449
817+
[i1342]:https://github.com/pythonnet/pythonnet/issues/1342

‎src/domain_tests/TestRunner.cs

Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -843,6 +843,210 @@ raise AssertionError('failed to raise')
843843
assert foo is not bar
844844
",
845845
},
846+
847+
newTestCase
848+
{
849+
Name="ref_to_out_param",
850+
DotNetBefore=@"
851+
namespace TestNamespace
852+
{
853+
854+
[System.Serializable]
855+
public class Data
856+
{
857+
public int num = -1;
858+
}
859+
860+
[System.Serializable]
861+
public class Cls
862+
{
863+
public static void MyFn (ref Data a)
864+
{
865+
a.num = 7;
866+
}
867+
}
868+
}",
869+
DotNetAfter=@"
870+
namespace TestNamespace
871+
{
872+
873+
[System.Serializable]
874+
public class Data
875+
{
876+
public int num = -1;
877+
}
878+
879+
[System.Serializable]
880+
public class Cls
881+
{
882+
public static void MyFn (out Data a)
883+
{
884+
a = new Data();
885+
a.num = 9001;
886+
}
887+
}
888+
}",
889+
PythonCode=@"
890+
import clr
891+
import sys
892+
clr.AddReference('DomainTests')
893+
import TestNamespace
894+
import System
895+
896+
def before_reload():
897+
898+
foo = TestNamespace.Data()
899+
bar = TestNamespace.Cls.MyFn(foo)
900+
# foo should have changed
901+
assert foo.num == 7
902+
assert bar.num == 7
903+
904+
905+
def after_reload():
906+
907+
foo = TestNamespace.Data()
908+
bar = TestNamespace.Cls.MyFn(foo)
909+
assert bar.num == 9001
910+
# foo shouldn't have changed.
911+
assert foo.num == -1
912+
# this should work too
913+
baz = TestNamespace.Cls.MyFn(None)
914+
assert baz.num == 9001
915+
",
916+
},
917+
newTestCase
918+
{
919+
Name="ref_to_in_param",
920+
DotNetBefore=@"
921+
namespace TestNamespace
922+
{
923+
924+
[System.Serializable]
925+
public class Data
926+
{
927+
public int num = -1;
928+
}
929+
930+
[System.Serializable]
931+
public class Cls
932+
{
933+
public static void MyFn (ref Data a)
934+
{
935+
a.num = 7;
936+
System.Console.Write(""Method with ref parameter: "");
937+
System.Console.WriteLine(a.num);
938+
}
939+
}
940+
}",
941+
DotNetAfter=@"
942+
namespace TestNamespace
943+
{
944+
[System.Serializable]
945+
public class Data
946+
{
947+
public int num = -1;
948+
}
949+
950+
[System.Serializable]
951+
public class Cls
952+
{
953+
public static void MyFn (Data a)
954+
{
955+
System.Console.Write(""Method with in parameter: "");
956+
System.Console.WriteLine(a.num);
957+
}
958+
}
959+
}",
960+
PythonCode=@"
961+
import clr
962+
import sys
963+
clr.AddReference('DomainTests')
964+
import TestNamespace
965+
import System
966+
967+
def before_reload():
968+
969+
foo = TestNamespace.Data()
970+
bar = TestNamespace.Cls.MyFn(foo)
971+
# foo should have changed
972+
assert foo.num == 7
973+
assert bar.num == 7
974+
975+
def after_reload():
976+
977+
foo = TestNamespace.Data()
978+
TestNamespace.Cls.MyFn(foo)
979+
# foo should not have changed
980+
assert foo.num == TestNamespace.Data().num
981+
982+
",
983+
},
984+
newTestCase
985+
{
986+
Name="in_to_ref_param",
987+
DotNetBefore=@"
988+
namespace TestNamespace
989+
{
990+
[System.Serializable]
991+
public class Data
992+
{
993+
public int num = -1;
994+
}
995+
996+
[System.Serializable]
997+
public class Cls
998+
{
999+
public static void MyFn (Data a)
1000+
{
1001+
System.Console.Write(""Method with in parameter: "");
1002+
System.Console.WriteLine(a.num);
1003+
}
1004+
}
1005+
}",
1006+
DotNetAfter=@"
1007+
namespace TestNamespace
1008+
{
1009+
1010+
[System.Serializable]
1011+
public class Data
1012+
{
1013+
public int num = -1;
1014+
}
1015+
1016+
[System.Serializable]
1017+
public class Cls
1018+
{
1019+
public static void MyFn (ref Data a)
1020+
{
1021+
a.num = 7;
1022+
System.Console.Write(""Method with ref parameter: "");
1023+
System.Console.WriteLine(a.num);
1024+
}
1025+
}
1026+
}",
1027+
PythonCode=@"
1028+
import clr
1029+
import sys
1030+
clr.AddReference('DomainTests')
1031+
import TestNamespace
1032+
import System
1033+
1034+
def before_reload():
1035+
1036+
foo = TestNamespace.Data()
1037+
TestNamespace.Cls.MyFn(foo)
1038+
# foo should not have changed
1039+
assert foo.num == TestNamespace.Data().num
1040+
1041+
def after_reload():
1042+
1043+
foo = TestNamespace.Data()
1044+
bar = TestNamespace.Cls.MyFn(foo)
1045+
# foo should have changed
1046+
assert foo.num == 7
1047+
assert bar.num == 7
1048+
",
1049+
},
8461050
newTestCase
8471051
{
8481052
Name="nested_type",

‎src/domain_tests/test_domain_reload.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,18 @@ def test_construct_removed_class():
8383
deftest_out_to_ref_param():
8484
_run_test("out_to_ref_param")
8585

86+
@pytest.mark.skipif(platform.system()=='Darwin',reason='FIXME: macos can\'t find the python library')
87+
deftest_ref_to_out_param():
88+
_run_test("ref_to_out_param")
89+
90+
@pytest.mark.skipif(platform.system()=='Darwin',reason='FIXME: macos can\'t find the python library')
91+
deftest_ref_to_in_param():
92+
_run_test("ref_to_in_param")
93+
94+
@pytest.mark.skipif(platform.system()=='Darwin',reason='FIXME: macos can\'t find the python library')
95+
deftest_in_to_ref_param():
96+
_run_test("in_to_ref_param")
97+
8698
@pytest.mark.skipif(platform.system()=='Darwin',reason='FIXME: macos can\'t find the python library')
8799
deftest_nested_type():
88100
_run_test("nested_type")

‎src/embed_tests/TestInterrupt.cs

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
2+
usingSystem;
3+
usingSystem.Threading;
4+
usingSystem.Threading.Tasks;
5+
6+
usingNUnit.Framework;
7+
8+
usingPython.Runtime;
9+
10+
namespacePython.EmbeddingTest
11+
{
12+
publicclassTestInterrupt
13+
{
14+
privateIntPtr_threadState;
15+
16+
[OneTimeSetUp]
17+
publicvoidSetUp()
18+
{
19+
PythonEngine.Initialize();
20+
_threadState=PythonEngine.BeginAllowThreads();
21+
}
22+
23+
[OneTimeTearDown]
24+
publicvoidDispose()
25+
{
26+
PythonEngine.EndAllowThreads(_threadState);
27+
PythonEngine.Shutdown();
28+
}
29+
30+
[Test]
31+
publicvoidInterruptTest()
32+
{
33+
intrunSimpleStringReturnValue=int.MinValue;
34+
ulongpythonThreadID=ulong.MinValue;
35+
Task.Factory.StartNew(()=>
36+
{
37+
using(Py.GIL())
38+
{
39+
pythonThreadID=PythonEngine.GetPythonThreadID();
40+
runSimpleStringReturnValue=PythonEngine.RunSimpleString(@"
41+
import time
42+
43+
while True:
44+
time.sleep(0.2)");
45+
}
46+
});
47+
48+
Thread.Sleep(200);
49+
50+
Assert.AreNotEqual(ulong.MinValue,pythonThreadID);
51+
52+
using(Py.GIL())
53+
{
54+
intinterruptReturnValue=PythonEngine.Interrupt(pythonThreadID);
55+
Assert.AreEqual(1,interruptReturnValue);
56+
}
57+
58+
Thread.Sleep(300);
59+
60+
Assert.AreEqual(-1,runSimpleStringReturnValue);
61+
}
62+
}
63+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp