Skip to content

gh-152433: Windows: Allow build winreg module for UWP - #154918

Open
thexai wants to merge 1 commit into
python:mainfrom
thexai:uwp-winreg
Open

gh-152433: Windows: Allow build winreg module for UWP#154918
thexai wants to merge 1 commit into
python:mainfrom
thexai:uwp-winreg

Conversation

@thexai

@thexai thexai commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

In current code, winreg module is not build because code guards not include MS_WINDOWS_APP.

Instead of add MS_WINDOWS_APP condition, guards removed when is:

#if defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES)

(as includes all Windows families)

Or replaced with MS_WINDOWS when code is for all platforms.

The clinic's code also regenerated, resulting in the removal of many redundant conditions.

Note that Windows Registry is not accessible from UWP Apps (or Games) but for consistency is necessary build module as is imported in many places at Python initialization. The same logic was already being applied with MS_WINDOWS_GAMES build.

@zooba

zooba commented Jul 30, 2026

Copy link
Copy Markdown
Member

Out of interest, what would it look like to make those imports conditional? They ought to be anyway, and I suspect we'll end up with better overall behaviour if they handle this as "no registry access exists" rather than "registry accesses always fail".

@thexai

thexai commented Jul 30, 2026

Copy link
Copy Markdown
Contributor Author

I don't really know how it would be done because it requires modifying a lot of Python code and introduce helper functions or constants to identify UWP / GAMES builds as "another platform". This is beyond the scope of this PR.

In addition to this, I want to avoid modifying the behavior of MS_WINDOWS_GAMES builds because I have no easy way to test it (nor any particular interest).

This PR allows compile the current code for UWP and is actually a simplification because it removes 185 lines of code. Without this PR, the resulting UWP builds won't work because they try to import a module that doesn't exist --> hard crash.

With this PR, you can use the rest of the Python code in UWP, and even if a Python script includes import winreg lines and the the script handles the exceptions, return values, etc. nothing bad happens.

Previously, Windows Registry was available for "Windows Phone" in the MS_WINDOWS_APP partition, and most of the Win32 Registry API is still defined. This is why compile winreg.c code for MS_WINDOWS_APP/GAMES is possible and doesn't produce errors. I'm not actually sure if accessing the Registry outside of classic Desktop environment is still useful on other types of devices (Surface or ARM64 devices).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants