Skip to content
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

platform.architecture() with Python2.7-32 misreports architecture on macOS. #73791

Closed
culler mannequin opened this issue Feb 20, 2017 · 5 comments
Closed

platform.architecture() with Python2.7-32 misreports architecture on macOS. #73791

culler mannequin opened this issue Feb 20, 2017 · 5 comments
Assignees
Labels

Comments

@culler
Copy link
Mannequin

culler mannequin commented Feb 20, 2017

BPO 29605
Nosy @malemburg, @ronaldoussoren, @ned-deily

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = 'https://github.com/malemburg'
closed_at = <Date 2017-02-20.16:57:23.624>
created_at = <Date 2017-02-20.13:13:49.018>
labels = ['OS-mac', 'invalid']
title = 'platform.architecture() with Python2.7-32 misreports architecture on macOS.'
updated_at = <Date 2017-02-20.19:00:09.390>
user = 'https://bugs.python.org/culler'

bugs.python.org fields:

activity = <Date 2017-02-20.19:00:09.390>
actor = 'lemburg'
assignee = 'lemburg'
closed = True
closed_date = <Date 2017-02-20.16:57:23.624>
closer = 'lemburg'
components = ['macOS']
creation = <Date 2017-02-20.13:13:49.018>
creator = 'culler'
dependencies = []
files = []
hgrepos = []
issue_num = 29605
keywords = []
message_count = 5.0
messages = ['288200', '288218', '288220', '288225', '288226']
nosy_count = 4.0
nosy_names = ['lemburg', 'ronaldoussoren', 'ned.deily', 'culler']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = 'resolved'
status = 'closed'
superseder = None
type = None
url = 'https://bugs.python.org/issue29605'
versions = ['Python 2.7']

@culler
Copy link
Mannequin Author

culler mannequin commented Feb 20, 2017

On macOS, the 32 bit python 2.7 reports its architecture as '64bit' in platform.architecture(). Note that the 32 bit Python versions 3.4, 3.5 and 3.6 all correctly report '32bit'.

$ python-32
Python 2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 12:39:47) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import platform
>>> platform.architecture()[0]
'64bit'
>>> import sys
>>> sys.maxsize > 2**32
False

@culler culler mannequin added the OS-mac label Feb 20, 2017
@ned-deily
Copy link
Member

platform.architecture() is documented as giving unreliable results with macOS universal files; see https://docs.python.org/2/library/platform.html#platform.architecture. The difference in behavior between Python 2.7 and 3.x for the example you show is due to the difference in the value of sys.executable between them on macOS. On 2.7, sys.executable points to the actual Python interpreter binary, which is a universal binary. On 3.x, the behavior was changed to not to resolve to the interpreter binary but rather the stub launcher binary and the "-32" launcher has only 32-bit executables:

$ /usr/local/bin/python2.7-32 -c 'import sys;print(sys.executable)'
/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python
$ /usr/local/bin/python3.6-32 -c 'import sys;print(sys.executable)'
/usr/local/bin/python3.6-32

Because platform.architecture() uses the "file" utility to examine the contents of the file pointed to by sys.executable, this change in 3.x has the side effect of producing the expected "32bit" value on 3.x when Python is invoked in this manner.

However, that doesn't cover all cases. For example:

$ arch -i386 /usr/local/bin/python3.6 -c 'import sys,platform;print(platform.architecture(), sys.maxsize > 2**32)'
('64bit', '') False

So the 3.x platform.architecture can still produce incorrect results. One can argue about what value(s) platform.architecture() should return for multi-architecture binaries; languishing bpo-10735 covers that. One could also argue that the value of sys.executable on 2.7 should be changed to behave like 3.x but it's very late in the life of 2.7 to be making a change like that and that change alone would not produce correct results for all cases, like "arch -i386" above.

@ned-deily ned-deily changed the title Python2.7-32 misreports architecture on macOS. platform.architecture() with Python2.7-32 misreports architecture on macOS. Feb 20, 2017
@malemburg
Copy link
Member

Thanks for the report, but there really isn't much we can do, since the API is not geared up for handling executables which contain binaries for multiple architectures.

AFAIK, the Python 3 binaries available from python.org are no longer built as universal binaries, so the problem doesn't show with those.

@ned-deily
Copy link
Member

AFAIK, the Python 3 binaries available from python.org are no longer built as universal binaries, so the problem doesn't show with those.

All python.org Mac binaries are built as universal. For example:

$ file /usr/local/bin/python3.6
/usr/local/bin/python3.6: 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.6 (for architecture i386):	Mach-O executable i386
/usr/local/bin/python3.6 (for architecture x86_64):	Mach-O 64-bit executable x86_64

@malemburg
Copy link
Member

Ok, thanks for the clarification. So if I understand correctly, the main change in Python 3 is that points to the stub launcher, not the binary itself.

In any case, a new function would have to be added to the platform module to query multiple architectures available in a binary and probably another one to return the architecture that Python runs.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants