Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6b2e75a

Browse files
committed
Replace custom platform handling by RuntimeInformation
1 parentce76f2e commit6b2e75a

File tree

4 files changed

+37
-117
lines changed

4 files changed

+37
-117
lines changed

‎src/embed_tests/TestRuntime.cs

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,6 @@ public void SetUp()
1818
}
1919
}
2020

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-
publicstaticvoidPlatformCache()
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-
4021
[Test]
4122
publicstaticvoidPy_IsInitializedValue()
4223
{

‎src/runtime/platform/LibraryLoader.cs

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,27 @@ interface ILibraryLoader
1515

1616
staticclassLibraryLoader
1717
{
18-
publicstaticILibraryLoaderGet(OperatingSystemTypeos)
18+
staticILibraryLoader_instance=null;
19+
20+
publicstaticILibraryLoaderInstance
1921
{
20-
switch(os)
22+
get
2123
{
22-
caseOperatingSystemType.Windows:
23-
returnnewWindowsLoader();
24-
caseOperatingSystemType.Darwin:
25-
returnnewDarwinLoader();
26-
caseOperatingSystemType.Linux:
27-
returnnewLinuxLoader();
28-
default:
29-
thrownewPlatformNotSupportedException($"This operating system ({os}) is not supported");
24+
if(_instance==null)
25+
{
26+
if(RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
27+
_instance=newWindowsLoader();
28+
elseif(RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
29+
_instance=newLinuxLoader();
30+
elseif(RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
31+
_instance=newDarwinLoader();
32+
else
33+
thrownewPlatformNotSupportedException(
34+
"This operating system is not supported"
35+
);
36+
}
37+
38+
return_instance;
3039
}
3140
}
3241
}

‎src/runtime/platform/NativeCodePage.cs

Lines changed: 17 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,6 @@ namespace Python.Runtime.Platform
66
{
77
classNativeCodePageHelper
88
{
9-
/// <summary>
10-
/// Gets the operating system as reported by python's platform.system().
11-
/// </summary>
12-
publicstaticOperatingSystemTypeOperatingSystem{get;privateset;}
13-
14-
/// <summary>
15-
/// Gets the operating system as reported by python's platform.system().
16-
/// </summary>
17-
[Obsolete]
18-
publicstaticstringOperatingSystemName=>PythonEngine.Platform;
19-
20-
/// <summary>
21-
/// Gets the machine architecture as reported by python's platform.machine().
22-
/// </summary>
23-
publicstaticMachineTypeMachine{get;privateset;}/* 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-
publicstaticstringMachineName{get;privateset;}
30-
319
/// <summary>
3210
/// Initialized by InitializeNativeCodePage.
3311
///
@@ -45,33 +23,6 @@ class NativeCodePageHelper
4523
internalstaticIntPtrNativeCodePage=IntPtr.Zero;
4624

4725

48-
staticreadonlyDictionary<string,OperatingSystemType>OperatingSystemTypeMapping=newDictionary<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-
staticreadonlyDictionary<string,MachineType>MachineTypeMapping=newDictionary<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-
7526
/// <summary>
7627
/// Structure to describe native code.
7728
///
@@ -108,11 +59,11 @@ public static NativeCode Active
10859
{
10960
get
11061
{
111-
switch(Machine)
62+
switch(RuntimeInformation.ProcessArchitecture)
11263
{
113-
caseMachineType.i386:
64+
caseArchitecture.X86:
11465
returnI386;
115-
caseMachineType.x86_64:
66+
caseArchitecture.X64:
11667
returnX86_64;
11768
default:
11869
returnnull;
@@ -205,14 +156,14 @@ int MAP_ANONYMOUS
205156
{
206157
get
207158
{
208-
switch(OperatingSystem)
159+
if(RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
209160
{
210-
caseOperatingSystemType.Darwin:
211-
return0x1000;
212-
caseOperatingSystemType.Linux:
213-
return0x20;
214-
default:
215-
thrownewNotImplementedException($"mmap is not supported on{OperatingSystemName}");
161+
return0x20;
162+
}
163+
else
164+
{
165+
// OSX, FreeBSD
166+
return0x1000;
216167
}
217168
}
218169
}
@@ -236,32 +187,16 @@ public void SetReadExec(IntPtr mappedMemory, int numBytes)
236187
}
237188
}
238189

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-
publicstaticvoidInitializePlatformData()
248-
{
249-
MachineName=SystemInfo.GetArchitecture();
250-
Machine=SystemInfo.GetMachineType();
251-
OperatingSystem=SystemInfo.GetSystemType();
252-
}
253-
254190
internalstaticIMemoryMapperCreateMemoryMapper()
255191
{
256-
switch(OperatingSystem)
192+
if(RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
193+
{
194+
returnnewWindowsMemoryMapper();
195+
}
196+
else
257197
{
258-
caseOperatingSystemType.Darwin:
259-
caseOperatingSystemType.Linux:
260-
returnnewUnixMemoryMapper();
261-
caseOperatingSystemType.Windows:
262-
returnnewWindowsMemoryMapper();
263-
default:
264-
thrownewNotImplementedException($"No support for{OperatingSystemName}");
198+
// Linux, OSX, FreeBSD
199+
returnnewUnixMemoryMapper();
265200
}
266201
}
267202

‎src/runtime/runtime.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,6 @@ internal static void Initialize(bool initSigs = false, ShutdownMode mode = Shutd
158158
ClassDerivedObject.Reset();
159159
TypeManager.Initialize();
160160

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-
166161
// Initialize modules that depend on the runtime class.
167162
AssemblyManager.Initialize();
168163
if(mode==ShutdownMode.Reload&&RuntimeData.HasStashData())
@@ -2153,7 +2148,7 @@ internal static void Py_CLEAR(ref IntPtr ob)
21532148

21542149
internalstaticvoid SetNoSiteFlag()
21552150
{
2156-
var loader= LibraryLoader.Get(NativeCodePageHelper.OperatingSystem);
2151+
var loader= LibraryLoader.Instance;
21572152
IntPtr dllLocal= IntPtr.Zero;
21582153
if(_PythonDll!= "__Internal")
21592154
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp