File tree Expand file tree Collapse file tree 5 files changed +87
-9
lines changed Expand file tree Collapse file tree 5 files changed +87
-9
lines changed Original file line number Diff line number Diff line change @@ -51,6 +51,7 @@ This document follows the conventions laid out in [Keep a CHANGELOG][].
51
51
- Fixed ` AppDomain ` unload during GC (#397 )(#400 )
52
52
- Fixed ` Py_Main ` & ` PySys_SetArgvEx ` ` no mem error ` on ` UCS4/PY3 ` (#399 )
53
53
- Fixed ` Python.Runtime.dll.config ` on macOS (#120 )
54
+ - Fixed crash on ` PythonEngine.Version ` (#413 )
54
55
55
56
### Removed
56
57
Original file line number Diff line number Diff line change 89
89
<Compile Include =" pyrunstring.cs" />
90
90
<Compile Include =" pythonexception.cs" />
91
91
<Compile Include =" pytuple.cs" />
92
+ <Compile Include =" TestPythonEngineProperties.cs" />
92
93
</ItemGroup >
93
94
<ItemGroup >
94
95
<ProjectReference Include =" ..\runtime\Python.Runtime.csproj" >
Original file line number Diff line number Diff line change
1
+ using System ;
2
+ using NUnit . Framework ;
3
+ using Python . Runtime ;
4
+
5
+ namespace Python . EmbeddingTest
6
+ {
7
+ public class TestPythonEngineProperties
8
+ {
9
+ [ Test ]
10
+ public static void GetBuildinfoDoesntCrash ( )
11
+ {
12
+ using ( Py . GIL ( ) )
13
+ {
14
+ string s = PythonEngine . BuildInfo ;
15
+
16
+ Assert . IsTrue ( s . Length > 5 ) ;
17
+ Assert . IsTrue ( s . Contains ( "," ) ) ;
18
+ }
19
+ }
20
+
21
+ [ Test ]
22
+ public static void GetCompilerDoesntCrash ( )
23
+ {
24
+ using ( Py . GIL ( ) )
25
+ {
26
+ string s = PythonEngine . Compiler ;
27
+
28
+ Assert . IsTrue ( s . Length > 0 ) ;
29
+ Assert . IsTrue ( s . Contains ( "[" ) ) ;
30
+ Assert . IsTrue ( s . Contains ( "]" ) ) ;
31
+ }
32
+ }
33
+
34
+ [ Test ]
35
+ public static void GetCopyrightDoesntCrash ( )
36
+ {
37
+ using ( Py . GIL ( ) )
38
+ {
39
+ string s = PythonEngine . Copyright ;
40
+
41
+ Assert . IsTrue ( s . Length > 0 ) ;
42
+ Assert . IsTrue ( s . Contains ( "Python Software Foundation" ) ) ;
43
+ }
44
+ }
45
+
46
+ [ Test ]
47
+ public static void GetPlatformDoesntCrash ( )
48
+ {
49
+ using ( Py . GIL ( ) )
50
+ {
51
+ string s = PythonEngine . Platform ;
52
+
53
+ Assert . IsTrue ( s . Length > 0 ) ;
54
+ Assert . IsTrue ( s . Contains ( "x" ) || s . Contains ( "win" ) ) ;
55
+ }
56
+ }
57
+
58
+ [ Test ]
59
+ public static void GetVersionDoesntCrash ( )
60
+ {
61
+ using ( Py . GIL ( ) )
62
+ {
63
+ string s = PythonEngine . Version ;
64
+
65
+ Assert . IsTrue ( s . Length > 0 ) ;
66
+ Assert . IsTrue ( s . Contains ( "," ) ) ;
67
+ }
68
+ }
69
+ }
70
+ }
Original file line number Diff line number Diff line change 3
3
using System . IO ;
4
4
using System . Linq ;
5
5
using System . Reflection ;
6
+ using System . Runtime . InteropServices ;
6
7
7
8
namespace Python . Runtime
8
9
{
@@ -96,22 +97,27 @@ public static string PythonPath
96
97
97
98
public static string Version
98
99
{
99
- get { return Runtime . Py_GetVersion ( ) ; }
100
+ get { return Marshal . PtrToStringAnsi ( Runtime . Py_GetVersion ( ) ) ; }
100
101
}
101
102
102
103
public static string BuildInfo
103
104
{
104
- get { return Runtime . Py_GetBuildInfo ( ) ; }
105
+ get { return Marshal . PtrToStringAnsi ( Runtime . Py_GetBuildInfo ( ) ) ; }
105
106
}
106
107
107
108
public static string Platform
108
109
{
109
- get { return Runtime . Py_GetPlatform ( ) ; }
110
+ get { return Marshal . PtrToStringAnsi ( Runtime . Py_GetPlatform ( ) ) ; }
110
111
}
111
112
112
113
public static string Copyright
113
114
{
114
- get { return Runtime . Py_GetCopyright ( ) ; }
115
+ get { return Marshal . PtrToStringAnsi ( Runtime . Py_GetCopyright ( ) ) ; }
116
+ }
117
+
118
+ public static string Compiler
119
+ {
120
+ get { return Marshal . PtrToStringAnsi ( Runtime . Py_GetCompiler ( ) ) ; }
115
121
}
116
122
117
123
public static int RunSimpleString ( string code )
Original file line number Diff line number Diff line change @@ -729,19 +729,19 @@ internal static extern void Py_SetPath(
729
729
#endif
730
730
731
731
[ DllImport ( PythonDll ) ]
732
- internal static extern string Py_GetVersion ( ) ;
732
+ internal static extern IntPtr Py_GetVersion( ) ;
733
733
734
734
[ DllImport ( PythonDll ) ]
735
- internal static extern string Py_GetPlatform ( ) ;
735
+ internal static extern IntPtr Py_GetPlatform( ) ;
736
736
737
737
[ DllImport ( PythonDll ) ]
738
- internal static extern string Py_GetCopyright ( ) ;
738
+ internal static extern IntPtr Py_GetCopyright( ) ;
739
739
740
740
[ DllImport ( PythonDll ) ]
741
- internal static extern string Py_GetCompiler ( ) ;
741
+ internal static extern IntPtr Py_GetCompiler( ) ;
742
742
743
743
[ DllImport ( PythonDll ) ]
744
- internal static extern string Py_GetBuildInfo ( ) ;
744
+ internal static extern IntPtr Py_GetBuildInfo( ) ;
745
745
746
746
[ DllImport ( PythonDll ) ]
747
747
internal static extern int PyRun_SimpleString ( string code ) ;
You can’t perform that action at this time.
0 commit comments