Skip to content

Commit 4d8df42

Browse files
committed
gh-152433: Windows: do not use _syscmd_ver() on UWP build
1 parent ad1cea6 commit 4d8df42

3 files changed

Lines changed: 47 additions & 5 deletions

File tree

Lib/platform.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -422,16 +422,21 @@ def _win32_ver(version, csd, ptype):
422422
# Fall back to a combination of sys.getwindowsversion and "ver"
423423
try:
424424
from sys import getwindowsversion
425+
from _winapi import IsWindowsDesktop
425426
except ImportError:
426427
return version, csd, ptype, True
427428

428429
winver = getwindowsversion()
429430
is_client = (getattr(winver, 'product_type', 1) == 1)
430-
try:
431-
version = _syscmd_ver()[2]
432-
major, minor, build = map(int, version.split('.'))
433-
except ValueError:
434-
major, minor, build = winver.platform_version or winver[:3]
431+
if IsWindowsDesktop():
432+
try:
433+
version = _syscmd_ver()[2]
434+
major, minor, build = map(int, version.split('.'))
435+
except ValueError:
436+
major, minor, build = winver.platform_version or winver[:3]
437+
version = '{0}.{1}.{2}'.format(major, minor, build)
438+
else:
439+
major, minor, build = winver[:3]
435440
version = '{0}.{1}.{2}'.format(major, minor, build)
436441

437442
# getwindowsversion() reflect the compatibility mode Python is

Modules/_winapi.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3175,6 +3175,23 @@ _winapi_GetTickCount64_impl(PyObject *module)
31753175
return PyLong_FromUnsignedLongLong(ticks);
31763176
}
31773177

3178+
/*[clinic input]
3179+
_winapi.IsWindowsDesktop
3180+
3181+
Return TRUE if current build is for Windows desktop, otherwise return FALSE (UWP build)
3182+
[clinic start generated code]*/
3183+
3184+
static DWORD
3185+
_winapi_IsWindowsDesktop_impl(PyObject* module)
3186+
/*[clinic end generated code: output=cb33c0568f0b3ed1 input=77ed6539ac7d6590]*/
3187+
{
3188+
#ifdef MS_WINDOWS_DESKTOP
3189+
return TRUE;
3190+
#else
3191+
return FALSE;
3192+
#endif
3193+
}
3194+
31783195

31793196
static PyMethodDef winapi_functions[] = {
31803197
_WINAPI_CLOSEHANDLE_METHODDEF
@@ -3228,6 +3245,7 @@ static PyMethodDef winapi_functions[] = {
32283245
_WINAPI_COPYFILE2_METHODDEF
32293246
_WINAPI_GETPROCESSMEMORYINFO_METHODDEF
32303247
_WINAPI_GETTICKCOUNT64_METHODDEF
3248+
_WINAPI_ISWINDOWSDESKTOP_METHODDEF
32313249
{NULL, NULL}
32323250
};
32333251

Modules/clinic/_winapi.c.h

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)