STINNER Victor <[email protected]> added the comment:
Ronald Oussoren gave more info on my previous PR 10780 ("platform.platform()
uses mac_ver() on macOS"):
https://github.com/python/cpython/pull/10780#issuecomment-444529371
"""
The information does not include data about fat binaries, resulting amongst
others in the following inconsistency:
ronald@Menegroth[0]$ arch -i386 python3.6 -m platform
Darwin-18.2.0-x86_64-i386-64bit
ronald@Menegroth[0]$ arch -i386 python3.6 -c 'import sys; print(sys.maxsize)'
2147483647
This platform output includes "64bit" because the binary for python3.6 includes
support for both i386 and x86_64, and doesn't show that the command is using
i386 instructions.
"""
I made some tests:
$ file /usr/local/bin/python3
/usr/local/bin/python3: Mach-O universal binary with 2 architectures:
[i386:Mach-O executable i386] [x86_64:Mach-O 64-bit executable x86_64]
/usr/local/bin/python3 (for architecture i386): Mach-O executable i386
/usr/local/bin/python3 (for architecture x86_64): Mach-O 64-bit
executable x86_64
$ /usr/local/bin/python3 -c 'import struct, sys, platform;
print(platform.architecture(), struct.calcsize("P"), sys.maxsize)'
('64bit', '') 8 9223372036854775807
$ arch -x86_64 /usr/local/bin/python3 -c 'import struct, sys, platform;
print(platform.architecture(), struct.calcsize("P"), sys.maxsize)'
('64bit', '') 8 9223372036854775807
$ arch -i386 /usr/local/bin/python3 -c 'import struct, sys, platform;
print(platform.architecture(), struct.calcsize("P"), sys.maxsize)'
('64bit', '') 4 2147483647
IMHO platform.architecture() should return 32bit when running "arch -i386
/usr/local/bin/python3" to be consistent with struct.calcsize("P") == 4 and
sys.maxsize == 2147483647. Otherwise, how would you notice that you are using
the 32-bit flavor of Python?
My PR 11186 implements this fix.
Ronald Oussoren:
> Using sizeof(void*) or sys.maxsize suffers from the a simular problem: this
> will only detect the pointer-size of the current proces and not that the
> binary is capable of running with a different pointer-size as well.
Right, but I don't think that it's possible to report that Python executable is
FAT binary in platform.architecture() result. If you want to provide such
information, IMHO you should write a new function or at least add a new
parameter to platform.architecture().
IMHO it's more consistent to report "32bit" for "arch -i386 python3" and
"64bit" for "arch -x86_64 python3".
----------
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue35348>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com