Movatterモバイル変換


[0]ホーム

URL:


homepage

Issue35389

This issue trackerhas been migrated toGitHub, and is currentlyread-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title:Use gnu_get_libc_version() in platform.libc_ver()?
Type:Stage:resolved
Components:Library (Lib)Versions:Python 3.8
process
Status:closedResolution:fixed
Dependencies:Superseder:
Assigned To:Nosy List: jwilk, lemburg, serhiy.storchaka, vstinner
Priority:normalKeywords:patch

Created on2018-12-03 16:02 byvstinner, last changed2022-04-11 14:59 byadmin. This issue is nowclosed.

Pull Requests
URLStatusLinkedEdit
PR 10891mergedvstinner,2018-12-04 11:47
PR 10951mergedvstinner,2018-12-05 21:03
PR 14418mergedvstinner,2019-06-26 23:43
Messages (11)
msg330952 -(view)Author: STINNER Victor (vstinner)*(Python committer)Date: 2018-12-03 16:02
Currently, platform.libc_ver() opens Python binary file (ex: /usr/bin/python3) and looks for a string like "GLIBC-2.28".Maybe gnu_get_libc_version() should be exposed in Python to get the version of the running glibc version? And use it if available, or fall back on parsing the binary file (as done currenetly) otherwise.Example:$ cat x.c #include <gnu/libc-version.h>#include <stdlib.h>#include <stdio.h>intmain(int argc, char *argv[]){    printf("GNU libc version: %s\n", gnu_get_libc_version());    printf("GNU libc release: %s\n", gnu_get_libc_release());    exit(EXIT_SUCCESS);}$ ./xGNU libc version: 2.28GNU libc release: stableI'm not sure if it's possible that Python is compiled with glibc but run with a different libc implementation?--Alternative: run a program to get the libc version which *might* be different than the libc version of Python if the libc is upgraded in the meanwhile (unlikely, but is technically possible on a server running for days):$ ldd --versionldd (GNU libc) 2.28...$ /lib64/libc.so.6 GNU C Library (GNU libc) stable release version 2.28....$ rpm -q glibcglibc-2.28-17.fc29.x86_64...etc.--See also discussions on platform.libc_ver() performance:https://github.com/python/cpython/pull/10868
msg330953 -(view)Author: Jakub Wilk (jwilk)Date: 2018-12-03 16:24
You can use confstr to get (running) glibc version:>>> os.confstr('CS_GNU_LIBC_VERSION')'glibc 2.28'
msg330956 -(view)Author: STINNER Victor (vstinner)*(Python committer)Date: 2018-12-03 16:38
> >>> os.confstr('CS_GNU_LIBC_VERSION')> 'glibc 2.28'That's cool because it doesn't require to write new C code ;-)
msg331036 -(view)Author: Serhiy Storchaka (serhiy.storchaka)*(Python committer)Date: 2018-12-04 12:03
Currently libc_ver() can be used for other executable. Seeissue26544 for discussion about libc_ver().
msg331041 -(view)Author: STINNER Victor (vstinner)*(Python committer)Date: 2018-12-04 13:12
> Currently libc_ver() can be used for other executable. Seeissue26544 for discussion about libc_ver().Oh, my PR had a bug: it ignores executable. Fixed: it now only uses os.confstr() if the executable argument is not set.
msg331109 -(view)Author: STINNER Victor (vstinner)*(Python committer)Date: 2018-12-05 13:04
New changeset476b113ed8531b9fbb0bd023a05eb3af21996600 by Victor Stinner in branch 'master':bpo-35389: platform.libc_ver() uses os.confstr() (GH-10891)https://github.com/python/cpython/commit/476b113ed8531b9fbb0bd023a05eb3af21996600
msg331117 -(view)Author: STINNER Victor (vstinner)*(Python committer)Date: 2018-12-05 14:26
> 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%)Oops, my benchmark in the commit message was wrong, it includes the startup time...Correct benchmark says 44,538x faster, it's *WAY* better![regex] 56.1 ms +- 1.9 ms -> [confstr] 1.26 us +- 0.04 us: 44537.88x faster (-100%)
msg331124 -(view)Author: Marc-Andre Lemburg (lemburg)*(Python committer)Date: 2018-12-05 14:52
Nice. I never liked the "parse the executable approach", but there wasn't anything better available at the time.
msg331126 -(view)Author: STINNER Victor (vstinner)*(Python committer)Date: 2018-12-05 14:59
> Nice. I never liked the "parse the executable approach", but there wasn't anything better available at the time.Aha. Well, it's not perfect but it works and was fast enough (since libc_ver() is never used in performance critical code) :-)I'm now curious and looked at the history of this feature."man confstr" says:> _CS_GNU_LIBC_VERSION (GNU C library only; since glibc 2.3.2)glibc 2.3.2 has been released in March 2003, so it's fine, we should get this constant in most "modern" Linux (using glibc) in 2018 :-)man gnu_get_libc_version says:> These functions first appeared in glibc in version 2.1.glibc 2.1 has been released in Feb 1999. Using this function might provide even better compatibility but I'm not sure that it's worth it to use it. As I wrote, I prefer to not write a new function C, if os.confstr() can already be used in pure Python!Sadly, these functions (confstr(_CS_GNU_LIBC_VERSION) / gnu_get_libc_version()) are specific to glibc. Sorry, I'm not interested to support other libc, I mostly care about Fedora, sorry :-)
msg331185 -(view)Author: STINNER Victor (vstinner)*(Python committer)Date: 2018-12-05 22:21
New changeset848acf7249b5669d73d70a7cb6e5ab60689cf825 by Victor Stinner in branch 'master':bpo-35389: test.pythoninfo logs platform.libc_ver (GH-10951)https://github.com/python/cpython/commit/848acf7249b5669d73d70a7cb6e5ab60689cf825
msg346713 -(view)Author: STINNER Victor (vstinner)*(Python committer)Date: 2019-06-27 07:04
New changeseta719c8f4bd3cc5b1d98700c15c4a818f4d5617a4 by Victor Stinner in branch 'master':bpo-35389: platform.platform() calls libc_ver() without executable (GH-14418)https://github.com/python/cpython/commit/a719c8f4bd3cc5b1d98700c15c4a818f4d5617a4
History
DateUserActionArgs
2022-04-11 14:59:08adminsetgithub: 79570
2019-06-27 07:04:39vstinnersetmessages: +msg346713
2019-06-26 23:43:33vstinnersetpull_requests: +pull_request14231
2018-12-05 22:21:56vstinnersetmessages: +msg331185
2018-12-05 21:03:13vstinnersetpull_requests: +pull_request10201
2018-12-05 14:59:31vstinnersetmessages: +msg331126
2018-12-05 14:52:24lemburgsetnosy: +lemburg
messages: +msg331124
2018-12-05 14:26:48vstinnersetmessages: +msg331117
2018-12-05 13:53:18vstinnersetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2018-12-05 13:04:57vstinnersetmessages: +msg331109
2018-12-04 13:12:14vstinnersetmessages: +msg331041
2018-12-04 12:03:18serhiy.storchakasetnosy: +serhiy.storchaka
messages: +msg331036
2018-12-04 11:47:51vstinnersetkeywords: +patch
stage: patch review
pull_requests: +pull_request10130
2018-12-03 16:38:33vstinnersetmessages: +msg330956
2018-12-03 16:24:04jwilksetnosy: +jwilk
messages: +msg330953
2018-12-03 16:02:13vstinnercreate
Supported byThe Python Software Foundation,
Powered byRoundup
Copyright © 1990-2022,Python Software Foundation
Legal Statements

[8]ページ先頭

©2009-2026 Movatter.jp