| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 9934cc8 commit c23958e
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -18,25 +18,6 @@ public void SetUp() | |||
| 18 | 18 | } | |
| 19 | 19 | } | |
| 20 | 20 | ||
| 21 | - /// <summary> | ||
| 22 | - /// Test the cache of the information from the platform module. | ||
| 23 | - /// | ||
| 24 | - /// Test fails on platforms we haven't implemented yet. | ||
| 25 | - /// </summary> | ||
| 26 | - [Test] | ||
| 27 | - public static void PlatformCache() | ||
| 28 | - { | ||
| 29 | - Runtime.Runtime.Initialize(); | ||
| 30 | - | ||
| 31 | - Assert.That(NativeCodePageHelper.Machine, Is.Not.EqualTo(MachineType.Other)); | ||
| 32 | - Assert.That(!string.IsNullOrEmpty(NativeCodePageHelper.MachineName)); | ||
| 33 | - | ||
| 34 | - Assert.That(NativeCodePageHelper.OperatingSystem, Is.Not.EqualTo(OperatingSystemType.Other)); | ||
| 35 | - Assert.That(!string.IsNullOrEmpty(NativeCodePageHelper.OperatingSystemName)); | ||
| 36 | - | ||
| 37 | - Runtime.Runtime.Shutdown(); | ||
| 38 | - } | ||
| 39 | - | ||
| 40 | 21 | [Test] | |
| 41 | 22 | public static void Py_IsInitializedValue() | |
| 42 | 23 | { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -15,18 +15,27 @@ interface ILibraryLoader | |||
| 15 | 15 | ||
| 16 | 16 | static class LibraryLoader | |
| 17 | 17 | { | |
| 18 | - public static ILibraryLoader Get(OperatingSystemType os) | ||
| 18 | + static ILibraryLoader _instance = null; | ||
| 19 | + | ||
| 20 | + public static ILibraryLoader Instance | ||
| 19 | 21 | { | |
| 20 | - switch (os) | ||
| 22 | + get | ||
| 21 | 23 | { | |
| 22 | - case OperatingSystemType.Windows: | ||
| 23 | - return new WindowsLoader(); | ||
| 24 | - case OperatingSystemType.Darwin: | ||
| 25 | - return new DarwinLoader(); | ||
| 26 | - case OperatingSystemType.Linux: | ||
| 27 | - return new LinuxLoader(); | ||
| 28 | - default: | ||
| 29 | - throw new PlatformNotSupportedException($"This operating system ({os}) is not supported"); | ||
| 24 | + if (_instance == null) | ||
| 25 | + { | ||
| 26 | + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) | ||
| 27 | + _instance = new WindowsLoader(); | ||
| 28 | + else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) | ||
| 29 | + _instance = new LinuxLoader(); | ||
| 30 | + else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) | ||
| 31 | + _instance = new DarwinLoader(); | ||
| 32 | + else | ||
| 33 | + throw new PlatformNotSupportedException( | ||
| 34 | + "This operating system is not supported" | ||
| 35 | + ); | ||
| 36 | + } | ||
| 37 | + | ||
| 38 | + return _instance; | ||
| 30 | 39 | } | |
| 31 | 40 | } | |
| 32 | 41 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,28 +6,6 @@ namespace Python.Runtime.Platform | |||
| 6 | 6 | { | |
| 7 | 7 | class NativeCodePageHelper | |
| 8 | 8 | { | |
| 9 | - /// <summary> | ||
| 10 | - /// Gets the operating system as reported by python's platform.system(). | ||
| 11 | - /// </summary> | ||
| 12 | - public static OperatingSystemType OperatingSystem { get; private set; } | ||
| 13 | - | ||
| 14 | - /// <summary> | ||
| 15 | - /// Gets the operating system as reported by python's platform.system(). | ||
| 16 | - /// </summary> | ||
| 17 | - [Obsolete] | ||
| 18 | - public static string OperatingSystemName => PythonEngine.Platform; | ||
| 19 | - | ||
| 20 | - /// <summary> | ||
| 21 | - /// Gets the machine architecture as reported by python's platform.machine(). | ||
| 22 | - /// </summary> | ||
| 23 | - public static MachineType Machine { get; private set; }/* set in Initialize using python's platform.machine */ | ||
| 24 | - | ||
| 25 | - /// <summary> | ||
| 26 | - /// Gets the machine architecture as reported by python's platform.machine(). | ||
| 27 | - /// </summary> | ||
| 28 | - [Obsolete] | ||
| 29 | - public static string MachineName { get; private set; } | ||
| 30 | - | ||
| 31 | 9 | /// <summary> | |
| 32 | 10 | /// Initialized by InitializeNativeCodePage. | |
| 33 | 11 | /// | |
@@ -45,33 +23,6 @@ class NativeCodePageHelper | |||
| 45 | 23 | internal static IntPtr NativeCodePage = IntPtr.Zero; | |
| 46 | 24 | ||
| 47 | 25 | ||
| 48 | - static readonly Dictionary<string, OperatingSystemType> OperatingSystemTypeMapping = new Dictionary<string, OperatingSystemType>() | ||
| 49 | - { | ||
| 50 | - { "Windows", OperatingSystemType.Windows }, | ||
| 51 | - { "Darwin", OperatingSystemType.Darwin }, | ||
| 52 | - { "Linux", OperatingSystemType.Linux }, | ||
| 53 | - }; | ||
| 54 | - | ||
| 55 | - /// <summary> | ||
| 56 | - /// Map lower-case version of the python machine name to the processor | ||
| 57 | - /// type. There are aliases, e.g. x86_64 and amd64 are two names for | ||
| 58 | - /// the same thing. Make sure to lower-case the search string, because | ||
| 59 | - /// capitalization can differ. | ||
| 60 | - /// </summary> | ||
| 61 | - static readonly Dictionary<string, MachineType> MachineTypeMapping = new Dictionary<string, MachineType>() | ||
| 62 | - { | ||
| 63 | - ["i386"] = MachineType.i386, | ||
| 64 | - ["i686"] = MachineType.i386, | ||
| 65 | - ["x86"] = MachineType.i386, | ||
| 66 | - ["x86_64"] = MachineType.x86_64, | ||
| 67 | - ["amd64"] = MachineType.x86_64, | ||
| 68 | - ["x64"] = MachineType.x86_64, | ||
| 69 | - ["em64t"] = MachineType.x86_64, | ||
| 70 | - ["armv7l"] = MachineType.armv7l, | ||
| 71 | - ["armv8"] = MachineType.armv8, | ||
| 72 | - ["aarch64"] = MachineType.aarch64, | ||
| 73 | - }; | ||
| 74 | - | ||
| 75 | 26 | /// <summary> | |
| 76 | 27 | /// Structure to describe native code. | |
| 77 | 28 | /// | |
@@ -108,11 +59,11 @@ public static NativeCode Active | |||
| 108 | 59 | { | |
| 109 | 60 | get | |
| 110 | 61 | { | |
| 111 | - switch (Machine) | ||
| 62 | + switch (RuntimeInformation.ProcessArchitecture) | ||
| 112 | 63 | { | |
| 113 | - case MachineType.i386: | ||
| 64 | + case Architecture.X86: | ||
| 114 | 65 | return I386; | |
| 115 | - case MachineType.x86_64: | ||
| 66 | + case Architecture.X64: | ||
| 116 | 67 | return X86_64; | |
| 117 | 68 | default: | |
| 118 | 69 | return null; | |
@@ -205,14 +156,14 @@ int MAP_ANONYMOUS | |||
| 205 | 156 | { | |
| 206 | 157 | get | |
| 207 | 158 | { | |
| 208 | - switch (OperatingSystem) | ||
| 159 | + if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) | ||
| 209 | 160 | { | |
| 210 | - case OperatingSystemType.Darwin: | ||
| 211 | - return 0x1000; | ||
| 212 | - case OperatingSystemType.Linux: | ||
| 213 | - return 0x20; | ||
| 214 | - default: | ||
| 215 | - throw new NotImplementedException($"mmap is not supported on {OperatingSystemName}"); | ||
| 161 | + return 0x20; | ||
| 162 | + } | ||
| 163 | + else | ||
| 164 | + { | ||
| 165 | + // OSX, FreeBSD | ||
| 166 | + return 0x1000; | ||
| 216 | 167 | } | |
| 217 | 168 | } | |
| 218 | 169 | } | |
@@ -236,32 +187,16 @@ public void SetReadExec(IntPtr mappedMemory, int numBytes) | |||
| 236 | 187 | } | |
| 237 | 188 | } | |
| 238 | 189 | ||
| 239 | - /// <summary> | ||
| 240 | - /// Initializes the data about platforms. | ||
| 241 | - /// | ||
| 242 | - /// This must be the last step when initializing the runtime: | ||
| 243 | - /// GetManagedString needs to have the cached values for types. | ||
| 244 | - /// But it must run before initializing anything outside the runtime | ||
| 245 | - /// because those rely on the platform data. | ||
| 246 | - /// </summary> | ||
| 247 | - public static void InitializePlatformData() | ||
| 248 | - { | ||
| 249 | - MachineName = SystemInfo.GetArchitecture(); | ||
| 250 | - Machine = SystemInfo.GetMachineType(); | ||
| 251 | - OperatingSystem = SystemInfo.GetSystemType(); | ||
| 252 | - } | ||
| 253 | - | ||
| 254 | 190 | internal static IMemoryMapper CreateMemoryMapper() | |
| 255 | 191 | { | |
| 256 | - switch (OperatingSystem) | ||
| 192 | + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) | ||
| 193 | + { | ||
| 194 | + return new WindowsMemoryMapper(); | ||
| 195 | + } | ||
| 196 | + else | ||
| 257 | 197 | { | |
| 258 | - case OperatingSystemType.Darwin: | ||
| 259 | - case OperatingSystemType.Linux: | ||
| 260 | - return new UnixMemoryMapper(); | ||
| 261 | - case OperatingSystemType.Windows: | ||
| 262 | - return new WindowsMemoryMapper(); | ||
| 263 | - default: | ||
| 264 | - throw new NotImplementedException($"No support for {OperatingSystemName}"); | ||
| 198 | + // Linux, OSX, FreeBSD | ||
| 199 | + return new UnixMemoryMapper(); | ||
| 265 | 200 | } | |
| 266 | 201 | } | |
| 267 | 202 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -158,11 +158,6 @@ internal static void Initialize(bool initSigs = false, ShutdownMode mode = Shutd | |||
| 158 | 158 | ClassDerivedObject.Reset(); | |
| 159 | 159 | TypeManager.Initialize(); | |
| 160 | 160 | ||
| 161 | - // Initialize data about the platform we're running on. We need | ||
| 162 | - // this for the type manager and potentially other details. Must | ||
| 163 | - // happen after caching the python types, above. | ||
| 164 | - NativeCodePageHelper.InitializePlatformData(); | ||
| 165 | - | ||
| 166 | 161 | // Initialize modules that depend on the runtime class. | |
| 167 | 162 | AssemblyManager.Initialize(); | |
| 168 | 163 | if (mode == ShutdownMode.Reload && RuntimeData.HasStashData()) | |
@@ -2153,7 +2148,7 @@ internal static void Py_CLEAR(ref IntPtr ob) | |||
| 2153 | 2148 | ||
| 2154 | 2149 | internal static void SetNoSiteFlag() | |
| 2155 | 2150 | { | |
| 2156 | - var loader = LibraryLoader.Get(NativeCodePageHelper.OperatingSystem); | ||
| 2151 | + var loader = LibraryLoader.Instance; | ||
| 2157 | 2152 | IntPtr dllLocal = IntPtr.Zero; | |
| 2158 | 2153 | if (_PythonDll != "__Internal") | |
| 2159 | 2154 | { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments