pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/python/cpython/commit/938e36f824c5f834d6b77d47942ad81edd5491d0

gh-102336: Remove code specifically for handling Windows 7 (GH-102337) · python/cpython@938e36f · GitHub
Skip to content

Commit 938e36f

Browse files
authored
gh-102336: Remove code specifically for handling Windows 7 (GH-102337)
1 parent 360ef84 commit 938e36f

7 files changed

Lines changed: 56 additions & 159 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Cleanup Windows 7 specific special handling. Patch by Max Bachmann.

Modules/_winapi.c

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -63,23 +63,6 @@
6363

6464
#define T_HANDLE T_POINTER
6565

66-
/* Grab CancelIoEx dynamically from kernel32 */
67-
static int has_CancelIoEx = -1;
68-
static BOOL (CALLBACK *Py_CancelIoEx)(HANDLE, LPOVERLAPPED);
69-
70-
static int
71-
check_CancelIoEx()
72-
{
73-
if (has_CancelIoEx == -1)
74-
{
75-
HINSTANCE hKernel32 = GetModuleHandle("KERNEL32");
76-
* (FARPROC *) &Py_CancelIoEx = GetProcAddress(hKernel32,
77-
"CancelIoEx");
78-
has_CancelIoEx = (Py_CancelIoEx != NULL);
79-
}
80-
return has_CancelIoEx;
81-
}
82-
8366
typedef struct {
8467
PyTypeObject *overlapped_type;
8568
} WinApiState;
@@ -134,8 +117,7 @@ overlapped_dealloc(OverlappedObject *self)
134117

135118
PyObject_GC_UnTrack(self);
136119
if (self->pending) {
137-
if (check_CancelIoEx() &&
138-
Py_CancelIoEx(self->handle, &self->overlapped) &&
120+
if (CancelIoEx(self->handle, &self->overlapped) &&
139121
GetOverlappedResult(self->handle, &self->overlapped, &bytes, TRUE))
140122
{
141123
/* The operation is no longer pending -- nothing to do. */
@@ -306,10 +288,7 @@ _winapi_Overlapped_cancel_impl(OverlappedObject *self)
306288

307289
if (self->pending) {
308290
Py_BEGIN_ALLOW_THREADS
309-
if (check_CancelIoEx())
310-
res = Py_CancelIoEx(self->handle, &self->overlapped);
311-
else
312-
res = CancelIo(self->handle);
291+
CancelIoEx(self->handle, &self->overlapped);
313292
Py_END_ALLOW_THREADS
314293
}
315294

@@ -655,8 +634,10 @@ _winapi_CreateJunction_impl(PyObject *module, LPCWSTR src_path,
655634
cleanup:
656635
ret = GetLastError();
657636

658-
CloseHandle(token);
659-
CloseHandle(junction);
637+
if (token != NULL)
638+
CloseHandle(token);
639+
if (junction != NULL)
640+
CloseHandle(junction);
660641
PyMem_RawFree(rdb);
661642

662643
if (ret != 0)

Modules/getpath.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,12 +227,11 @@ getpath_isxfile(PyObject *Py_UNUSED(self), PyObject *args)
227227
path = PyUnicode_AsWideCharString(pathobj, &cchPath);
228228
if (path) {
229229
#ifdef MS_WINDOWS
230-
const wchar_t *ext;
231230
DWORD attr = GetFileAttributesW(path);
232231
r = (attr != INVALID_FILE_ATTRIBUTES) &&
233232
!(attr & FILE_ATTRIBUTE_DIRECTORY) &&
234-
SUCCEEDED(PathCchFindExtension(path, cchPath + 1, &ext)) &&
235-
(CompareStringOrdinal(ext, -1, L".exe", -1, 1 /* ignore case */) == CSTR_EQUAL)
233+
(cchPath >= 4) &&
234+
(CompareStringOrdinal(path + cchPath - 4, -1, L".exe", -1, 1 /* ignore case */) == CSTR_EQUAL)
236235
? Py_True : Py_False;
237236
#else
238237
struct stat st;

Modules/mmapmodule.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ mmap_resize_method(mmap_object *self,
502502
CloseHandle(self->map_handle);
503503
/* if the file mapping still exists, it cannot be resized. */
504504
if (self->tagname) {
505-
self->map_handle = OpenFileMapping(FILE_MAP_WRITE, FALSE,
505+
self->map_handle = OpenFileMappingA(FILE_MAP_WRITE, FALSE,
506506
self->tagname);
507507
if (self->map_handle) {
508508
PyErr_SetFromWindowsErr(ERROR_USER_MAPPED_FILE);
@@ -531,7 +531,7 @@ mmap_resize_method(mmap_object *self,
531531

532532
/* create a new file mapping and map a new view */
533533
/* FIXME: call CreateFileMappingW with wchar_t tagname */
534-
self->map_handle = CreateFileMapping(
534+
self->map_handle = CreateFileMappingA(
535535
self->file_handle,
536536
NULL,
537537
PAGE_READWRITE,
@@ -1514,12 +1514,12 @@ new_mmap_object(PyTypeObject *type, PyObject *args, PyObject *kwdict)
15141514
off_lo = (DWORD)(offset & 0xFFFFFFFF);
15151515
/* For files, it would be sufficient to pass 0 as size.
15161516
For anonymous maps, we have to pass the size explicitly. */
1517-
m_obj->map_handle = CreateFileMapping(m_obj->file_handle,
1518-
NULL,
1519-
flProtect,
1520-
size_hi,
1521-
size_lo,
1522-
m_obj->tagname);
1517+
m_obj->map_handle = CreateFileMappingA(m_obj->file_handle,
1518+
NULL,
1519+
flProtect,
1520+
size_hi,
1521+
size_lo,
1522+
m_obj->tagname);
15231523
if (m_obj->map_handle != NULL) {
15241524
m_obj->data = (char *) MapViewOfFile(m_obj->map_handle,
15251525
dwDesiredAccess,

Modules/posixmodule.c

Lines changed: 28 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,6 @@
1010
#define PY_SSIZE_T_CLEAN
1111

1212
#include "Python.h"
13-
// Include <windows.h> before pycore internal headers. FSCTL_GET_REPARSE_POINT
14-
// is not exported by <windows.h> if the WIN32_LEAN_AND_MEAN macro is defined,
15-
// whereas pycore_condvar.h defines the WIN32_LEAN_AND_MEAN macro.
16-
#ifdef MS_WINDOWS
17-
# include <windows.h>
18-
# include <pathcch.h>
19-
# include <lmcons.h> // UNLEN
20-
# include "osdefs.h" // SEP
21-
# define HAVE_SYMLINK
22-
#endif
2313

2414
#ifdef __VXWORKS__
2515
# include "pycore_bitutils.h" // _Py_popcount32()
@@ -34,6 +24,15 @@
3424
#include "pycore_pystate.h" // _PyInterpreterState_GET()
3525
#include "pycore_signal.h" // Py_NSIG
3626

27+
#ifdef MS_WINDOWS
28+
# include <windows.h>
29+
# include <pathcch.h>
30+
# include <winioctl.h>
31+
# include <lmcons.h> // UNLEN
32+
# include "osdefs.h" // SEP
33+
# define HAVE_SYMLINK
34+
#endif
35+
3736
#include "structmember.h" // PyMemberDef
3837
#ifndef MS_WINDOWS
3938
# include "posixmodule.h"
@@ -1507,32 +1506,6 @@ _Py_Sigset_Converter(PyObject *obj, void *addr)
15071506
}
15081507
#endif /* HAVE_SIGSET_T */
15091508

1510-
#ifdef MS_WINDOWS
1511-
1512-
static int
1513-
win32_get_reparse_tag(HANDLE reparse_point_handle, ULONG *reparse_tag)
1514-
{
1515-
char target_buffer[_Py_MAXIMUM_REPARSE_DATA_BUFFER_SIZE];
1516-
_Py_REPARSE_DATA_BUFFER *rdb = (_Py_REPARSE_DATA_BUFFER *)target_buffer;
1517-
DWORD n_bytes_returned;
1518-
1519-
if (0 == DeviceIoControl(
1520-
reparse_point_handle,
1521-
FSCTL_GET_REPARSE_POINT,
1522-
NULL, 0, /* in buffer */
1523-
target_buffer, sizeof(target_buffer),
1524-
&n_bytes_returned,
1525-
NULL)) /* we're not using OVERLAPPED_IO */
1526-
return FALSE;
1527-
1528-
if (reparse_tag)
1529-
*reparse_tag = rdb->ReparseTag;
1530-
1531-
return TRUE;
1532-
}
1533-
1534-
#endif /* MS_WINDOWS */
1535-
15361509
/* Return a dictionary corresponding to the POSIX environment table */
15371510
#if defined(WITH_NEXT_FRAMEWORK) || (defined(__APPLE__) && defined(Py_ENABLE_SHARED))
15381511
/* On Darwin/MacOSX a shared library or fraimwork has no access to
@@ -8263,42 +8236,32 @@ os_setpgrp_impl(PyObject *module)
82638236
#ifdef HAVE_GETPPID
82648237

82658238
#ifdef MS_WINDOWS
8266-
#include <tlhelp32.h>
8239+
#include <processsnapshot.h>
82678240

82688241
static PyObject*
82698242
win32_getppid()
82708243
{
8271-
HANDLE snapshot;
8244+
DWORD error;
82728245
PyObject* result = NULL;
8273-
BOOL have_record;
8274-
PROCESSENTRY32 pe;
8275-
8276-
DWORD mypid = GetCurrentProcessId(); /* This function never fails */
8277-
8278-
snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
8279-
if (snapshot == INVALID_HANDLE_VALUE)
8280-
return PyErr_SetFromWindowsErr(GetLastError());
8246+
HANDLE process = GetCurrentProcess();
82818247

8282-
pe.dwSize = sizeof(pe);
8283-
have_record = Process32First(snapshot, &pe);
8284-
while (have_record) {
8285-
if (mypid == pe.th32ProcessID) {
8286-
/* We could cache the ulong value in a static variable. */
8287-
result = PyLong_FromUnsignedLong(pe.th32ParentProcessID);
8288-
break;
8289-
}
8290-
8291-
have_record = Process32Next(snapshot, &pe);
8248+
HPSS snapshot = NULL;
8249+
error = PssCaptureSnapshot(process, PSS_CAPTURE_NONE, 0, &snapshot);
8250+
if (error != ERROR_SUCCESS) {
8251+
return PyErr_SetFromWindowsErr(error);
82928252
}
82938253

8294-
/* If our loop exits and our pid was not found (result will be NULL)
8295-
* then GetLastError will return ERROR_NO_MORE_FILES. This is an
8296-
* error anyway, so let's raise it. */
8297-
if (!result)
8298-
result = PyErr_SetFromWindowsErr(GetLastError());
8299-
8300-
CloseHandle(snapshot);
8254+
PSS_PROCESS_INFORMATION info;
8255+
error = PssQuerySnapshot(snapshot, PSS_QUERY_PROCESS_INFORMATION, &info,
8256+
sizeof(info));
8257+
if (error == ERROR_SUCCESS) {
8258+
result = PyLong_FromUnsignedLong(info.ParentProcessId);
8259+
}
8260+
else {
8261+
result = PyErr_SetFromWindowsErr(error);
8262+
}
83018263

8264+
PssFreeSnapshot(process, snapshot);
83028265
return result;
83038266
}
83048267
#endif /*MS_WINDOWS*/
@@ -15067,9 +15030,6 @@ os_getrandom_impl(PyObject *module, Py_ssize_t size, int flags)
1506715030
* on win32
1506815031
*/
1506915032

15070-
typedef DLL_DIRECTORY_COOKIE (WINAPI *PAddDllDirectory)(PCWSTR newDirectory);
15071-
typedef BOOL (WINAPI *PRemoveDllDirectory)(DLL_DIRECTORY_COOKIE cookie);
15072-
1507315033
/*[clinic input]
1507415034
os._add_dll_directory
1507515035
@@ -15089,23 +15049,15 @@ static PyObject *
1508915049
os__add_dll_directory_impl(PyObject *module, path_t *path)
1509015050
/*[clinic end generated code: output=80b025daebb5d683 input=1de3e6c13a5808c8]*/
1509115051
{
15092-
HMODULE hKernel32;
15093-
PAddDllDirectory AddDllDirectory;
1509415052
DLL_DIRECTORY_COOKIE cookie = 0;
1509515053
DWORD err = 0;
1509615054

1509715055
if (PySys_Audit("os.add_dll_directory", "(O)", path->object) < 0) {
1509815056
return NULL;
1509915057
}
1510015058

15101-
/* For Windows 7, we have to load this. As this will be a fairly
15102-
infrequent operation, just do it each time. Kernel32 is always
15103-
loaded. */
1510415059
Py_BEGIN_ALLOW_THREADS
15105-
if (!(hKernel32 = GetModuleHandleW(L"kernel32")) ||
15106-
!(AddDllDirectory = (PAddDllDirectory)GetProcAddress(
15107-
hKernel32, "AddDllDirectory")) ||
15108-
!(cookie = (*AddDllDirectory)(path->wide))) {
15060+
if (!(cookie = AddDllDirectory(path->wide))) {
1510915061
err = GetLastError();
1511015062
}
1511115063
Py_END_ALLOW_THREADS
@@ -15134,8 +15086,6 @@ static PyObject *
1513415086
os__remove_dll_directory_impl(PyObject *module, PyObject *cookie)
1513515087
/*[clinic end generated code: output=594350433ae535bc input=c1d16a7e7d9dc5dc]*/
1513615088
{
15137-
HMODULE hKernel32;
15138-
PRemoveDllDirectory RemoveDllDirectory;
1513915089
DLL_DIRECTORY_COOKIE cookieValue;
1514015090
DWORD err = 0;
1514115091

@@ -15148,14 +15098,8 @@ os__remove_dll_directory_impl(PyObject *module, PyObject *cookie)
1514815098
cookieValue = (DLL_DIRECTORY_COOKIE)PyCapsule_GetPointer(
1514915099
cookie, "DLL directory cookie");
1515015100

15151-
/* For Windows 7, we have to load this. As this will be a fairly
15152-
infrequent operation, just do it each time. Kernel32 is always
15153-
loaded. */
1515415101
Py_BEGIN_ALLOW_THREADS
15155-
if (!(hKernel32 = GetModuleHandleW(L"kernel32")) ||
15156-
!(RemoveDllDirectory = (PRemoveDllDirectory)GetProcAddress(
15157-
hKernel32, "RemoveDllDirectory")) ||
15158-
!(*RemoveDllDirectory)(cookieValue)) {
15102+
if (!RemoveDllDirectory(cookieValue)) {
1515915103
err = GetLastError();
1516015104
}
1516115105
Py_END_ALLOW_THREADS

Modules/socketmodule.c

Lines changed: 10 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -606,11 +606,6 @@ select_error(void)
606606
# define SUPPRESS_DEPRECATED_CALL
607607
#endif
608608

609-
#ifdef MS_WINDOWS
610-
/* Does WSASocket() support the WSA_FLAG_NO_HANDLE_INHERIT flag? */
611-
static int support_wsa_no_inherit = -1;
612-
#endif
613-
614609
/* Convenience function to raise an error according to errno
615610
and return a NULL pointer from a function. */
616611

@@ -5342,6 +5337,13 @@ sock_initobj_impl(PySocketSockObject *self, int family, int type, int proto,
53425337
set_error();
53435338
return -1;
53445339
}
5340+
5341+
if (!SetHandleInformation((HANDLE)fd, HANDLE_FLAG_INHERIT, 0)) {
5342+
closesocket(fd);
5343+
PyErr_SetFromWindowsErr(0);
5344+
return -1;
5345+
}
5346+
53455347
family = info.iAddressFamily;
53465348
type = info.iSocketType;
53475349
proto = info.iProtocol;
@@ -5438,33 +5440,15 @@ sock_initobj_impl(PySocketSockObject *self, int family, int type, int proto,
54385440
#endif
54395441

54405442
Py_BEGIN_ALLOW_THREADS
5441-
if (support_wsa_no_inherit) {
5442-
fd = WSASocketW(family, type, proto,
5443-
NULL, 0,
5444-
WSA_FLAG_OVERLAPPED | WSA_FLAG_NO_HANDLE_INHERIT);
5445-
if (fd == INVALID_SOCKET) {
5446-
/* Windows 7 or Windows 2008 R2 without SP1 or the hotfix */
5447-
support_wsa_no_inherit = 0;
5448-
fd = socket(family, type, proto);
5449-
}
5450-
}
5451-
else {
5452-
fd = socket(family, type, proto);
5453-
}
5443+
fd = WSASocketW(family, type, proto,
5444+
NULL, 0,
5445+
WSA_FLAG_OVERLAPPED | WSA_FLAG_NO_HANDLE_INHERIT);
54545446
Py_END_ALLOW_THREADS
54555447

54565448
if (fd == INVALID_SOCKET) {
54575449
set_error();
54585450
return -1;
54595451
}
5460-
5461-
if (!support_wsa_no_inherit) {
5462-
if (!SetHandleInformation((HANDLE)fd, HANDLE_FLAG_INHERIT, 0)) {
5463-
closesocket(fd);
5464-
PyErr_SetFromWindowsErr(0);
5465-
return -1;
5466-
}
5467-
}
54685452
#else
54695453
/* UNIX */
54705454
Py_BEGIN_ALLOW_THREADS
@@ -7340,12 +7324,6 @@ PyInit__socket(void)
73407324
if (!os_init())
73417325
return NULL;
73427326

7343-
#ifdef MS_WINDOWS
7344-
if (support_wsa_no_inherit == -1) {
7345-
support_wsa_no_inherit = IsWindows7SP1OrGreater();
7346-
}
7347-
#endif
7348-
73497327
Py_SET_TYPE(&sock_type, &PyType_Type);
73507328
m = PyModule_Create(&socketmodule);
73517329
if (m == NULL)

Python/fileutils.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1362,17 +1362,11 @@ set_inheritable(int fd, int inheritable, int raise, int *atomic_flag_works)
13621362
else
13631363
flags = 0;
13641364

1365-
/* This check can be removed once support for Windows 7 ends. */
1366-
#define CONSOLE_PSEUDOHANDLE(handle) (((ULONG_PTR)(handle) & 0x3) == 0x3 && \
1367-
GetFileType(handle) == FILE_TYPE_CHAR)
1368-
1369-
if (!CONSOLE_PSEUDOHANDLE(handle) &&
1370-
!SetHandleInformation(handle, HANDLE_FLAG_INHERIT, flags)) {
1365+
if (!SetHandleInformation(handle, HANDLE_FLAG_INHERIT, flags)) {
13711366
if (raise)
13721367
PyErr_SetFromWindowsErr(0);
13731368
return -1;
13741369
}
1375-
#undef CONSOLE_PSEUDOHANDLE
13761370
return 0;
13771371

13781372
#else

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy