Skip to content

Commit 200ba3d

Browse files
committed
Merge branch 'master' into modernize-import-hook
2 parents 18844e7 + 32fdc9c commit 200ba3d

20 files changed

+703
-97
lines changed

AUTHORS.md

+3-2
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

+5
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

+204
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+
new TestCase
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+
new TestCase
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+
new TestCase
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
new TestCase
8471051
{
8481052
Name = "nested_type",

src/domain_tests/test_domain_reload.py

+12
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,18 @@ def test_construct_removed_class():
8383
def test_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+
def test_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+
def test_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+
def test_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
def test_nested_type():
88100
_run_test("nested_type")

src/embed_tests/TestInterrupt.cs

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
2+
using System;
3+
using System.Threading;
4+
using System.Threading.Tasks;
5+
6+
using NUnit.Framework;
7+
8+
using Python.Runtime;
9+
10+
namespace Python.EmbeddingTest
11+
{
12+
public class TestInterrupt
13+
{
14+
private IntPtr _threadState;
15+
16+
[OneTimeSetUp]
17+
public void SetUp()
18+
{
19+
PythonEngine.Initialize();
20+
_threadState = PythonEngine.BeginAllowThreads();
21+
}
22+
23+
[OneTimeTearDown]
24+
public void Dispose()
25+
{
26+
PythonEngine.EndAllowThreads(_threadState);
27+
PythonEngine.Shutdown();
28+
}
29+
30+
[Test]
31+
public void InterruptTest()
32+
{
33+
int runSimpleStringReturnValue = int.MinValue;
34+
ulong pythonThreadID = 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+
int interruptReturnValue = 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)