Skip to content

Commit 3e96f32

Browse files
committed
Issue #23451: Update pyconfig.h for Windows to require Vista headers and remove unnecessary version checks.
1 parent 2f3d440 commit 3e96f32

File tree

6 files changed

+29
-68
lines changed

6 files changed

+29
-68
lines changed

Modules/_winapi.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,6 +1001,12 @@ PyDoc_STRVAR(GetVersion_doc,
10011001
\n\
10021002
Return the version number of the current operating system.");
10031003

1004+
/* Disable deprecation warnings about GetVersionEx as the result is
1005+
being passed straight through to the caller, who is responsible for
1006+
using it correctly. */
1007+
#pragma warning(push)
1008+
#pragma warning(disable:4996)
1009+
10041010
static PyObject *
10051011
winapi_GetVersion(PyObject* self, PyObject* args)
10061012
{
@@ -1010,6 +1016,8 @@ winapi_GetVersion(PyObject* self, PyObject* args)
10101016
return PyLong_FromUnsignedLong(GetVersion());
10111017
}
10121018

1019+
#pragma warning(pop)
1020+
10131021
static PyObject *
10141022
winapi_OpenProcess(PyObject *self, PyObject *args)
10151023
{

Modules/socketmodule.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@
1414

1515
#else /* MS_WINDOWS */
1616
# include <winsock2.h>
17+
/* Windows 'supports' CMSG_LEN, but does not follow the POSIX standard
18+
* interface at all, so there is no point including the code that
19+
* attempts to use it.
20+
*/
21+
# ifdef PySocket_BUILDING_SOCKET
22+
# undef CMSG_LEN
23+
# endif
1724
# include <ws2tcpip.h>
1825
/* VC6 is shipped with old platform headers, and does not have MSTcpIP.h
1926
* Separate SDKs have all the functions we want, but older ones don't have

Objects/unicodeobject.c

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -519,10 +519,6 @@ unicode_result_unchanged(PyObject *unicode)
519519
return _PyUnicode_Copy(unicode);
520520
}
521521

522-
#ifdef HAVE_MBCS
523-
static OSVERSIONINFOEX winver;
524-
#endif
525-
526522
/* --- Bloom Filters ----------------------------------------------------- */
527523

528524
/* stuff to implement simple "bloom filters" for Unicode characters.
@@ -7112,13 +7108,7 @@ static DWORD
71127108
encode_code_page_flags(UINT code_page, const char *errors)
71137109
{
71147110
if (code_page == CP_UTF8) {
7115-
if (winver.dwMajorVersion >= 6)
7116-
/* CP_UTF8 supports WC_ERR_INVALID_CHARS on Windows Vista
7117-
and later */
7118-
return WC_ERR_INVALID_CHARS;
7119-
else
7120-
/* CP_UTF8 only supports flags=0 on Windows older than Vista */
7121-
return 0;
7111+
return WC_ERR_INVALID_CHARS;
71227112
}
71237113
else if (code_page == CP_UTF7) {
71247114
/* CP_UTF7 only supports flags=0 */
@@ -14976,13 +14966,6 @@ int _PyUnicode_Init(void)
1497614966
if (PyType_Ready(&PyFormatterIter_Type) < 0)
1497714967
Py_FatalError("Can't initialize formatter iter type");
1497814968

14979-
#ifdef HAVE_MBCS
14980-
winver.dwOSVersionInfoSize = sizeof(winver);
14981-
if (!GetVersionEx((OSVERSIONINFO*)&winver)) {
14982-
PyErr_SetFromWindowsErr(0);
14983-
return -1;
14984-
}
14985-
#endif
1498614969
return 0;
1498714970
}
1498814971

PC/pyconfig.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,9 @@ WIN32 is still required for the locale module.
156156
#endif /* MS_WIN64 */
157157

158158
/* set the version macros for the windows headers */
159-
/* Python 3.4+ requires Windows XP or greater */
160-
#define Py_WINVER 0x0501 /* _WIN32_WINNT_WINXP */
161-
#define Py_NTDDI NTDDI_WINXP
159+
/* Python 3.5+ requires Windows Vista or greater */
160+
#define Py_WINVER 0x0600 /* _WIN32_WINNT_VISTA */
161+
#define Py_NTDDI NTDDI_VISTA
162162

163163
/* We only set these values when building Python - we don't want to force
164164
these values on extensions, as that will affect the prototypes and

Python/pytime.c

Lines changed: 2 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@
77
#include <mach/mach_time.h> /* mach_absolute_time(), mach_timebase_info() */
88
#endif
99

10-
#ifdef MS_WINDOWS
11-
static OSVERSIONINFOEX winver;
12-
#endif
13-
1410
static int
1511
pygettimeofday(_PyTime_timeval *tp, _Py_clock_info_t *info, int raise)
1612
{
@@ -124,52 +120,19 @@ pymonotonic(_PyTime_timeval *tp, _Py_clock_info_t *info, int raise)
124120
static _PyTime_timeval last = {0, -1};
125121
#endif
126122
#if defined(MS_WINDOWS)
127-
static ULONGLONG (*GetTickCount64) (void) = NULL;
128-
static ULONGLONG (CALLBACK *Py_GetTickCount64)(void);
129-
static int has_gettickcount64 = -1;
130123
ULONGLONG result;
131124

132125
assert(info == NULL || raise);
133126

134-
if (has_gettickcount64 == -1) {
135-
/* GetTickCount64() was added to Windows Vista */
136-
has_gettickcount64 = (winver.dwMajorVersion >= 6);
137-
if (has_gettickcount64) {
138-
HINSTANCE hKernel32;
139-
hKernel32 = GetModuleHandleW(L"KERNEL32");
140-
*(FARPROC*)&Py_GetTickCount64 = GetProcAddress(hKernel32,
141-
"GetTickCount64");
142-
assert(Py_GetTickCount64 != NULL);
143-
}
144-
}
145-
146-
if (has_gettickcount64) {
147-
result = Py_GetTickCount64();
148-
}
149-
else {
150-
static DWORD last_ticks = 0;
151-
static DWORD n_overflow = 0;
152-
DWORD ticks;
153-
154-
ticks = GetTickCount();
155-
if (ticks < last_ticks)
156-
n_overflow++;
157-
last_ticks = ticks;
158-
159-
result = (ULONGLONG)n_overflow << 32;
160-
result += ticks;
161-
}
127+
result = GetTickCount64();
162128

163129
tp->tv_sec = result / 1000;
164130
tp->tv_usec = (result % 1000) * 1000;
165131

166132
if (info) {
167133
DWORD timeAdjustment, timeIncrement;
168134
BOOL isTimeAdjustmentDisabled, ok;
169-
if (has_gettickcount64)
170-
info->implementation = "GetTickCount64()";
171-
else
172-
info->implementation = "GetTickCount()";
135+
info->implementation = "GetTickCount64()";
173136
info->monotonic = 1;
174137
ok = GetSystemTimeAdjustment(&timeAdjustment, &timeIncrement,
175138
&isTimeAdjustmentDisabled);
@@ -409,14 +372,6 @@ _PyTime_Init(void)
409372
{
410373
_PyTime_timeval tv;
411374

412-
#ifdef MS_WINDOWS
413-
winver.dwOSVersionInfoSize = sizeof(winver);
414-
if (!GetVersionEx((OSVERSIONINFO*)&winver)) {
415-
PyErr_SetFromWindowsErr(0);
416-
return -1;
417-
}
418-
#endif
419-
420375
/* ensure that the system clock works */
421376
if (_PyTime_gettimeofday_info(&tv, NULL) < 0)
422377
return -1;

Python/sysmodule.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -772,6 +772,12 @@ static PyStructSequence_Desc windows_version_desc = {
772772
via indexing, the rest are name only */
773773
};
774774

775+
/* Disable deprecation warnings about GetVersionEx as the result is
776+
being passed straight through to the caller, who is responsible for
777+
using it correctly. */
778+
#pragma warning(push)
779+
#pragma warning(disable:4996)
780+
775781
static PyObject *
776782
sys_getwindowsversion(PyObject *self)
777783
{
@@ -803,6 +809,8 @@ sys_getwindowsversion(PyObject *self)
803809
return version;
804810
}
805811

812+
#pragma warning(pop)
813+
806814
#endif /* MS_WINDOWS */
807815

808816
#ifdef HAVE_DLOPEN

0 commit comments

Comments
 (0)