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
This repository was archived by the owner on Jul 22, 2023. It is now read-only.
/pythonnetPublic archive
forked frompythonnet/pythonnet

Commit5753d38

Browse files
committed
Drop InitializePlatformData
1 parent60d15cd commit5753d38

File tree

4 files changed

+36
-142
lines changed

4 files changed

+36
-142
lines changed

‎Python.Runtime/platform/InternalLoadContext.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,8 @@ class InternalLoadContext : AssemblyLoadContext
1010

1111
protectedoverrideIntPtrLoadUnmanagedDll(stringname)
1212
{
13-
if(name=="__Internal")
14-
{
15-
varloader=LibraryLoader.Get(OperatingSystemType.Linux);
16-
returnloader.Load(null);
17-
}
18-
19-
returnIntPtr.Zero;
13+
varfiltered=name=="__Internal"?null:name;
14+
returnLibraryLoader.Instance.Load(filtered);
2015
}
2116

2217
publicstaticAssemblyLoadContextInstance{get;}=newInternalLoadContext();

‎Python.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.OSX))
29+
_instance=newDarwinLoader();
30+
elseif(RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
31+
_instance=newLinuxLoader();
32+
else
33+
thrownewPlatformNotSupportedException(
34+
$"This operating system is not supported"
35+
);
36+
}
37+
38+
return_instance;
3039
}
3140
}
3241
}

‎Python.Runtime/runtime.cs

Lines changed: 2 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -26,56 +26,7 @@ public static partial class Runtime
2626

2727
internalstaticboolIs32Bit=IntPtr.Size==4;
2828

29-
// .NET core: System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
30-
internalstaticboolIsWindows=Environment.OSVersion.Platform==PlatformID.Win32NT;
31-
32-
staticreadonlyDictionary<string,OperatingSystemType>OperatingSystemTypeMapping=newDictionary<string,OperatingSystemType>()
33-
{
34-
{"Windows",OperatingSystemType.Windows},
35-
{"Darwin",OperatingSystemType.Darwin},
36-
{"Linux",OperatingSystemType.Linux},
37-
};
38-
39-
/// <summary>
40-
/// Gets the operating system as reported by python's platform.system().
41-
/// </summary>
42-
publicstaticOperatingSystemTypeOperatingSystem{get;privateset;}
43-
44-
/// <summary>
45-
/// Gets the operating system as reported by python's platform.system().
46-
/// </summary>
47-
publicstaticstringOperatingSystemName{get;privateset;}
48-
49-
50-
/// <summary>
51-
/// Map lower-case version of the python machine name to the processor
52-
/// type. There are aliases, e.g. x86_64 and amd64 are two names for
53-
/// the same thing. Make sure to lower-case the search string, because
54-
/// capitalization can differ.
55-
/// </summary>
56-
staticreadonlyDictionary<string,MachineType>MachineTypeMapping=newDictionary<string,MachineType>()
57-
{
58-
["i386"]=MachineType.i386,
59-
["i686"]=MachineType.i386,
60-
["x86"]=MachineType.i386,
61-
["x86_64"]=MachineType.x86_64,
62-
["amd64"]=MachineType.x86_64,
63-
["x64"]=MachineType.x86_64,
64-
["em64t"]=MachineType.x86_64,
65-
["armv7l"]=MachineType.armv7l,
66-
["armv8"]=MachineType.armv8,
67-
["aarch64"]=MachineType.aarch64,
68-
};
69-
70-
/// <summary>
71-
/// Gets the machine architecture as reported by python's platform.machine().
72-
/// </summary>
73-
publicstaticMachineTypeMachine{get;privateset;}/* set in Initialize using python's platform.machine */
74-
75-
/// <summary>
76-
/// Gets the machine architecture as reported by python's platform.machine().
77-
/// </summary>
78-
publicstaticstringMachineName{get;privateset;}
29+
internalstaticboolIsWindows=RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
7930

8031
#ifPYTHON2
8132
internalstaticboolIsPython2=true;
@@ -221,13 +172,8 @@ internal static void Initialize(bool initSigs = false)
221172

222173
Error=newIntPtr(-1);
223174

224-
// Initialize data about the platform we're running on. We need
225-
// this for the type manager and potentially other details. Must
226-
// happen after caching the python types, above.
227-
InitializePlatformData();
228-
229175
IntPtrdllLocal=IntPtr.Zero;
230-
varloader=LibraryLoader.Get(OperatingSystem);
176+
varloader=LibraryLoader.Instance;
231177

232178
_PyObject_NextNotImplemented=loader.GetFunction(dllLocal,"_PyObject_NextNotImplemented");
233179
PyModuleType=loader.GetFunction(dllLocal,"PyModule_Type");
@@ -248,53 +194,6 @@ internal static void Initialize(bool initSigs = false)
248194
AssemblyManager.UpdatePath();
249195
}
250196

251-
/// <summary>
252-
/// Initializes the data about platforms.
253-
///
254-
/// This must be the last step when initializing the runtime:
255-
/// GetManagedString needs to have the cached values for types.
256-
/// But it must run before initializing anything outside the runtime
257-
/// because those rely on the platform data.
258-
/// </summary>
259-
privatestaticvoidInitializePlatformData()
260-
{
261-
IntPtrop;
262-
IntPtrfn;
263-
IntPtrplatformModule=PyImport_ImportModule("platform");
264-
IntPtremptyTuple=PyTuple_New(0);
265-
266-
fn=PyObject_GetAttrString(platformModule,"system");
267-
op=PyObject_Call(fn,emptyTuple,IntPtr.Zero);
268-
OperatingSystemName=GetManagedString(op);
269-
XDecref(op);
270-
XDecref(fn);
271-
272-
fn=PyObject_GetAttrString(platformModule,"machine");
273-
op=PyObject_Call(fn,emptyTuple,IntPtr.Zero);
274-
MachineName=GetManagedString(op);
275-
XDecref(op);
276-
XDecref(fn);
277-
278-
XDecref(emptyTuple);
279-
XDecref(platformModule);
280-
281-
// Now convert the strings into enum values so we can do switch
282-
// statements rather than constant parsing.
283-
OperatingSystemTypeOSType;
284-
if(!OperatingSystemTypeMapping.TryGetValue(OperatingSystemName,outOSType))
285-
{
286-
OSType=OperatingSystemType.Other;
287-
}
288-
OperatingSystem=OSType;
289-
290-
MachineTypeMType;
291-
if(!MachineTypeMapping.TryGetValue(MachineName.ToLower(),outMType))
292-
{
293-
MType=MachineType.Other;
294-
}
295-
Machine=MType;
296-
}
297-
298197
internalstaticvoidShutdown()
299198
{
300199
AssemblyManager.Shutdown();

‎Python.Runtime/typemanager.cs

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -503,11 +503,11 @@ public static NativeCode Active
503503
{
504504
get
505505
{
506-
switch(Runtime.Machine)
506+
switch(RuntimeInformation.ProcessArchitecture)
507507
{
508-
caseMachineType.i386:
508+
caseArchitecture.X86:
509509
returnI386;
510-
caseMachineType.x86_64:
510+
caseArchitecture.X64:
511511
returnX86_64;
512512
default:
513513
returnnull;
@@ -600,15 +600,12 @@ int MAP_ANONYMOUS
600600
{
601601
get
602602
{
603-
switch(Runtime.OperatingSystem)
604-
{
605-
caseOperatingSystemType.Darwin:
606-
return0x1000;
607-
caseOperatingSystemType.Linux:
608-
return0x20;
609-
default:
610-
thrownewNotImplementedException($"mmap is not supported on{Runtime.OperatingSystemName}");
611-
}
603+
if(RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
604+
return0x1000;
605+
elseif(RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
606+
return0x20;
607+
else
608+
thrownewNotImplementedException($"mmap is not supported on this operating system");
612609
}
613610
}
614611

@@ -633,16 +630,10 @@ public void SetReadExec(IntPtr mappedMemory, int numBytes)
633630

634631
internalstaticIMemoryMapperCreateMemoryMapper()
635632
{
636-
switch(Runtime.OperatingSystem)
637-
{
638-
caseOperatingSystemType.Darwin:
639-
caseOperatingSystemType.Linux:
640-
returnnewUnixMemoryMapper();
641-
caseOperatingSystemType.Windows:
642-
returnnewWindowsMemoryMapper();
643-
default:
644-
thrownewNotImplementedException($"No support for{Runtime.OperatingSystemName}");
645-
}
633+
if(Runtime.IsWindows)
634+
returnnewWindowsMemoryMapper();
635+
else
636+
returnnewUnixMemoryMapper();
646637
}
647638

648639
/// <summary>

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp