| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,5 +1,4 @@ | |||
| 1 | 1 | using System.Reflection; | |
| 2 | - using System.Runtime.CompilerServices; | ||
| 3 | 2 | using System.Runtime.InteropServices; | |
| 4 | 3 | ||
| 5 | 4 | // General Information about an assembly is controlled through the following | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,5 +1,5 @@ | |||
| 1 | 1 | //============================================================================ | |
| 2 | - // This file replaces the hand-maintained stub that used to implement clr.dll. | ||
| 2 | + // This file replaces the hand-maintained stub that used to implement clr.dll. | ||
| 3 | 3 | // This is a line-by-line port from IL back to C#. | |
| 4 | 4 | // We now use RGiesecke.DllExport on the required static init method so it can be | |
| 5 | 5 | // loaded by a standard CPython interpreter as an extension module. When it | |
@@ -11,31 +11,34 @@ | |||
| 11 | 11 | ||
| 12 | 12 | // If defined, the "pythonRuntimeVersionString" variable must be set to | |
| 13 | 13 | // Python.Runtime's current version. | |
| 14 | - | ||
| 15 | 14 | #define USE_PYTHON_RUNTIME_VERSION | |
| 16 | 15 | ||
| 17 | 16 | // If defined, the "PythonRuntimePublicKeyTokenData" data array must be | |
| 18 | 17 | // set to Python.Runtime's public key token. (sn -T Python.Runtin.dll) | |
| 19 | 18 | #define USE_PYTHON_RUNTIME_PUBLIC_KEY_TOKEN | |
| 20 | 19 | ||
| 21 | - // If DEBUG_PRINT is defined in the Build Properties, a few System.Console.WriteLine | ||
| 20 | + // If DEBUG_PRINT is defined in the Build Properties, a few Console.WriteLine | ||
| 22 | 21 | // calls are made to indicate what's going on during the load... | |
| 23 | 22 | //============================================================================ | |
| 24 | 23 | using System; | |
| 25 | - | ||
| 24 | + using System.Globalization; | ||
| 25 | + using System.IO; | ||
| 26 | + using System.Reflection; | ||
| 27 | + using System.Runtime.InteropServices; | ||
| 28 | + using RGiesecke.DllExport; | ||
| 26 | 29 | ||
| 27 | 30 | public class clrModule | |
| 28 | 31 | { | |
| 29 | 32 | #if (PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35 || PYTHON36) | |
| 30 | - [RGiesecke.DllExport.DllExport("PyInit_clr", System.Runtime.InteropServices.CallingConvention.StdCall)] | ||
| 33 | + [DllExport("PyInit_clr", CallingConvention.StdCall)] | ||
| 31 | 34 | public static IntPtr PyInit_clr() | |
| 32 | 35 | #else | |
| 33 | - [RGiesecke.DllExport.DllExport("initclr", System.Runtime.InteropServices.CallingConvention.StdCall)] | ||
| 36 | + [DllExport("initclr", CallingConvention.StdCall)] | ||
| 34 | 37 | public static void initclr() | |
| 35 | 38 | #endif | |
| 36 | 39 | { | |
| 37 | 40 | #if DEBUG_PRINT | |
| 38 | - System.Console.WriteLine("Attempting to load Python.Runtime using standard binding rules... "); | ||
| 41 | + Console.WriteLine("Attempting to load Python.Runtime using standard binding rules... "); | ||
| 39 | 42 | #endif | |
| 40 | 43 | #if USE_PYTHON_RUNTIME_PUBLIC_KEY_TOKEN | |
| 41 | 44 | var pythonRuntimePublicKeyTokenData = new byte[] { 0x50, 0x00, 0xfe, 0xa6, 0xcb, 0xa7, 0x02, 0xdd }; | |
@@ -47,26 +50,26 @@ public static void initclr() | |||
| 47 | 50 | // - ApplicationBase | |
| 48 | 51 | // - A PrivateBinPath under ApplicationBase | |
| 49 | 52 | // With an unsigned assembly, the GAC is skipped. | |
| 50 | - var pythonRuntimeName = new System.Reflection.AssemblyName("Python.Runtime") | ||
| 53 | + var pythonRuntimeName = new AssemblyName("Python.Runtime") | ||
| 51 | 54 | { | |
| 52 | 55 | #if USE_PYTHON_RUNTIME_VERSION | |
| 53 | - Version = new System.Version("4.0.0.1"), | ||
| 56 | + Version = new Version("4.0.0.1"), | ||
| 54 | 57 | #endif | |
| 55 | - CultureInfo = System.Globalization.CultureInfo.InvariantCulture, | ||
| 58 | + CultureInfo = CultureInfo.InvariantCulture | ||
| 56 | 59 | }; | |
| 57 | 60 | #if USE_PYTHON_RUNTIME_PUBLIC_KEY_TOKEN | |
| 58 | 61 | pythonRuntimeName.SetPublicKeyToken(pythonRuntimePublicKeyTokenData); | |
| 59 | 62 | #endif | |
| 60 | 63 | // We've got the AssemblyName with optional features; try to load it. | |
| 61 | - System.Reflection.Assembly pythonRuntime; | ||
| 64 | + Assembly pythonRuntime; | ||
| 62 | 65 | try | |
| 63 | 66 | { | |
| 64 | - pythonRuntime = System.Reflection.Assembly.Load(pythonRuntimeName); | ||
| 67 | + pythonRuntime = Assembly.Load(pythonRuntimeName); | ||
| 65 | 68 | #if DEBUG_PRINT | |
| 66 | - System.Console.WriteLine("Success!"); | ||
| 69 | + Console.WriteLine("Success!"); | ||
| 67 | 70 | #endif | |
| 68 | 71 | } | |
| 69 | - catch (System.IO.IOException) | ||
| 72 | + catch (IOException) | ||
| 70 | 73 | { | |
| 71 | 74 | try | |
| 72 | 75 | { | |
@@ -79,20 +82,22 @@ public static void initclr() | |||
| 79 | 82 | // http://blogs.msdn.com/suzcook/archive/2003/05/29/57143.aspx | |
| 80 | 83 | // http://blogs.msdn.com/suzcook/archive/2003/06/13/57180.aspx | |
| 81 | 84 | ||
| 82 | - var executingAssembly = System.Reflection.Assembly.GetExecutingAssembly(); | ||
| 83 | - var assemblyDirectory = System.IO.Path.GetDirectoryName(executingAssembly.Location); | ||
| 85 | + Assembly executingAssembly = Assembly.GetExecutingAssembly(); | ||
| 86 | + string assemblyDirectory = Path.GetDirectoryName(executingAssembly.Location); | ||
| 84 | 87 | if (assemblyDirectory == null) | |
| 85 | - throw new System.InvalidOperationException(executingAssembly.Location); | ||
| 86 | - var pythonRuntimeDllPath = System.IO.Path.Combine(assemblyDirectory, "Python.Runtime.dll"); | ||
| 88 | + { | ||
| 89 | + throw new InvalidOperationException(executingAssembly.Location); | ||
| 90 | + } | ||
| 91 | + string pythonRuntimeDllPath = Path.Combine(assemblyDirectory, "Python.Runtime.dll"); | ||
| 87 | 92 | #if DEBUG_PRINT | |
| 88 | - System.Console.WriteLine("Attempting to load Python.Runtime from: '{0}'...", pythonRuntimeDllPath); | ||
| 93 | + Console.WriteLine("Attempting to load Python.Runtime from: '{0}'...", pythonRuntimeDllPath); | ||
| 89 | 94 | #endif | |
| 90 | - pythonRuntime = System.Reflection.Assembly.LoadFrom(pythonRuntimeDllPath); | ||
| 95 | + pythonRuntime = Assembly.LoadFrom(pythonRuntimeDllPath); | ||
| 91 | 96 | } | |
| 92 | - catch (System.InvalidOperationException) | ||
| 97 | + catch (InvalidOperationException) | ||
| 93 | 98 | { | |
| 94 | 99 | #if DEBUG_PRINT | |
| 95 | - System.Console.WriteLine("Could not load Python.Runtime, so sad."); | ||
| 100 | + Console.WriteLine("Could not load Python.Runtime"); | ||
| 96 | 101 | #endif | |
| 97 | 102 | #if (PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35 || PYTHON36) | |
| 98 | 103 | return IntPtr.Zero; | |
@@ -104,12 +109,12 @@ public static void initclr() | |||
| 104 | 109 | ||
| 105 | 110 | // Once here, we've successfully loaded SOME version of Python.Runtime | |
| 106 | 111 | // So now we get the PythonEngine and execute the InitExt method on it. | |
| 107 | - var pythonEngineType = pythonRuntime.GetType("Python.Runtime.PythonEngine"); | ||
| 112 | + Type pythonEngineType = pythonRuntime.GetType("Python.Runtime.PythonEngine"); | ||
| 108 | 113 | ||
| 109 | 114 | #if (PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35 || PYTHON36) | |
| 110 | - return (IntPtr)pythonEngineType.InvokeMember("InitExt", System.Reflection.BindingFlags.InvokeMethod, null, null, null); | ||
| 115 | + return (IntPtr)pythonEngineType.InvokeMember("InitExt", BindingFlags.InvokeMethod, null, null, null); | ||
| 111 | 116 | #else | |
| 112 | - pythonEngineType.InvokeMember("InitExt", System.Reflection.BindingFlags.InvokeMethod, null, null, null); | ||
| 117 | + pythonEngineType.InvokeMember("InitExt", BindingFlags.InvokeMethod, null, null, null); | ||
| 113 | 118 | #endif | |
| 114 | 119 | } | |
| 115 | 120 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -196,7 +196,7 @@ | |||
| 196 | 196 | <ItemGroup> | |
| 197 | 197 | <Content Include="python-clear.ico" /> | |
| 198 | 198 | <EmbeddedResource Include="$(PythonBuildDir)\Python.Runtime.dll"> | |
| 199 | - <LogicalName>Python.Runtime.dll</LogicalName> | ||
| 199 | + <LogicalName>Python.Runtime.dll</LogicalName> | ||
| 200 | 200 | </EmbeddedResource> | |
| 201 | 201 | </ItemGroup> | |
| 202 | 202 | <ItemGroup> | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,18 +1,18 @@ | |||
| 1 | 1 | using System; | |
| 2 | 2 | using System.Reflection; | |
| 3 | - using System.Security.Permissions; | ||
| 4 | - using System.Runtime.InteropServices; | ||
| 5 | 3 | using System.Resources; | |
| 4 | + using System.Runtime.InteropServices; | ||
| 5 | + using System.Security.Permissions; | ||
| 6 | 6 | ||
| 7 | - [assembly: System.Reflection.AssemblyProduct("Python for .NET")] | ||
| 8 | - [assembly: System.Reflection.AssemblyVersion("2.4.2.7")] | ||
| 9 | - [assembly: AssemblyTitleAttribute("Python Console")] | ||
| 10 | - [assembly: AssemblyDefaultAliasAttribute("python.exe")] | ||
| 7 | + [assembly: AssemblyProduct("Python for .NET")] | ||
| 8 | + [assembly: AssemblyVersion("2.4.2.7")] | ||
| 9 | + [assembly: AssemblyTitle("Python Console")] | ||
| 10 | + [assembly: AssemblyDefaultAlias("python.exe")] | ||
| 11 | 11 | [assembly: CLSCompliant(true)] | |
| 12 | 12 | [assembly: ComVisible(false)] | |
| 13 | - [assembly: PermissionSetAttribute(SecurityAction.RequestMinimum, | ||
| 13 | + [assembly: PermissionSet(SecurityAction.RequestMinimum, | ||
| 14 | 14 | Name = "FullTrust")] | |
| 15 | - [assembly: AssemblyDescriptionAttribute("")] | ||
| 16 | - [assembly: AssemblyCopyrightAttribute("MIT License")] | ||
| 17 | - [assembly: AssemblyFileVersionAttribute("2.0.0.4")] | ||
| 18 | - [assembly: NeutralResourcesLanguageAttribute("en")] | ||
| 15 | + [assembly: AssemblyDescription("")] | ||
| 16 | + [assembly: AssemblyCopyright("MIT License")] | ||
| 17 | + [assembly: AssemblyFileVersion("2.0.0.4")] | ||
| 18 | + [assembly: NeutralResourcesLanguage("en")] | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,12 +1,14 @@ | |||
| 1 | 1 | using System; | |
| 2 | - using System.Reflection; | ||
| 3 | 2 | using System.Collections.Generic; | |
| 3 | + using System.Reflection; | ||
| 4 | 4 | using Python.Runtime; | |
| 5 | 5 | ||
| 6 | 6 | namespace Python.Runtime | |
| 7 | 7 | { | |
| 8 | 8 | public sealed class PythonConsole | |
| 9 | 9 | { | |
| 10 | + private static AssemblyLoader assemblyLoader = new AssemblyLoader(); | ||
| 11 | + | ||
| 10 | 12 | private PythonConsole() | |
| 11 | 13 | { | |
| 12 | 14 | } | |
@@ -26,7 +28,7 @@ public static int Main(string[] args) | |||
| 26 | 28 | return i; | |
| 27 | 29 | } | |
| 28 | 30 | ||
| 29 | - // Register a callback function to load embedded assmeblies. | ||
| 31 | + // Register a callback function to load embedded assemblies. | ||
| 30 | 32 | // (Python.Runtime.dll is included as a resource) | |
| 31 | 33 | private sealed class AssemblyLoader | |
| 32 | 34 | { | |
@@ -39,7 +41,7 @@ public AssemblyLoader() | |||
| 39 | 41 | AppDomain.CurrentDomain.AssemblyResolve += (sender, args) => | |
| 40 | 42 | { | |
| 41 | 43 | string shortName = args.Name.Split(',')[0]; | |
| 42 | - String resourceName = shortName + ".dll"; | ||
| 44 | + string resourceName = string.Format("{0}.dll", shortName); | ||
| 43 | 45 | ||
| 44 | 46 | if (loadedAssemblies.ContainsKey(resourceName)) | |
| 45 | 47 | { | |
@@ -51,7 +53,7 @@ public AssemblyLoader() | |||
| 51 | 53 | { | |
| 52 | 54 | if (stream != null) | |
| 53 | 55 | { | |
| 54 | - Byte[] assemblyData = new Byte[stream.Length]; | ||
| 56 | + var assemblyData = new byte[stream.Length]; | ||
| 55 | 57 | stream.Read(assemblyData, 0, assemblyData.Length); | |
| 56 | 58 | Assembly assembly = Assembly.Load(assemblyData); | |
| 57 | 59 | loadedAssemblies[resourceName] = assembly; | |
@@ -62,8 +64,6 @@ public AssemblyLoader() | |||
| 62 | 64 | return null; | |
| 63 | 65 | }; | |
| 64 | 66 | } | |
| 65 | - }; | ||
| 66 | - | ||
| 67 | - private static AssemblyLoader assemblyLoader = new AssemblyLoader(); | ||
| 68 | - }; | ||
| 69 | - } | ||
| 67 | + } | ||
| 68 | + } | ||
| 69 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments