-
Notifications
You must be signed in to change notification settings - Fork 0
/
0004-restore-support-for-windows-7.patch
187 lines (172 loc) · 6.48 KB
/
0004-restore-support-for-windows-7.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
From e30a560527d17ae81685dd11d3268bc982af2048 Mon Sep 17 00:00:00 2001
From: Adam Johnson <[email protected]>
Date: Tue, 16 Feb 2021 18:03:07 -0500
Subject: [PATCH 7/7] restore support for windows 7
this backports the windows 7 compatible fix for bpo-39401 from gh-18234,
originally authored by Steve Dower, and removes explicit dependencies on
pathcch.
The same mechanism is applied to fix posixmodule.c
---
index 25ddc82..ff51042 100644
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -20,7 +20,7 @@
FSCTL_GET_REPARSE_POINT is not exported with WIN32_LEAN_AND_MEAN. */
# include <windows.h>
-# include <pathcch.h>
+# include <Shlwapi.h>
#endif
#ifdef __VXWORKS__
@@ -4410,6 +4410,10 @@ os__getvolumepathname_impl(PyObject *module, path_t *path)
return result;
}
+static int _PathCchSkipRoot_Initialized = 0;
+typedef HRESULT (__stdcall *PPathCchSkipRoot) (PCWSTR pszPath, PCWSTR *ppszRootEnd);
+static PPathCchSkipRoot _PathCchSkipRoot;
+
/*[clinic input]
os._path_splitroot
@@ -4428,6 +4432,19 @@ os__path_splitroot_impl(PyObject *module, path_t *path)
PyObject *result = NULL;
HRESULT ret;
+ if (_PathCchSkipRoot_Initialized == 0) {
+ HMODULE pathapi = LoadLibraryExW(L"api-ms-win-core-path-l1-1-0.dll", NULL,
+ LOAD_LIBRARY_SEARCH_SYSTEM32);
+
+ if (pathapi) {
+ _PathCchSkipRoot = (PPathCchSkipRoot)GetProcAddress(pathapi, "PathCchSkipRoot");
+ } else {
+ _PathCchSkipRoot = NULL;
+ }
+
+ _PathCchSkipRoot_Initialized = 1;
+ }
+
buffer = (wchar_t*)PyMem_Malloc(sizeof(wchar_t) * (wcslen(path->wide) + 1));
if (!buffer) {
return NULL;
@@ -4438,7 +4455,14 @@ os__path_splitroot_impl(PyObject *module, path_t *path)
}
Py_BEGIN_ALLOW_THREADS
- ret = PathCchSkipRoot(buffer, &end);
+ if (_PathCchSkipRoot) {
+ ret = _PathCchSkipRoot(buffer, &end);
+ } else {
+ end = PathSkipRootW(buffer);
+ if (!end) {
+ ret = E_FAIL;
+ }
+ }
Py_END_ALLOW_THREADS
if (FAILED(ret)) {
result = Py_BuildValue("sO", "", path->object);
diff --git a/PC/getpathp.c b/PC/getpathp.c
index 53da3a6..3d58bbf 100644
--- a/PC/getpathp.c
+++ b/PC/getpathp.c
@@ -90,7 +90,7 @@
#endif
#include <windows.h>
-#include <pathcch.h>
+#include <Shlwapi.h>
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
@@ -249,14 +249,43 @@ ismodule(wchar_t *filename, int update_filename)
stuff as fits will be appended.
*/
+
+static int _PathCchCombineEx_Initialized = 0;
+typedef HRESULT(__stdcall *PPathCchCombineEx) (PWSTR pszPathOut, size_t cchPathOut,
+ PCWSTR pszPathIn, PCWSTR pszMore,
+ unsigned long dwFlags);
+static PPathCchCombineEx _PathCchCombineEx;
+
static void
join(wchar_t *buffer, const wchar_t *stuff)
{
- if (FAILED(PathCchCombineEx(buffer, MAXPATHLEN+1, buffer, stuff, 0))) {
- Py_FatalError("buffer overflow in getpathp.c's join()");
+ if (_PathCchCombineEx_Initialized == 0) {
+ HMODULE pathapi = LoadLibraryExW(L"api-ms-win-core-path-l1-1-0.dll", NULL,
+ LOAD_LIBRARY_SEARCH_SYSTEM32);
+ if (pathapi) {
+ _PathCchCombineEx = (PPathCchCombineEx)GetProcAddress(pathapi, "PathCchCombineEx");
+ }
+ else {
+ _PathCchCombineEx = NULL;
+ }
+ _PathCchCombineEx_Initialized = 1;
+ }
+ if (_PathCchCombineEx) {
+ if (FAILED(_PathCchCombineEx(buffer, MAXPATHLEN+1, buffer, stuff, 0))) {
+ Py_FatalError("buffer overflow in getpathp.c's join()");
+ }
+ } else {
+ if (!PathCombineW(buffer, buffer, stuff)) {
+ Py_FatalError("buffer overflow in getpathp.c's join()");
+ }
}
}
+static int _PathCchCanonicalizeEx_Initialized = 0;
+typedef HRESULT(__stdcall *PPathCchCanonicalizeEx) (PWSTR pszPathOut, size_t cchPathOut,
+ PCWSTR pszPathIn, unsigned long dwFlags);
+static PPathCchCanonicalizeEx _PathCchCanonicalizeEx;
+
/* Call PathCchCanonicalizeEx(path): remove navigation elements such as "."
and ".." to produce a direct, well-formed path. */
static PyStatus
@@ -267,8 +296,26 @@ canonicalize(wchar_t *buffer, const wchar_t *path)
return _PyStatus_NO_MEMORY();
}
- if (FAILED(PathCchCanonicalizeEx(buffer, MAXPATHLEN + 1, path, 0))) {
- return INIT_ERR_BUFFER_OVERFLOW();
+ if (_PathCchCanonicalizeEx_Initialized == 0) {
+ HMODULE pathapi = LoadLibraryExW(L"api-ms-win-core-path-l1-1-0.dll", NULL,
+ LOAD_LIBRARY_SEARCH_SYSTEM32);
+ if (pathapi) {
+ _PathCchCanonicalizeEx = (PPathCchCanonicalizeEx)GetProcAddress(pathapi, "PathCchCanonicalizeEx");
+ }
+ else {
+ _PathCchCanonicalizeEx = NULL;
+ }
+ _PathCchCanonicalizeEx_Initialized = 1;
+ }
+ if (_PathCchCanonicalizeEx) {
+ if (FAILED(_PathCchCanonicalizeEx(buffer, MAXPATHLEN + 1, path, 0))) {
+ return INIT_ERR_BUFFER_OVERFLOW();
+ }
+ }
+ else {
+ if (!PathCanonicalizeW(buffer, path)) {
+ return INIT_ERR_BUFFER_OVERFLOW();
+ }
}
return _PyStatus_OK();
}
diff --git a/PC/pyconfig.h b/PC/pyconfig.h
index d7d3cf0..6e9c090 100644
--- a/PC/pyconfig.h
+++ b/PC/pyconfig.h
@@ -136,8 +136,8 @@ WIN32 is still required for the locale module.
/* set the version macros for the windows headers */
/* Python 3.9+ requires Windows 8 or greater */
-#define Py_WINVER 0x0602 /* _WIN32_WINNT_WIN8 */
-#define Py_NTDDI NTDDI_WIN8
+#define Py_WINVER 0x0601 /* _WIN32_WINNT_WIN7 */
+#define Py_NTDDI NTDDI_WIN7
/* We only set these values when building Python - we don't want to force
these values on extensions, as that will affect the prototypes and
diff --git a/PCbuild/pythoncore.vcxproj b/PCbuild/pythoncore.vcxproj
index c39ba3e1a9..0ef3a05fb6 100644
--- a/PCbuild/pythoncore.vcxproj
+++ b/PCbuild/pythoncore.vcxproj
@@ -106,7 +106,7 @@
<PreprocessorDefinitions Condition="$(IncludeExternals)">_Py_HAVE_ZLIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
- <AdditionalDependencies>version.lib;ws2_32.lib;pathcch.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ <AdditionalDependencies>version.lib;ws2_32.lib;shlwapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup>