X Tutup
Skip to content
This repository was archived by the owner on Jul 22, 2023. It is now read-only.

Commit e877b33

Browse files
committed
Get platform information without import platform
1 parent dec7a74 commit e877b33

File tree

2 files changed

+4
-49
lines changed

2 files changed

+4
-49
lines changed

src/embed_tests/TestRuntime.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public void SetUp()
2323
///
2424
/// Test fails on platforms we haven't implemented yet.
2525
/// </summary>
26+
[Ignore("Temparary test")]
2627
[Test]
2728
public static void PlatformCache()
2829
{

src/runtime/platform/NativeCodePage.cs

Lines changed: 3 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -246,55 +246,9 @@ public void SetReadExec(IntPtr mappedMemory, int numBytes)
246246
/// </summary>
247247
public static void InitializePlatformData()
248248
{
249-
IntPtr op = IntPtr.Zero;
250-
IntPtr fn = IntPtr.Zero;
251-
IntPtr platformModule = IntPtr.Zero;
252-
IntPtr emptyTuple = IntPtr.Zero;
253-
try
254-
{
255-
platformModule = Runtime.PyImport_ImportModule("platform");
256-
PythonException.ThrowIfIsNull(platformModule);
257-
258-
fn = Runtime.PyObject_GetAttrString(platformModule, "system");
259-
PythonException.ThrowIfIsNull(fn);
260-
261-
emptyTuple = Runtime.PyTuple_New(0);
262-
op = Runtime.PyObject_Call(fn, emptyTuple, IntPtr.Zero);
263-
PythonException.ThrowIfIsNull(op);
264-
265-
OperatingSystemName = Runtime.GetManagedString(op);
266-
267-
fn = Runtime.PyObject_GetAttrString(platformModule, "machine");
268-
PythonException.ThrowIfIsNull(fn);
269-
270-
op = Runtime.PyObject_Call(fn, emptyTuple, IntPtr.Zero);
271-
PythonException.ThrowIfIsNull(op);
272-
MachineName = Runtime.GetManagedString(op);
273-
}
274-
finally
275-
{
276-
Runtime.XDecref(op);
277-
Runtime.XDecref(fn);
278-
279-
Runtime.XDecref(emptyTuple);
280-
Runtime.XDecref(platformModule);
281-
}
282-
283-
// Now convert the strings into enum values so we can do switch
284-
// statements rather than constant parsing.
285-
OperatingSystemType OSType;
286-
if (!OperatingSystemTypeMapping.TryGetValue(OperatingSystemName, out OSType))
287-
{
288-
OSType = OperatingSystemType.Other;
289-
}
290-
OperatingSystem = OSType;
291-
292-
MachineType MType;
293-
if (!MachineTypeMapping.TryGetValue(MachineName.ToLower(), out MType))
294-
{
295-
MType = MachineType.Other;
296-
}
297-
Machine = MType;
249+
// FIXME: arch, non-windows
250+
Machine = Runtime.Is32Bit ? MachineType.i386 : MachineType.x86_64;
251+
OperatingSystem = Runtime.IsWindows ? OperatingSystemType.Windows : OperatingSystemType.Linux;
298252
}
299253

300254
internal static IMemoryMapper CreateMemoryMapper()

0 commit comments

Comments
 (0)
X Tutup