1
-
2
- //============================================================================
1
+ //============================================================================
3
2
// This file replaces the hand-maintained stub that used to implement clr.dll.
4
3
// This is a line-by-line port from IL back to C#.
5
4
// We now use RGiesecke.DllExport on the required static init method so it can be
25
24
using System ;
26
25
27
26
28
-
29
27
public class clrModule
30
-
31
-
32
28
{
33
-
34
29
#if ( PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35 )
35
30
[ RGiesecke . DllExport . DllExport ( "PyInit_clr" , System . Runtime . InteropServices . CallingConvention . StdCall ) ]
36
31
public static IntPtr PyInit_clr ( )
37
32
#else
38
33
[ RGiesecke . DllExport . DllExport ( "initclr" , System . Runtime . InteropServices . CallingConvention . StdCall ) ]
39
34
public static void initclr ( )
40
35
#endif
41
-
42
36
{
43
37
#if DEBUG_PRINT
44
38
System . Console . WriteLine ( "Attempting to load Python.Runtime using standard binding rules... " ) ;
@@ -54,12 +48,12 @@ public static void initclr()
54
48
// - A PrivateBinPath under ApplicationBase
55
49
// With an unsigned assembly, the GAC is skipped.
56
50
var pythonRuntimeName = new System . Reflection . AssemblyName ( "Python.Runtime" )
57
- {
51
+ {
58
52
#if USE_PYTHON_RUNTIME_VERSION
59
- Version = new System . Version ( "4.0.0.1" ) ,
53
+ Version = new System . Version ( "4.0.0.1" ) ,
60
54
#endif
61
- CultureInfo = System. Globalization . CultureInfo . InvariantCulture ,
62
- } ;
55
+ CultureInfo = System. Globalization . CultureInfo . InvariantCulture ,
56
+ } ;
63
57
#if USE_PYTHON_RUNTIME_PUBLIC_KEY_TOKEN
64
58
pythonRuntimeName . SetPublicKeyToken ( pythonRuntimePublicKeyTokenData ) ;
65
59
#endif
@@ -77,13 +71,13 @@ public static void initclr()
77
71
try
78
72
{
79
73
// If the above fails for any reason, we fallback to attempting to load "Python.Runtime.dll"
80
- // from the directory this assembly is running in. "This assembly" is probably "clr.pyd",
81
- // sitting somewhere in PYTHONPATH. This is using Assembly.LoadFrom, and inherits all the
82
- // caveats of that call. See MSDN docs for details.
83
- // Suzanne Cook's blog is also an excellent source of info on this:
84
- // http://blogs.msdn.com/suzcook/
85
- // http://blogs.msdn.com/suzcook/archive/2003/05/29/57143.aspx
86
- // http://blogs.msdn.com/suzcook/archive/2003/06/13/57180.aspx
74
+ // from the directory this assembly is running in. "This assembly" is probably "clr.pyd",
75
+ // sitting somewhere in PYTHONPATH. This is using Assembly.LoadFrom, and inherits all the
76
+ // caveats of that call. See MSDN docs for details.
77
+ // Suzanne Cook's blog is also an excellent source of info on this:
78
+ // http://blogs.msdn.com/suzcook/
79
+ // http://blogs.msdn.com/suzcook/archive/2003/05/29/57143.aspx
80
+ // http://blogs.msdn.com/suzcook/archive/2003/06/13/57180.aspx
87
81
88
82
var executingAssembly = System . Reflection . Assembly . GetExecutingAssembly ( ) ;
89
83
var assemblyDirectory = System . IO . Path . GetDirectoryName ( executingAssembly . Location ) ;
@@ -95,7 +89,8 @@ public static void initclr()
95
89
#endif
96
90
pythonRuntime = System . Reflection . Assembly . LoadFrom ( pythonRuntimeDllPath ) ;
97
91
}
98
- catch ( System . InvalidOperationException ) {
92
+ catch ( System . InvalidOperationException )
93
+ {
99
94
#if DEBUG_PRINT
100
95
System . Console . WriteLine ( "Could not load Python.Runtime, so sad." ) ;
101
96
#endif
@@ -108,7 +103,7 @@ public static void initclr()
108
103
}
109
104
110
105
// Once here, we've successfully loaded SOME version of Python.Runtime
111
- // So now we get the PythonEngine and execute the InitExt method on it.
106
+ // So now we get the PythonEngine and execute the InitExt method on it.
112
107
var pythonEngineType = pythonRuntime . GetType ( "Python.Runtime.PythonEngine" ) ;
113
108
114
109
#if ( PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35 )
@@ -117,4 +112,4 @@ public static void initclr()
117
112
pythonEngineType . InvokeMember ( "InitExt" , System . Reflection . BindingFlags . InvokeMethod , null , null , null ) ;
118
113
#endif
119
114
}
120
- }
115
+ }
0 commit comments