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-152433: Windows: modernize and refactor fileutils to allow build for Windows UWP by thexai · Pull Request #153700 · python/cpython

Conversation

@thexai

@thexai thexai commented Jul 14, 2026 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

Windows: modernize and refactor fileutils to allow build for Windows UWP

This is probably the last relevant commit missing to allow compile all Python core for UWP.

GetFileInformationByHandle is not supported in UWP, then is replaced with more modern GetFileInformationByHandleEx calls.

Also code refactored to avoid some duplicated code.

Note that Xbox (all models) runs only on Windows 11 based OS. Then is guaranteed that "fast stat" code (based on GetFileInformationByName) is supported:

cpython/Modules/posixmodule.c

Line 2299 in 050a84b

if (_Py_GetFileInformationByName(path, FileStatBasicByNameInfo,

"slow stat" code path is not much relevant for UWP but also works if replaced CreateFileW with CreateFile2 (in other PR).

  • Issue: Windows: improve compatibility to build for UWP / Xbox #152433

Sorry, something went wrong.

Uh oh!

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

All reactions
@bedevere-app bedevere-app Bot mentioned this pull request Jul 14, 2026
Windows: improve compatibility to build for UWP / Xbox #152433
Open
@bedevere-app bedevere-app Bot added the awaiting review label Jul 14, 2026
@thexai
thexai force-pushed the uwp-fileutils branch from a26c789 to 866215a Compare July 17, 2026 14:22
@thexai

thexai commented Jul 17, 2026

Copy link
Copy Markdown
Contributor Author

Updated with more simplified and less invasive changes.

All reactions

Sorry, something went wrong.

Uh oh!

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

@thexai
thexai force-pushed the uwp-fileutils branch 3 times, most recently from 57f8125 to f0f837b Compare July 19, 2026 08:33
@chris-eibl

chris-eibl commented Jul 19, 2026

Copy link
Copy Markdown
Member

This breaks CI, e.g.

test_1686475 (test.test_os.test_os.StatAttributeTests.test_1686475) ... Windows fatal exception: access violation

Can you reproduce this on a local Windows installation and fix?

Regarding tests I have another question: are you able to run the tests on XBOX in general? I'd be curious in how many of them fail ...

All reactions

Sorry, something went wrong.

Uh oh!

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

@thexai
pythongh-152433: Windows: modernize fileutils to allow build for Wind…
190b3f2
…ows UWP
@thexai
thexai force-pushed the uwp-fileutils branch from f0f837b to 190b3f2 Compare July 19, 2026 11:25
@thexai

thexai commented Jul 19, 2026 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor Author

This breaks CI, e.g.

test_1686475 (test.test_os.test_os.StatAttributeTests.test_1686475) ... Windows fatal exception: access violation

Can you reproduce this on a local Windows installation and fix?

Reproduced and now should be fixed in latest PR update. 🙂

It's important to note that some tests fail because they expect specific responses to unusual situations that may not have a single logical outcome. For example:

If a file is inaccessible (due to permissions), the parent directory is read, and if it's no longer available, the original error is not restored (instead of return access violation error, return file no exist error).

    # bpo-46785: the implementation of os.stat() falls back to reading
    # the parent directory if CreateFileW() fails with a permission
    # error. If reading the parent directory fails because the file or
    # directory are subsequently unlinked, or because the volume or
    # share are no longer available, then the original permission error
    # should not be restored.

Also on UWP, due security restrictions (every App runs isolated) is not possible to access to some information in the file system like st_dev (VolumeSerialNumber) or st_ino.

chris-eibl reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

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

@chris-eibl chris-eibl added the sprint label Jul 19, 2026
@github-project-automation github-project-automation Bot added this to Sprint Jul 19, 2026
@github-project-automation github-project-automation Bot moved this to Todo in Sprint Jul 19, 2026
chris-eibl
chris-eibl approved these changes Jul 19, 2026
View reviewed changes

@chris-eibl chris-eibl left a comment

Copy link
Copy Markdown
Member

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.

LGTM, but I'd appreciate a second pair of eyes @python/windows-team.

Sorry, something went wrong.

Uh oh!

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

All reactions
@bedevere-app bedevere-app Bot removed the awaiting review label Jul 19, 2026
@github-project-automation github-project-automation Bot moved this from Todo to In Progress in Sprint Jul 19, 2026
@bedevere-app bedevere-app Bot added the awaiting merge label Jul 19, 2026
zooba
zooba reviewed Jul 20, 2026
View reviewed changes

@zooba zooba left a comment

Copy link
Copy Markdown
Member

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.

Only left two comments, but the guts of it is, I think we can switch to FileStandardInfo for everyone, and that should simplify this change down to basically not needing the separate UWP path at all.

Sorry, something went wrong.

Uh oh!

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

thexai reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
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.

@thexai
Simplification 1
5dabc7c
@thexai

thexai commented Jul 21, 2026 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor Author

Updated PR with one simplification:

UWP not support GetFileInformationByHandle but the struct used to pass info BY_HANDLE_FILE_INFORMATION is still defined and can be used in some places e.g here:

cpython/Modules/posixmodule.c

Lines 2027 to 2043 in 202c4c8

find_data_to_file_info(WIN32_FIND_DATAW *pFileData,
BY_HANDLE_FILE_INFORMATION *info,
ULONG *reparse_tag)
{
memset(info, 0, sizeof(*info));
info->dwFileAttributes = pFileData->dwFileAttributes;
info->ftCreationTime = pFileData->ftCreationTime;
info->ftLastAccessTime = pFileData->ftLastAccessTime;
info->ftLastWriteTime = pFileData->ftLastWriteTime;
info->nFileSizeHigh = pFileData->nFileSizeHigh;
info->nFileSizeLow = pFileData->nFileSizeLow;
/* info->nNumberOfLinks = 1; */
if (pFileData->dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT)
*reparse_tag = pFileData->dwReserved0;
else
*reparse_tag = 0;
}

This allows remove part of UWP only code and some ifdef.

All reactions

Sorry, something went wrong.

Uh oh!

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

thexai added 2 commits July 21, 2026 10:03
@thexai
Full remove of _Py_find_data_to_stat
43d4fc2
@thexai
Simplification 2
003af98
@thexai

thexai commented Jul 21, 2026

Copy link
Copy Markdown
Contributor Author

Simplification 2:

Merges _Py_attribute_data_to_stat and _Py_attribute_data_to_stat_UWP in one.

All reactions

Sorry, something went wrong.

Uh oh!

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

thexai added 4 commits July 21, 2026 11:45
@thexai
Fix typo
a0f6bb7
@thexai
Simplification 3: Remove GetFileInformationByHandle on Desktop
9a694a3
Use same code for UWP and Desktop.
@thexai
Remove unnecessary/accidental changes
b81a7d1
@thexai
Preserve old code format
24a0f47
@thexai

thexai commented Jul 21, 2026

Copy link
Copy Markdown
Contributor Author

I think I've finished this!

Minimal changes and the same common code for UWP and Desktop.

Tests should pass...

chris-eibl reacted with hooray emoji
All reactions
  • 🎉 1 reaction

Sorry, something went wrong.

Uh oh!

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

zooba
zooba reviewed Jul 21, 2026
View reviewed changes

@zooba zooba left a comment

Copy link
Copy Markdown
Member

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.

Apologies for lots of suggestions, but I'm excited about this cleanup! We're so close to really streamlining this code, so it'd be great to go the whole way.

My main target is to fully remove the BY_HANDLE_FILE_INFORMATION usage entirely, and also to minimise the logic in the to_stat function (more overwriting, less checking). The comments I've left should lead you there, but feel free to ignore them if you see another way.

Sorry, something went wrong.

Uh oh!

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

chris-eibl reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
Comment thread Python/fileutils.c Resolved

Uh oh!

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

Comment thread Python/fileutils.c Resolved

Uh oh!

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

Comment thread Python/fileutils.c Resolved

Uh oh!

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

Comment thread Python/fileutils.c Resolved

Uh oh!

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

Comment thread Python/fileutils.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.

thexai added 2 commits July 23, 2026 09:47
@thexai
Use BASIC_INFO and STANDARD_INFO in find_data_to_file_info
4c18091
@thexai
Full remove of BY_HANDLE_FILE_INFORMATION parameter
7221f0c
@thexai

thexai commented Jul 23, 2026

Copy link
Copy Markdown
Contributor Author

Full remove BY_HANDLE_FILE_INFORMATION usage and cleanup done!

chris-eibl reacted with hooray emoji
All reactions
  • 🎉 1 reaction

Sorry, something went wrong.

Uh oh!

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

@thexai
Improve NEWS and cosmetics
9c7338a
zooba
zooba reviewed Jul 23, 2026
View reviewed changes

@zooba zooba left a comment

Copy link
Copy Markdown
Member

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.

Looks great overall, glad we kept going, this is really neat!

Still have a question about guessing at ino values when we don't know them.

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread Python/fileutils.c Outdated
Comment on lines +1128 to +1131
// use these fallback values for systems where it's not possible
// to obtain VolumeSerialNumber / FileId (e.g. Windows UWP)
result->st_dev = 1;
result->st_ino = basic_info->CreationTime.QuadPart;

@zooba zooba Jul 23, 2026

Copy link
Copy Markdown
Member

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.

Do you have a specific scenario for needing these to be non-zero but inaccurate?

They are documented as allowed to be zero if not obtainable (even though it turns out that samestat doesn't check that), but I think the risk of declaring two files to be the same when they aren't is worse than declaring the ino as unknown when it's unknown. So I'd prefer to leave them both at zero if there's no ID info.

Sorry, something went wrong.

Uh oh!

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

All reactions

@thexai thexai Jul 24, 2026

Copy link
Copy Markdown
Contributor 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 don't have a concrete answer right now, I only added it because it was in the old UWP patches... I can remove it for now and add it back later if a specific reason comes up.

Sorry, something went wrong.

Uh oh!

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

zooba reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@thexai
Remove st_dev and st_ino fallback values
e4e4d5d
@zooba
zooba merged commit 0d71cc4 into python:main Jul 24, 2026
53 checks passed

Uh oh!

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

@github-project-automation github-project-automation Bot moved this from In Progress to Done in Sprint Jul 24, 2026
@bedevere-app bedevere-app Bot removed the awaiting merge label Jul 24, 2026
@zooba

zooba commented Jul 24, 2026

Copy link
Copy Markdown
Member

Thanks! I'm really happy with how this one looks

chris-eibl reacted with hooray emoji
All reactions
  • 🎉 1 reaction

Sorry, something went wrong.

Uh oh!

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

@thexai
thexai deleted the uwp-fileutils branch July 24, 2026 10:52
@thexai thexai mentioned this pull request Aug 6, 2026
[Windows] Bump Python to 3.14.7 / Pillow to 12.3.0 / expat to 2.8.2 xbmc/xbmc#28842
Merged
3 of 14 tasks
mbeijen pushed a commit to mbeijen/cpython that referenced this pull request Aug 14, 2026
@thexai @mbeijen
pythongh-152433: Windows: modernize and refactor stat emulation APIs (p…
a55f77a
…ythonGH-153700)

This allows build on more API sets (e.g. UWP) without excluding any currently supported desktop OS.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@zooba zooba zooba left review comments
@chris-eibl chris-eibl chris-eibl approved these changes

Uh oh!

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

Assignees

No one assigned

Labels

sprint

Projects

Sprint
Archived in project

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

@thexai @chris-eibl @zooba
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.