1-
2- //============================================================================
1+ //============================================================================
32// This file replaces the hand-maintained stub that used to implement clr.dll.
43// This is a line-by-line port from IL back to C#.
54// We now use RGiesecke.DllExport on the required static init method so it can be
2524using System ;
2625
2726
28-
2927public class clrModule
30-
31-
3228{
33-
3429#if ( PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35 )
3530 [ RGiesecke . DllExport . DllExport ( "PyInit_clr" , System . Runtime . InteropServices . CallingConvention . StdCall ) ]
3631 public static IntPtr PyInit_clr ( )
3732#else
3833 [ RGiesecke . DllExport . DllExport ( "initclr" , System . Runtime . InteropServices . CallingConvention . StdCall ) ]
3934 public static void initclr ( )
4035#endif
41-
4236 {
4337#if DEBUG_PRINT
4438 System . Console . WriteLine ( "Attempting to load Python.Runtime using standard binding rules... " ) ;
@@ -54,12 +48,12 @@ public static void initclr()
5448 // - A PrivateBinPath under ApplicationBase
5549 // With an unsigned assembly, the GAC is skipped.
5650 var pythonRuntimeName = new System . Reflection . AssemblyName ( "Python.Runtime" )
57- {
51+ {
5852#if USE_PYTHON_RUNTIME_VERSION
59- Version = new System . Version ( "4.0.0.1" ) ,
53+ Version = new System . Version ( "4.0.0.1" ) ,
6054#endif
61- CultureInfo = System. Globalization . CultureInfo . InvariantCulture ,
62- } ;
55+ CultureInfo = System. Globalization . CultureInfo . InvariantCulture ,
56+ } ;
6357#if USE_PYTHON_RUNTIME_PUBLIC_KEY_TOKEN
6458 pythonRuntimeName . SetPublicKeyToken ( pythonRuntimePublicKeyTokenData ) ;
6559#endif
@@ -77,13 +71,13 @@ public static void initclr()
7771 try
7872 {
7973 // 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
8781
8882 var executingAssembly = System . Reflection . Assembly . GetExecutingAssembly ( ) ;
8983 var assemblyDirectory = System . IO . Path . GetDirectoryName ( executingAssembly . Location ) ;
@@ -95,7 +89,8 @@ public static void initclr()
9589#endif
9690 pythonRuntime = System . Reflection . Assembly . LoadFrom ( pythonRuntimeDllPath ) ;
9791 }
98- catch ( System . InvalidOperationException ) {
92+ catch ( System . InvalidOperationException )
93+ {
9994#if DEBUG_PRINT
10095 System . Console . WriteLine ( "Could not load Python.Runtime, so sad." ) ;
10196#endif
@@ -108,7 +103,7 @@ public static void initclr()
108103 }
109104
110105 // 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.
112107 var pythonEngineType = pythonRuntime . GetType ( "Python.Runtime.PythonEngine" ) ;
113108
114109#if ( PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35 )
@@ -117,4 +112,4 @@ public static void initclr()
117112 pythonEngineType . InvokeMember ( "InitExt" , System . Reflection . BindingFlags . InvokeMethod , null , null , null ) ;
118113#endif
119114 }
120- }
115+ }
0 commit comments