Skip to content

gh-83714: Use statx on Linux 4.11 and later in os.stat #136334

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jbosboom
Copy link

@jbosboom jbosboom commented Jul 6, 2025

I've posted some questions in gh-83714. For now, this PR should be considered earnest effort (in the sense of earnest money). It will change based on the answers to the questions in the issue. It needs tests for the new features and the fallback that are not obvious to implement. I need guidance as to when it should strictly conform to PEP 7 and when it should match the surrounding code style (especially with regards to brace placement). But it should demonstrate I'm willing and able.

The libc statx wrapper is required at build time, but weakly linked. There is no configure test; we just look for STATX_BASIC_STATS being defined by sys/stat.h. posix_do_stat will fall back to calling stat if statx is not available at runtime due to an old libc or an old kernel. The fallback variable statx_works is based on dup3_works, for the thread-safety of which see @ericsnowcurrently's comment. The values are (to me) nonobvious: -1 means statx has never failed, 0 means its first failure was ENOSYS and 1 means its first failure was something other than ENOSYS.

This PR is not directly based on gh-19125, but was greatly informed by it, and I'd be happy to give Co-authored-by and/or blurb credit to @ntninja.


📚 Documentation preview 📚: https://cpython-previews--136334.org.readthedocs.build/

The libc statx wrapper is required at build time, but weakly linked, and
posix_do_stat will fall back to calling stat if statx is not available
at runtime due to an old libc or an old kernel.
@python-cla-bot
Copy link

python-cla-bot bot commented Jul 6, 2025

All commit authors signed the Contributor License Agreement.

CLA signed

@bedevere-app
Copy link

bedevere-app bot commented Jul 6, 2025

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@StanFromIreland
Copy link
Member

Please update the title to use the gh issue number.

See the :const:`!STATX_ATTR* <stat.STATX_ATTR_COMPRESSED>`
constants in the :mod:`stat` module.

.. versionadded: next
Copy link
Member

Choose a reason for hiding this comment

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

These need a double colon, otherwise they are parsed as comments.

@jbosboom jbosboom changed the title bpo-39533: Use statx on Linux 4.11 and later in os.stat gh-83714: Use statx on Linux 4.11 and later in os.stat Jul 6, 2025
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.

2 participants