New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Inconsistent results from platform.machine() on Windows ARM64 #98962
Comments
|
Out of curiosity, can you install the x86 and AMD64 versions of 3.12.0a1 and check |
|
Success! Thanks for the tip. In 3.12.0a1, all binaries return I notice however that, in a similar issue on macOS, #96993, @rossng seems to have a different expectation. The problem remains that ARM64-on-ARM64 and AMD64-on-ARM64 are only distinguishable by Detailed output AMD64-on-ARM64x86-on-ARM64ARM64-on-ARM64AMD64-on-AMD64x86-on-AMD64 |
Have you checked Since you don't control the environment that was used to create the current process, it would be more reliable to call WinAPI |
|
Confirmed, these methods both work on all combinations, on both 3.11.0 and 3.12.0a1. Thanks! That will do as a workaround, although of course it would be nicer to have it abstracted in the (It seems weird that two processes started from the same shell would see different environments, but then I’m used to weirdness from Microsoft.) Detailed output Scriptimport os
print('PROCESSOR_ARCHITECTURE:', os.environ['PROCESSOR_ARCHITECTURE'])
import ctypes
import ctypes.wintypes
class SYSTEM_INFO(ctypes.Structure):
_fields_ = [('wProcessorArchitecture', ctypes.wintypes.WORD), ('dwPageSize', ctypes.wintypes.DWORD), ('lpMinimumApplicationAddress', ctypes.wintypes.LPVOID), ('lpMaximumApplicationAddress', ctypes.wintypes.LPVOID), ('dwActiveProcessorMask', ctypes.c_void_p), ('dwNumberOfProcessors', ctypes.wintypes.DWORD), ('dwProcessorType', ctypes.wintypes.DWORD), ('dwAllocationGranularity', ctypes.wintypes.DWORD), ('wProcessorLevel', ctypes.wintypes.WORD), ('wProcessorRevision', ctypes.wintypes.WORD)]
info = SYSTEM_INFO()
ctypes.windll.kernel32.GetSystemInfo(ctypes.byref(info))
print('GetSystemInfo: ', {f[0]: getattr(info, f[0]) for f in SYSTEM_INFO._fields_})
ctypes.windll.kernel32.GetNativeSystemInfo(ctypes.byref(info))
print('GetNativeSystemInfo:', {f[0]: getattr(info, f[0]) for f in SYSTEM_INFO._fields_})AMD64-on-ARM64x86-on-ARM64ARM64-on-ARM64AMD64-on-AMD64x86-on-AMD64 |
|
I just checked the source for QEMU user space emulation, which is used on Linux and BSD to emulate another CPU architecture in user space, relying on native system calls. When translating the Off-topic comments on using ctypes:
|
|
I’m not sure what is correct. Maybe before deciding about that one should discuss what is useful. I have use cases for wanting to know
So far I do not have a use case for wanting to know the emulated architecture, but it may exist. I would consider consistency across platforms very desirable (and, at the moment, lacking). What would also be useful in that regard is if one could agree on a known set of possible values for an “architecture”, in particular choose one of “x86_64” and “AMD64” and one of “aarch64” and “ARM64” and stick to it. (Thanks for the ctypes tips! Omitting |
Bug report
Running x86 and AMD64 builds of Python 3.11.0 (official binary releases) in emulation on Windows 11 on an ARM64 machine gives me
This seem inconsistent. I would expect both to return
'ARM64', the actual underlying processor architecture, in the same way as running an x86 build on AMD64 returns'AMD64'. But even if they were reporting the emulated architecture, it should be'AMD64'and'x86', not'AMD64'and'ARM64'(or possibly'AMD64'and'AMD64', if x86 binaries are also handled by the AMD64 emulator, I have no idea how that works).This makes it hard to distinguish between an AMD64 build running on ARM64 and an AMD64 build running on AMD64. In fact, the only
platformfunction that gives any indication at all isprocessor(), and parsing the desired information out of the free-form text returned by that seems fiddly. ('ARMv8 (64-bit) Family 8 Model 0 Revision 0, 'and'Intel64 Family 6 Model 44 Stepping 2, GenuineIntel'here.)Relatedly, how do I distinguish between an ARM64 build running on ARM64 and an AMD64 build running on ARM64? The inconsistency above makes them differ in
platform.machine(), but what if that were fixed? This seems like a job forplatform.architecture(), which is explicitly meant to give information about the running binary, but that just returns('64bit', 'WindowsPE')in both cases.platform.python_compiler()happens to have that information ('MSC v.1933 64 bit (ARM64)'vs.'MSC v.1933 64 bit (AMD64)'), but again that is fiddly free-form text and may not work for other compilers than MSC.Your environment
The text was updated successfully, but these errors were encountered: