GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-83714: Set os.statx() members to None if missing from stx_mask by vstinner · Pull Request #140216 · python/cpython

Conversation

@vstinner

@vstinner vstinner commented Oct 16, 2025 •
edited by bedevere-app Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member
  • Issue: Add os.statx() function #83714

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@vstinner vstinner added the skip news label Oct 16, 2025
@bedevere-app bedevere-app Bot mentioned this pull request Oct 16, 2025
Add os.statx() function #83714
Closed
@vstinner

vstinner commented Oct 16, 2025

Copy link
Copy Markdown
Member Author

See my comment #83714 (comment) for an explanation of this PR.

The PR is currently incomplete, it only supports some stx_result members such as st_atime and st_mtime.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner
vstinner force-pushed the statx_none branch from b23f8ff to 2fc5158 Compare October 16, 2025 18:29
@vstinner
pythongh-83714: Set os.statx() members to None if missing from stx_mask
289f458
@vstinner
vstinner force-pushed the statx_none branch from 2fc5158 to 289f458 Compare October 16, 2025 18:35
@vstinner

vstinner commented Oct 16, 2025

Copy link
Copy Markdown
Member Author

The PR is currently incomplete, it only supports some stx_result members such as st_atime and st_mtime.

I completed the PR to handle all stx_mask flags.

I didn't use these flags:

STATX_TYPE  Want stx_mode & S_IFMT
STATX_MODE  Want stx_mode & ~S_IFMT

statx manual page, up to date: https://man7.org/linux/man-pages/man2/statx.2.html

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

maurycy
maurycy reviewed Oct 16, 2025
View reviewed changes
Comment thread Modules/posixmodule.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Modules/posixmodule.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Modules/posixmodule.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Modules/posixmodule.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Modules/posixmodule.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

vstinner added 2 commits October 17, 2025 00:48
@vstinner
Fix copy/paste mistakes
106c5ad
@vstinner
Fix pystatx_result_repr()
52d7ef2
Change the logic to write the comma.
@vstinner

vstinner commented Oct 16, 2025

Copy link
Copy Markdown
Member Author

@maurycy: Thanks for your review. I updated my PR.

maurycy reacted with heart emoji
All reactions
  • ❤️ 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner
vstinner marked this pull request as ready for review October 17, 2025 01:06
@bedevere-app bedevere-app Bot added the awaiting core review label Oct 17, 2025
jbosboom
jbosboom reviewed Oct 17, 2025
View reviewed changes
Comment thread Modules/posixmodule.c
STATX_GET_NSEC(st_ctime_ns, stx_ctime, STATX_CTIME)
STATX_GET_NSEC(st_mtime_ns, stx_mtime, STATX_MTIME)

/* The low 16 bits of the context pointer are the offset from the start of

@jbosboom jbosboom Oct 17, 2025

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I know the mask bit itself won't fit in the context pointer on 32-bit, but you could store the mask bit index in the upper 16 bits. For example, STATX_ATIME is 0x20, so you'd store 5 in the upper 16 bits, and recover the mask bit as 1 << i in the getter. That way you'd only need one getter per type, rather than one per member, which is a lot less code.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@jbosboom jbosboom Oct 17, 2025

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

(You probably already know, but just in case, you can get the bit index with __builtin_ctz, and both GCC and Clang will evaluate __builtin_ctz at compile time when the arguments are constant.)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@vstinner vstinner Oct 17, 2025

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I prefer to avoid bad surprises on 32-bit systems when Linux will get more bits in mask. If all bits of mask are used, there will be no remaining place for an offset. It sounds more future proof to do as i did, one function per member and put the mask and "offset" there.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@jbosboom jbosboom Oct 17, 2025

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Perhaps I wasn't clear. I'm not proposing to store the mask in the context pointer; I'm proposing to store the index of the mask bit, which is a number from 0 to 31. Even if the mask were somehow extended to 64 bits in the future, the index would then be from 0 to 63, which would still easily fit.

CPython doesn't really care about code size, so I'm fine with the way you did it.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@vstinner vstinner Oct 18, 2025

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Oh ok. The problem is that I'm not sure that all compilers supported by Python on Linux can compute the bit position at build time.

I don't think that code size is an issue here.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

jbosboom reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@vstinner

vstinner commented Oct 17, 2025

Copy link
Copy Markdown
Member Author

cc @gpshead @serhiy-storchaka

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner
Document None in os.rst
ac61fd9
@vstinner
vstinner merged commit 3222ea0 into python:main Oct 20, 2025
4 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@vstinner
vstinner deleted the statx_none branch October 20, 2025 15:59
@bedevere-app bedevere-app Bot removed the awaiting core review label Oct 20, 2025
StanFromIreland pushed a commit to StanFromIreland/cpython that referenced this pull request Dec 6, 2025
@vstinner @StanFromIreland
pythongh-83714: Set os.statx() members to None if missing from stx_ma…
f00083d
…sk (python#140216)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

2 more reviewers
@maurycy maurycy maurycy left review comments
@jbosboom jbosboom jbosboom left review comments
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

skip news

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@vstinner @maurycy @jbosboom
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.