Author vstinner
Recipients Windson Yang, lemburg, ronaldoussoren, serhiy.storchaka, vstinner
Date 2018-12-17.09:13:53
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1545038034.39.0.788709270274.issue35348@psf.upfronthosting.co.za>
In-reply-to
Content
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".
History
Date User Action Args
2018-12-17 09:13:54vstinnersetrecipients: + vstinner, lemburg, ronaldoussoren, serhiy.storchaka, Windson Yang
2018-12-17 09:13:54vstinnersetmessageid: <1545038034.39.0.788709270274.issue35348@psf.upfronthosting.co.za>
2018-12-17 09:13:54vstinnerlinkissue35348 messages
2018-12-17 09:13:53vstinnercreate