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

bpo-35389: platform.libc_ver() uses os.confstr() #10891

Merged
merged 2 commits into from
Dec 5, 2018
Merged

bpo-35389: platform.libc_ver() uses os.confstr() #10891

merged 2 commits into from
Dec 5, 2018

Conversation

vstinner
Copy link
Member

@vstinner vstinner commented Dec 4, 2018

platform.libc_ver() now uses os.confstr('CS_GNU_LIBC_VERSION') if
available.

Quick benchmark on Fedora 29:

python3 -m perf command ./python -S -c 'import platform; platform.libc_ver()'
94.9 ms +- 4.3 ms -> 33.2 ms +- 1.4 ms: 2.86x faster (-65%)

https://bugs.python.org/issue35389

Lib/platform.py Outdated
parts = ver.split(maxsplit=1)
if len(parts) == 2:
return tuple(parts)
except (AttributeError, ValueError):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On some systems (IIRC using musl libc) os.confstr('CS_GNU_LIBC_VERSION') fails with OSError, so that should be caught too.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I didn't know. It's now fixed.

@@ -0,0 +1,2 @@
:func:`platform.libc_ver` now uses ``os.confstr('CS_GNU_LIBC_VERSION')`` if
available.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I should add that it's only used if the executable parameter is not set.

@vstinner
Copy link
Member Author

vstinner commented Dec 5, 2018

Travis CI failed because of https://bugs.python.org/issue35411 :-( I just fixed this issue, this PR should be rebase (or merged with master).

platform.libc_ver() now uses os.confstr('CS_GNU_LIBC_VERSION') if
available and the *executable* parameter is not set. The default
value of the libc_ver() *executable* parameter becomes None.

Quick benchmark on Fedora 29:

python3 -m perf command ./python -S -c 'import platform; platform.libc_ver()'
94.9 ms +- 4.3 ms -> 33.2 ms +- 1.4 ms: 2.86x faster (-65%)
@vstinner
Copy link
Member Author

vstinner commented Dec 5, 2018

I squashed my commits and rebased my PR.

Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test overrides the existing test test_libc_ver.

@bedevere-bot
Copy link

When you're done making the requested changes, leave the comment: I have made the requested changes; please review again.

And if you don't make the requested changes, you will be put in the comfy chair!

@vstinner
Copy link
Member Author

vstinner commented Dec 5, 2018

I have made the requested changes; please review again.

@bedevere-bot
Copy link

Thanks for making the requested changes!

@serhiy-storchaka: please review the changes made to this pull request.

@vstinner
Copy link
Member Author

vstinner commented Dec 5, 2018

The test overrides the existing test test_libc_ver.

Oops, I missed these tests! It's now fixed.

@vstinner vstinner merged commit 476b113 into python:master Dec 5, 2018
@vstinner vstinner deleted the platform_confstr branch December 5, 2018 13:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants