From 58ab04ae46a70d76df207e9840250f64d773d1b3 Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Fri, 24 Feb 2023 15:01:54 +0100 Subject: [PATCH 001/100] better support building on non desktop windows systems --- Modules/_io/fileio.c | 2 ++ Modules/_io/winconsoleio.c | 2 ++ Modules/_localemodule.c | 2 ++ Modules/_multiprocessing/multiprocessing.h | 4 +++- Modules/_pickle.c | 6 ++++++ Modules/errnomodule.c | 2 ++ Modules/posixmodule.c | 24 ++++++++++++---------- Modules/selectmodule.c | 4 +++- Modules/timemodule.c | 4 +++- 9 files changed, 36 insertions(+), 14 deletions(-) diff --git a/Modules/_io/fileio.c b/Modules/_io/fileio.c index f424fb8439d7a8..104ffbe889e584 100644 --- a/Modules/_io/fileio.c +++ b/Modules/_io/fileio.c @@ -37,7 +37,9 @@ #ifdef MS_WINDOWS /* can simulate truncate with Win32 API functions; see file_truncate */ #define HAVE_FTRUNCATE +#ifndef WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN +#endif #include #endif diff --git a/Modules/_io/winconsoleio.c b/Modules/_io/winconsoleio.c index e913d831874617..61c6e184eb3bee 100644 --- a/Modules/_io/winconsoleio.c +++ b/Modules/_io/winconsoleio.c @@ -22,7 +22,9 @@ #endif #include /* For offsetof */ +#ifndef WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN +#endif #include #include diff --git a/Modules/_localemodule.c b/Modules/_localemodule.c index 23c38e14d997d1..b6646a48d30d6f 100644 --- a/Modules/_localemodule.c +++ b/Modules/_localemodule.c @@ -35,7 +35,9 @@ This software comes with no warranty. Use at your own risk. #endif #if defined(MS_WINDOWS) +#ifndef WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN +#endif #include #endif diff --git a/Modules/_multiprocessing/multiprocessing.h b/Modules/_multiprocessing/multiprocessing.h index b595e5a8dd18de..dfc2a8e0799a60 100644 --- a/Modules/_multiprocessing/multiprocessing.h +++ b/Modules/_multiprocessing/multiprocessing.h @@ -12,7 +12,9 @@ */ #ifdef MS_WINDOWS -# define WIN32_LEAN_AND_MEAN +# ifndef WIN32_LEAN_AND_MEAN +# define WIN32_LEAN_AND_MEAN +# endif # include # include # include /* getpid() */ diff --git a/Modules/_pickle.c b/Modules/_pickle.c index 1b34977806b661..a26732af8ba2a1 100644 --- a/Modules/_pickle.c +++ b/Modules/_pickle.c @@ -42,6 +42,12 @@ enum { #define FLOAT FLOAT_ #define INT INT_ #define LONG LONG_ + +/* This can already be defined on Windows to set the character set + the Windows header files treat as default */ +#ifdef UNICODE +#undef UNICODE +#endif #endif /* Pickle opcodes. These must be kept updated with pickle.py. diff --git a/Modules/errnomodule.c b/Modules/errnomodule.c index 4de4144520aa48..df4e494ba8a973 100644 --- a/Modules/errnomodule.c +++ b/Modules/errnomodule.c @@ -5,7 +5,9 @@ /* Windows socket errors (WSA*) */ #ifdef MS_WINDOWS +#ifndef WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN +#endif #include /* The following constants were added to errno.h in VS2010 but have preferred WSA equivalents. */ diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 51aa89ef715a19..b8ce99e115dd21 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -18,7 +18,9 @@ # include # include // UNLEN # include "osdefs.h" // SEP -# define HAVE_SYMLINK +# ifndef MS_WINDOWS_NON_DESKTOP +# define HAVE_SYMLINK +# endif #endif #ifdef __VXWORKS__ @@ -312,7 +314,7 @@ corresponding Unix manual entries for more information on calls."); # include #endif -#if defined(MS_WINDOWS) +#if defined(MS_WINDOWS) && !defined(MS_WINDOWS_NON_DESKTOP) # define TERMSIZE_USE_CONIO #elif defined(HAVE_SYS_IOCTL_H) # include @@ -330,21 +332,21 @@ corresponding Unix manual entries for more information on calls."); # define HAVE_OPENDIR 1 # define HAVE_SYSTEM 1 # include -#else -# ifdef _MSC_VER - /* Microsoft compiler */ +#elif defined( _MSC_VER) + /* Microsoft compiler */ +# ifndef MS_WINDOWS_NON_DESKTOP # define HAVE_GETPPID 1 # define HAVE_GETLOGIN 1 # define HAVE_SPAWNV 1 # define HAVE_EXECV 1 # define HAVE_WSPAWNV 1 # define HAVE_WEXECV 1 -# define HAVE_PIPE 1 # define HAVE_SYSTEM 1 # define HAVE_CWAIT 1 -# define HAVE_FSYNC 1 -# define fsync _commit -# endif /* _MSC_VER */ +# endif /* !MS_WINDOWS_NON_DESKTOP */ +# define HAVE_PIPE 1 +# define HAVE_FSYNC 1 +# define fsync _commit #endif /* ! __WATCOMC__ || __QNX__ */ /*[clinic input] @@ -8385,9 +8387,9 @@ os_getuid_impl(PyObject *module) #endif /* HAVE_GETUID */ -#ifdef MS_WINDOWS +#if defined(MS_WINDOWS) && !defined(MS_WINDOWS_NON_DESKTOP) #define HAVE_KILL -#endif /* MS_WINDOWS */ +#endif /* MS_WINDOWS && !MS_WINDOWS_NON_DESKTOP */ #ifdef HAVE_KILL /*[clinic input] diff --git a/Modules/selectmodule.c b/Modules/selectmodule.c index df4043de08dacc..4de33ad97c5dbb 100644 --- a/Modules/selectmodule.c +++ b/Modules/selectmodule.c @@ -57,7 +57,9 @@ extern void bzero(void *, int); #endif #ifdef MS_WINDOWS -# define WIN32_LEAN_AND_MEAN +# ifndef WIN32_LEAN_AND_MEAN +# define WIN32_LEAN_AND_MEAN +# endif # include #else # define SOCKET int diff --git a/Modules/timemodule.c b/Modules/timemodule.c index c2bacaae0c0339..71c5ebd6504367 100644 --- a/Modules/timemodule.c +++ b/Modules/timemodule.c @@ -30,7 +30,9 @@ # include #else # ifdef MS_WINDOWS -# define WIN32_LEAN_AND_MEAN +# ifndef WIN32_LEAN_AND_MEAN +# define WIN32_LEAN_AND_MEAN +# endif # include # endif /* MS_WINDOWS */ #endif /* !__WATCOMC__ || __QNX__ */ From 66a68bdeabcbd700cb859d5a1943f774e28a5a65 Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Sat, 25 Feb 2023 19:57:05 +0100 Subject: [PATCH 002/100] stub posix apis --- Modules/_localemodule.c | 6 +++--- Modules/_posixsubprocess.c | 6 ++++++ Modules/_randommodule.c | 4 ++++ Modules/getpath.c | 4 ++++ Modules/mmapmodule.c | 21 +++++++++++++-------- Modules/posixmodule.c | 8 +++++++- Objects/fileobject.c | 6 ++++++ Objects/object.c | 5 +++++ Objects/obmalloc.c | 4 ++++ Parser/myreadline.c | 6 ++++++ Parser/tokenizer.c | 7 +++++++ Python/bltinmodule.c | 6 ++++++ Python/fileutils.c | 11 +++++++++++ Python/initconfig.c | 3 +++ Python/marshal.c | 5 +++++ Python/pylifecycle.c | 6 ++++++ Python/sysmodule.c | 4 ++++ Python/traceback.c | 5 +++++ 18 files changed, 105 insertions(+), 12 deletions(-) diff --git a/Modules/_localemodule.c b/Modules/_localemodule.c index b6646a48d30d6f..96675cdfb661ad 100644 --- a/Modules/_localemodule.c +++ b/Modules/_localemodule.c @@ -459,12 +459,12 @@ _locale__getdefaultlocale_impl(PyObject *module) PyOS_snprintf(encoding, sizeof(encoding), "cp%u", GetACP()); - if (GetLocaleInfo(LOCALE_USER_DEFAULT, + if (GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_SISO639LANGNAME, locale, sizeof(locale))) { Py_ssize_t i = strlen(locale); locale[i++] = '_'; - if (GetLocaleInfo(LOCALE_USER_DEFAULT, + if (GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_SISO3166CTRYNAME, locale+i, (int)(sizeof(locale)-i))) return Py_BuildValue("ss", locale, encoding); @@ -476,7 +476,7 @@ _locale__getdefaultlocale_impl(PyObject *module) locale[0] = '0'; locale[1] = 'x'; - if (GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_IDEFAULTLANGUAGE, + if (GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_IDEFAULTLANGUAGE, locale+2, sizeof(locale)-2)) { return Py_BuildValue("ss", locale, encoding); } diff --git a/Modules/_posixsubprocess.c b/Modules/_posixsubprocess.c index f3ff39215eab76..be18809d069343 100644 --- a/Modules/_posixsubprocess.c +++ b/Modules/_posixsubprocess.c @@ -59,6 +59,12 @@ # endif #endif +/* the deprecated posix apis are not available on xbox */ +#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY != WINAPI_FAMILY_DESKTOP_GAMES) +# define dup _dup +# define dup2 _dup2 +#endif + #if defined(__FreeBSD__) || (defined(__APPLE__) && defined(__MACH__)) || defined(__DragonFly__) # define FD_DIR "/dev/fd" #else diff --git a/Modules/_randommodule.c b/Modules/_randommodule.c index 68060c07033d34..09e445a4b0f8d5 100644 --- a/Modules/_randommodule.c +++ b/Modules/_randommodule.c @@ -77,6 +77,10 @@ # include // getpid() #endif +#ifdef MS_WINDOWS_NON_DESKTOP +# include +#endif + /* Period parameters -- These are all magic. Don't change. */ #define N 624 #define M 397 diff --git a/Modules/getpath.c b/Modules/getpath.c index 13db010649fed8..8a01a03a34e70b 100644 --- a/Modules/getpath.c +++ b/Modules/getpath.c @@ -12,6 +12,10 @@ #ifdef MS_WINDOWS # include // GetFullPathNameW(), MAX_PATH # include + +# if defined(WINAPI_FAMILY) && (WINAPI_FAMILY != WINAPI_FAMILY_DESKTOP_GAMES) +# define wcsicmp _wcsicmp +# endif #endif #ifdef __APPLE__ diff --git a/Modules/mmapmodule.c b/Modules/mmapmodule.c index a01e798265c5a5..0d2c93c3c3da51 100644 --- a/Modules/mmapmodule.c +++ b/Modules/mmapmodule.c @@ -36,6 +36,11 @@ # endif /* HAVE_FCNTL_H */ #endif +/* the deprecated posix apis are not available on xbox */ +#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY != WINAPI_FAMILY_DESKTOP_GAMES) +# define lseek _lseek +#endif + #ifdef MS_WINDOWS #include static int @@ -502,7 +507,7 @@ mmap_resize_method(mmap_object *self, CloseHandle(self->map_handle); /* if the file mapping still exists, it cannot be resized. */ if (self->tagname) { - self->map_handle = OpenFileMapping(FILE_MAP_WRITE, FALSE, + self->map_handle = OpenFileMappingA(FILE_MAP_WRITE, FALSE, self->tagname); if (self->map_handle) { PyErr_SetFromWindowsErr(ERROR_USER_MAPPED_FILE); @@ -531,7 +536,7 @@ mmap_resize_method(mmap_object *self, /* create a new file mapping and map a new view */ /* FIXME: call CreateFileMappingW with wchar_t tagname */ - self->map_handle = CreateFileMapping( + self->map_handle = CreateFileMappingA( self->file_handle, NULL, PAGE_READWRITE, @@ -1514,12 +1519,12 @@ new_mmap_object(PyTypeObject *type, PyObject *args, PyObject *kwdict) off_lo = (DWORD)(offset & 0xFFFFFFFF); /* For files, it would be sufficient to pass 0 as size. For anonymous maps, we have to pass the size explicitly. */ - m_obj->map_handle = CreateFileMapping(m_obj->file_handle, - NULL, - flProtect, - size_hi, - size_lo, - m_obj->tagname); + m_obj->map_handle = CreateFileMappingA(m_obj->file_handle, + NULL, + flProtect, + size_hi, + size_lo, + m_obj->tagname); if (m_obj->map_handle != NULL) { m_obj->data = (char *) MapViewOfFile(m_obj->map_handle, dwDesiredAccess, diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index b8ce99e115dd21..718ae7409acade 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -324,7 +324,7 @@ corresponding Unix manual entries for more information on calls."); # if defined(TIOCGWINSZ) # define TERMSIZE_USE_IOCTL # endif -#endif /* MS_WINDOWS */ +#endif /* MS_WINDOWS && !MS_WINDOWS_NON_DESKTOP */ /* Various compilers have only certain posix functions */ /* XXX Gosh I wish these were all moved into pyconfig.h */ @@ -347,6 +347,12 @@ corresponding Unix manual entries for more information on calls."); # define HAVE_PIPE 1 # define HAVE_FSYNC 1 # define fsync _commit +# if defined(WINAPI_FAMILY) && (WINAPI_FAMILY != WINAPI_FAMILY_DESKTOP_GAMES) +# define dup2 _dup2 +# define umask _umask +# define close _close +# define isatty _isatty +# endif #endif /* ! __WATCOMC__ || __QNX__ */ /*[clinic input] diff --git a/Objects/fileobject.c b/Objects/fileobject.c index e99e155f2b8c98..9deaf343005c8d 100644 --- a/Objects/fileobject.c +++ b/Objects/fileobject.c @@ -5,6 +5,12 @@ #include "pycore_call.h" // _PyObject_CallNoArgs() #include "pycore_runtime.h" // _PyRuntime +/* the deprecated posix apis are not available on xbox */ +#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY != WINAPI_FAMILY_DESKTOP_GAMES) +# define isatty _isatty +# define fileno _fileno +#endif + #if defined(HAVE_GETC_UNLOCKED) && !defined(_Py_MEMORY_SANITIZER) /* clang MemorySanitizer doesn't yet understand getc_unlocked. */ #define GETC(f) getc_unlocked(f) diff --git a/Objects/object.c b/Objects/object.c index 446c7b1f5f0302..e1fba88f3ec7f9 100644 --- a/Objects/object.c +++ b/Objects/object.c @@ -22,6 +22,11 @@ # error "Py_LIMITED_API macro must not be defined" #endif +/* the deprecated posix apis are not available on xbox */ +#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY != WINAPI_FAMILY_DESKTOP_GAMES) +# define fileno _fileno +#endif + #ifdef __cplusplus extern "C" { #endif diff --git a/Objects/obmalloc.c b/Objects/obmalloc.c index 276c5a276c06e6..43e14a8548563c 100644 --- a/Objects/obmalloc.c +++ b/Objects/obmalloc.c @@ -8,6 +8,10 @@ #include // malloc() #include +/* the deprecated posix apis are not available on xbox */ +#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY != WINAPI_FAMILY_DESKTOP_GAMES) +# define fileno _fileno +#endif #undef uint #define uint pymem_uint diff --git a/Parser/myreadline.c b/Parser/myreadline.c index d55fcefbb6f206..c2b5c0cd42c376 100644 --- a/Parser/myreadline.c +++ b/Parser/myreadline.c @@ -13,8 +13,14 @@ #include "pycore_fileutils.h" // _Py_BEGIN_SUPPRESS_IPH #include "pycore_pystate.h" // _PyThreadState_GET() #ifdef MS_WINDOWS +# ifndef WIN32_LEAN_AND_MEAN # define WIN32_LEAN_AND_MEAN +# endif # include "windows.h" +# if defined(WINAPI_FAMILY) && (WINAPI_FAMILY != WINAPI_FAMILY_DESKTOP_GAMES) +# define isatty _isatty +# define fileno _fileno +# endif #endif /* MS_WINDOWS */ diff --git a/Parser/tokenizer.c b/Parser/tokenizer.c index 463c0e00ca1411..fc22fb97e47b61 100644 --- a/Parser/tokenizer.c +++ b/Parser/tokenizer.c @@ -16,6 +16,13 @@ #include "fileobject.h" #include "abstract.h" +/* the deprecated posix apis are not available on xbox */ +#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY != WINAPI_FAMILY_DESKTOP_GAMES) +# define fdopen _fdopen +# define lseek _lseek +# define fileno _fileno +#endif + /* Alternate tab spacing */ #define ALTTABSIZE 1 diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index 53439ab16040c4..6561b1bd11e097 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -13,6 +13,12 @@ #include "clinic/bltinmodule.c.h" +/* the deprecated posix apis are not available on xbox */ +#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY != WINAPI_FAMILY_DESKTOP_GAMES) +# define isatty _isatty +# define fileno _fileno +#endif + static PyObject* update_bases(PyObject *bases, PyObject *const *args, Py_ssize_t nargs) { diff --git a/Python/fileutils.c b/Python/fileutils.c index 897c2f9f4ea160..4c7b5a2b2d69b3 100644 --- a/Python/fileutils.c +++ b/Python/fileutils.c @@ -40,6 +40,17 @@ extern int winerror_to_errno(int); int _Py_open_cloexec_works = -1; #endif +/* the deprecated posix apis are not available on xbox */ +#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY != WINAPI_FAMILY_DESKTOP_GAMES) +# define dup _dup +# define open _open +# define read _read +# define write _write +# define isatty _isatty +# define close _close +# define fileno _fileno +#endif + // The value must be the same in unicodeobject.c. #define MAX_UNICODE 0x10ffff diff --git a/Python/initconfig.c b/Python/initconfig.c index deec805a6b1ca4..2f949f8a1a20ea 100644 --- a/Python/initconfig.c +++ b/Python/initconfig.c @@ -21,6 +21,9 @@ # ifdef HAVE_FCNTL_H # include // O_BINARY # endif +# if defined(WINAPI_FAMILY) && (WINAPI_FAMILY != WINAPI_FAMILY_DESKTOP_GAMES) +# define fileno _fileno +# endif #endif /* --- Command line options --------------------------------------- */ diff --git a/Python/marshal.c b/Python/marshal.c index 94e79d4392ae6d..bf44e2d534e7cc 100644 --- a/Python/marshal.c +++ b/Python/marshal.c @@ -14,6 +14,11 @@ #include "pycore_hashtable.h" // _Py_hashtable_t #include "marshal.h" // Py_MARSHAL_VERSION +/* the deprecated posix apis are not available on xbox */ +#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY != WINAPI_FAMILY_DESKTOP_GAMES) +# define fileno _fileno +#endif + /*[clinic input] module marshal [clinic start generated code]*/ diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index e80dd30c89dfd0..81b5356664817e 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -56,6 +56,12 @@ extern void _PyIO_Fini(void); # undef BYTE #endif +/* the deprecated posix apis are not available on xbox */ +#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY != WINAPI_FAMILY_DESKTOP_GAMES) +# define isatty _isatty +# define fileno _fileno +#endif + #define PUTS(fd, str) _Py_write_noraise(fd, str, (int)strlen(str)) diff --git a/Python/sysmodule.c b/Python/sysmodule.c index b69b803560924c..8fb2573c7734aa 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -40,6 +40,10 @@ Data members: #ifdef MS_WINDOWS #define WIN32_LEAN_AND_MEAN #include +/* the deprecated posix apis are not available on xbox */ +#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY != WINAPI_FAMILY_DESKTOP_GAMES) +# define fileno _fileno +#endif #endif /* MS_WINDOWS */ #ifdef MS_COREDLL diff --git a/Python/traceback.c b/Python/traceback.c index 31b85e77575efa..d29cda78cefb64 100644 --- a/Python/traceback.c +++ b/Python/traceback.c @@ -23,6 +23,11 @@ # include #endif +/* the deprecated posix apis are not available on xbox */ +#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY != WINAPI_FAMILY_DESKTOP_GAMES) +# define lseek _lseek +#endif + #define OFF(x) offsetof(PyTracebackObject, x) #define PUTS(fd, str) _Py_write_noraise(fd, str, (int)strlen(str)) From 26f5a443cb3afa999c0f7709c1f8a4cb9d10d1e4 Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Sat, 25 Feb 2023 21:57:32 +0100 Subject: [PATCH 003/100] add basic isabs implementation --- Modules/posixmodule.c | 9 +++++++++ Python/fileutils.c | 7 ++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 718ae7409acade..50b496f72a26b7 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -4479,9 +4479,18 @@ os__path_splitroot_impl(PyObject *module, path_t *path) *p = L'\\'; } +#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY != WINAPI_FAMILY_DESKTOP_GAMES) + /* this does not handle persistent local storage */ + ret = E_FAIL; + if ((wcsncmp(buffer, L"G:\\", 3) != 0) && (wcsncmp(buffer, L"D:\\", 3) != 0) && (wcsncmp(buffer, L"T:\\", 3) != 0)) { + end = buffer + 3; + ret = S_OK; + } +#else Py_BEGIN_ALLOW_THREADS ret = PathCchSkipRoot(buffer, &end); Py_END_ALLOW_THREADS +#endif if (FAILED(ret)) { result = Py_BuildValue("sO", "", path->object); } else if (end != buffer) { diff --git a/Python/fileutils.c b/Python/fileutils.c index 4c7b5a2b2d69b3..e4035e67624413 100644 --- a/Python/fileutils.c +++ b/Python/fileutils.c @@ -2030,7 +2030,12 @@ _Py_wrealpath(const wchar_t *path, int _Py_isabs(const wchar_t *path) { -#ifdef MS_WINDOWS +#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY != WINAPI_FAMILY_DESKTOP_GAMES) + /* this does not handle persistent local storage */ + return (wcsncmp(path, L"G:\\", 3) == 0) + || (wcsncmp(path, L"D:\\", 3) == 0) + || (wcsncmp(path, L"T:\\", 3) == 0); +#elif defined(MS_WINDOWS) const wchar_t *tail; HRESULT hr = PathCchSkipRoot(path, &tail); if (FAILED(hr) || path == tail) { From 68a1f67bda085e3eafdb1d5e4919931f3dc87315 Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Sat, 25 Feb 2023 22:45:21 +0100 Subject: [PATCH 004/100] implement isxfile --- Modules/getpath.c | 7 +++++++ Modules/posixmodule.c | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Modules/getpath.c b/Modules/getpath.c index 8a01a03a34e70b..7166ab4b92666f 100644 --- a/Modules/getpath.c +++ b/Modules/getpath.c @@ -232,10 +232,17 @@ getpath_isxfile(PyObject *Py_UNUSED(self), PyObject *args) if (path) { #ifdef MS_WINDOWS const wchar_t *ext; +#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY != WINAPI_FAMILY_DESKTOP_GAMES) + ext = (cchPath >= 4) ? path + cchPath - 4 : NULL; +#endif DWORD attr = GetFileAttributesW(path); r = (attr != INVALID_FILE_ATTRIBUTES) && !(attr & FILE_ATTRIBUTE_DIRECTORY) && +#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY != WINAPI_FAMILY_DESKTOP_GAMES) + (ext != NULL) && +#else SUCCEEDED(PathCchFindExtension(path, cchPath + 1, &ext)) && +#endif (CompareStringOrdinal(ext, -1, L".exe", -1, 1 /* ignore case */) == CSTR_EQUAL) ? Py_True : Py_False; #else diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 50b496f72a26b7..0807df0209735c 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -4482,7 +4482,7 @@ os__path_splitroot_impl(PyObject *module, path_t *path) #if defined(WINAPI_FAMILY) && (WINAPI_FAMILY != WINAPI_FAMILY_DESKTOP_GAMES) /* this does not handle persistent local storage */ ret = E_FAIL; - if ((wcsncmp(buffer, L"G:\\", 3) != 0) && (wcsncmp(buffer, L"D:\\", 3) != 0) && (wcsncmp(buffer, L"T:\\", 3) != 0)) { + if ((wcsncmp(buffer, L"G:\\", 3) == 0) || (wcsncmp(buffer, L"D:\\", 3) == 0) || (wcsncmp(buffer, L"T:\\", 3) == 0)) { end = buffer + 3; ret = S_OK; } From 492bac0be3189e086a026eea118e442b4bde5d1e Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Sat, 25 Feb 2023 23:02:59 +0100 Subject: [PATCH 005/100] fix static linking --- Modules/getpath.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Modules/getpath.c b/Modules/getpath.c index 7166ab4b92666f..ef653e9c076c6e 100644 --- a/Modules/getpath.c +++ b/Modules/getpath.c @@ -757,10 +757,12 @@ static int library_to_dict(PyObject *dict, const char *key) { #ifdef MS_WINDOWS +#ifdef Py_ENABLE_SHARED extern HMODULE PyWin_DLLhModule; if (PyWin_DLLhModule) { return winmodule_to_dict(dict, key, PyWin_DLLhModule); } +#endif #elif defined(WITH_NEXT_FRAMEWORK) static char modPath[MAXPATHLEN + 1]; static int modPathInitialized = -1; From 26b4b24012b6879d828c3ffab07bf6b67b5dfd58 Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Sat, 25 Feb 2023 23:23:17 +0100 Subject: [PATCH 006/100] fix guards --- Modules/_posixsubprocess.c | 2 +- Modules/getpath.c | 6 +++--- Modules/mmapmodule.c | 2 +- Modules/posixmodule.c | 4 ++-- Objects/fileobject.c | 2 +- Objects/object.c | 2 +- Objects/obmalloc.c | 2 +- Parser/myreadline.c | 2 +- Parser/tokenizer.c | 2 +- Python/bltinmodule.c | 2 +- Python/fileutils.c | 4 ++-- Python/initconfig.c | 2 +- Python/marshal.c | 2 +- Python/pylifecycle.c | 2 +- Python/sysmodule.c | 2 +- Python/traceback.c | 2 +- 16 files changed, 20 insertions(+), 20 deletions(-) diff --git a/Modules/_posixsubprocess.c b/Modules/_posixsubprocess.c index be18809d069343..99903247fb3d02 100644 --- a/Modules/_posixsubprocess.c +++ b/Modules/_posixsubprocess.c @@ -60,7 +60,7 @@ #endif /* the deprecated posix apis are not available on xbox */ -#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY != WINAPI_FAMILY_DESKTOP_GAMES) +#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_GAMES) # define dup _dup # define dup2 _dup2 #endif diff --git a/Modules/getpath.c b/Modules/getpath.c index ef653e9c076c6e..c3bdd15beeb493 100644 --- a/Modules/getpath.c +++ b/Modules/getpath.c @@ -13,7 +13,7 @@ # include // GetFullPathNameW(), MAX_PATH # include -# if defined(WINAPI_FAMILY) && (WINAPI_FAMILY != WINAPI_FAMILY_DESKTOP_GAMES) +# if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_GAMES) # define wcsicmp _wcsicmp # endif #endif @@ -232,13 +232,13 @@ getpath_isxfile(PyObject *Py_UNUSED(self), PyObject *args) if (path) { #ifdef MS_WINDOWS const wchar_t *ext; -#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY != WINAPI_FAMILY_DESKTOP_GAMES) +#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_GAMES) ext = (cchPath >= 4) ? path + cchPath - 4 : NULL; #endif DWORD attr = GetFileAttributesW(path); r = (attr != INVALID_FILE_ATTRIBUTES) && !(attr & FILE_ATTRIBUTE_DIRECTORY) && -#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY != WINAPI_FAMILY_DESKTOP_GAMES) +#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_GAMES) (ext != NULL) && #else SUCCEEDED(PathCchFindExtension(path, cchPath + 1, &ext)) && diff --git a/Modules/mmapmodule.c b/Modules/mmapmodule.c index 0d2c93c3c3da51..fb7ddbb403496b 100644 --- a/Modules/mmapmodule.c +++ b/Modules/mmapmodule.c @@ -37,7 +37,7 @@ #endif /* the deprecated posix apis are not available on xbox */ -#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY != WINAPI_FAMILY_DESKTOP_GAMES) +#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_GAMES) # define lseek _lseek #endif diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 0807df0209735c..1cf7a075b2c159 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -347,7 +347,7 @@ corresponding Unix manual entries for more information on calls."); # define HAVE_PIPE 1 # define HAVE_FSYNC 1 # define fsync _commit -# if defined(WINAPI_FAMILY) && (WINAPI_FAMILY != WINAPI_FAMILY_DESKTOP_GAMES) +# if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_GAMES) # define dup2 _dup2 # define umask _umask # define close _close @@ -4479,7 +4479,7 @@ os__path_splitroot_impl(PyObject *module, path_t *path) *p = L'\\'; } -#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY != WINAPI_FAMILY_DESKTOP_GAMES) +#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_GAMES) /* this does not handle persistent local storage */ ret = E_FAIL; if ((wcsncmp(buffer, L"G:\\", 3) == 0) || (wcsncmp(buffer, L"D:\\", 3) == 0) || (wcsncmp(buffer, L"T:\\", 3) == 0)) { diff --git a/Objects/fileobject.c b/Objects/fileobject.c index 9deaf343005c8d..a6928c6d6c2296 100644 --- a/Objects/fileobject.c +++ b/Objects/fileobject.c @@ -6,7 +6,7 @@ #include "pycore_runtime.h" // _PyRuntime /* the deprecated posix apis are not available on xbox */ -#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY != WINAPI_FAMILY_DESKTOP_GAMES) +#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_GAMES) # define isatty _isatty # define fileno _fileno #endif diff --git a/Objects/object.c b/Objects/object.c index e1fba88f3ec7f9..ee1c40e446e9de 100644 --- a/Objects/object.c +++ b/Objects/object.c @@ -23,7 +23,7 @@ #endif /* the deprecated posix apis are not available on xbox */ -#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY != WINAPI_FAMILY_DESKTOP_GAMES) +#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_GAMES) # define fileno _fileno #endif diff --git a/Objects/obmalloc.c b/Objects/obmalloc.c index 43e14a8548563c..97e3174e5d5a3c 100644 --- a/Objects/obmalloc.c +++ b/Objects/obmalloc.c @@ -9,7 +9,7 @@ #include /* the deprecated posix apis are not available on xbox */ -#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY != WINAPI_FAMILY_DESKTOP_GAMES) +#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_GAMES) # define fileno _fileno #endif diff --git a/Parser/myreadline.c b/Parser/myreadline.c index c2b5c0cd42c376..5a6e5dfa595c47 100644 --- a/Parser/myreadline.c +++ b/Parser/myreadline.c @@ -17,7 +17,7 @@ # define WIN32_LEAN_AND_MEAN # endif # include "windows.h" -# if defined(WINAPI_FAMILY) && (WINAPI_FAMILY != WINAPI_FAMILY_DESKTOP_GAMES) +# if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_GAMES) # define isatty _isatty # define fileno _fileno # endif diff --git a/Parser/tokenizer.c b/Parser/tokenizer.c index fc22fb97e47b61..f8587bd34da62a 100644 --- a/Parser/tokenizer.c +++ b/Parser/tokenizer.c @@ -17,7 +17,7 @@ #include "abstract.h" /* the deprecated posix apis are not available on xbox */ -#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY != WINAPI_FAMILY_DESKTOP_GAMES) +#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_GAMES) # define fdopen _fdopen # define lseek _lseek # define fileno _fileno diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index 6561b1bd11e097..3662cfde6a2ba6 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -14,7 +14,7 @@ #include "clinic/bltinmodule.c.h" /* the deprecated posix apis are not available on xbox */ -#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY != WINAPI_FAMILY_DESKTOP_GAMES) +#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_GAMES) # define isatty _isatty # define fileno _fileno #endif diff --git a/Python/fileutils.c b/Python/fileutils.c index e4035e67624413..520dba941f34c0 100644 --- a/Python/fileutils.c +++ b/Python/fileutils.c @@ -41,7 +41,7 @@ int _Py_open_cloexec_works = -1; #endif /* the deprecated posix apis are not available on xbox */ -#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY != WINAPI_FAMILY_DESKTOP_GAMES) +#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_GAMES) # define dup _dup # define open _open # define read _read @@ -2030,7 +2030,7 @@ _Py_wrealpath(const wchar_t *path, int _Py_isabs(const wchar_t *path) { -#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY != WINAPI_FAMILY_DESKTOP_GAMES) +#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_GAMES) /* this does not handle persistent local storage */ return (wcsncmp(path, L"G:\\", 3) == 0) || (wcsncmp(path, L"D:\\", 3) == 0) diff --git a/Python/initconfig.c b/Python/initconfig.c index 2f949f8a1a20ea..be8d8a54ca9a8e 100644 --- a/Python/initconfig.c +++ b/Python/initconfig.c @@ -21,7 +21,7 @@ # ifdef HAVE_FCNTL_H # include // O_BINARY # endif -# if defined(WINAPI_FAMILY) && (WINAPI_FAMILY != WINAPI_FAMILY_DESKTOP_GAMES) +# if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_GAMES) # define fileno _fileno # endif #endif diff --git a/Python/marshal.c b/Python/marshal.c index bf44e2d534e7cc..1eb6c2a6b86d94 100644 --- a/Python/marshal.c +++ b/Python/marshal.c @@ -15,7 +15,7 @@ #include "marshal.h" // Py_MARSHAL_VERSION /* the deprecated posix apis are not available on xbox */ -#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY != WINAPI_FAMILY_DESKTOP_GAMES) +#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_GAMES) # define fileno _fileno #endif diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index 81b5356664817e..68985339ee1bf0 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -57,7 +57,7 @@ extern void _PyIO_Fini(void); #endif /* the deprecated posix apis are not available on xbox */ -#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY != WINAPI_FAMILY_DESKTOP_GAMES) +#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_GAMES) # define isatty _isatty # define fileno _fileno #endif diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 8fb2573c7734aa..f62606ece2dbb7 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -41,7 +41,7 @@ Data members: #define WIN32_LEAN_AND_MEAN #include /* the deprecated posix apis are not available on xbox */ -#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY != WINAPI_FAMILY_DESKTOP_GAMES) +#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_GAMES) # define fileno _fileno #endif #endif /* MS_WINDOWS */ diff --git a/Python/traceback.c b/Python/traceback.c index d29cda78cefb64..82611d3cfd1124 100644 --- a/Python/traceback.c +++ b/Python/traceback.c @@ -24,7 +24,7 @@ #endif /* the deprecated posix apis are not available on xbox */ -#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY != WINAPI_FAMILY_DESKTOP_GAMES) +#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_GAMES) # define lseek _lseek #endif From 467bf40dc3808cf53889b4a132dbefa2b327a502 Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Sun, 26 Feb 2023 00:24:22 +0100 Subject: [PATCH 007/100] add MS_XBOX --- Modules/_posixsubprocess.c | 2 +- Modules/getpath.c | 11 +++++++---- Modules/mmapmodule.c | 2 +- Modules/posixmodule.c | 4 ++-- Objects/fileobject.c | 2 +- Objects/object.c | 2 +- Objects/obmalloc.c | 2 +- PC/pyconfig.h | 8 +++++++- Parser/myreadline.c | 2 +- Parser/tokenizer.c | 2 +- Python/bltinmodule.c | 2 +- Python/fileutils.c | 4 ++-- Python/initconfig.c | 2 +- Python/marshal.c | 2 +- Python/pylifecycle.c | 2 +- Python/sysmodule.c | 2 +- Python/traceback.c | 2 +- 17 files changed, 31 insertions(+), 22 deletions(-) diff --git a/Modules/_posixsubprocess.c b/Modules/_posixsubprocess.c index 99903247fb3d02..05815cc52e2063 100644 --- a/Modules/_posixsubprocess.c +++ b/Modules/_posixsubprocess.c @@ -60,7 +60,7 @@ #endif /* the deprecated posix apis are not available on xbox */ -#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_GAMES) +#ifdef MS_XBOX # define dup _dup # define dup2 _dup2 #endif diff --git a/Modules/getpath.c b/Modules/getpath.c index c3bdd15beeb493..fa324b8ebe6d91 100644 --- a/Modules/getpath.c +++ b/Modules/getpath.c @@ -12,8 +12,7 @@ #ifdef MS_WINDOWS # include // GetFullPathNameW(), MAX_PATH # include - -# if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_GAMES) +# ifdef MS_XBOX # define wcsicmp _wcsicmp # endif #endif @@ -221,6 +220,10 @@ getpath_isfile(PyObject *Py_UNUSED(self), PyObject *args) static PyObject * getpath_isxfile(PyObject *Py_UNUSED(self), PyObject *args) { +#ifdef MS_XBOX + /* having other executables on */ + Py_RETURN_FALSE; + PyObject *r = NULL; PyObject *pathobj; const wchar_t *path; @@ -232,13 +235,13 @@ getpath_isxfile(PyObject *Py_UNUSED(self), PyObject *args) if (path) { #ifdef MS_WINDOWS const wchar_t *ext; -#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_GAMES) +#ifdef MS_XBOX ext = (cchPath >= 4) ? path + cchPath - 4 : NULL; #endif DWORD attr = GetFileAttributesW(path); r = (attr != INVALID_FILE_ATTRIBUTES) && !(attr & FILE_ATTRIBUTE_DIRECTORY) && -#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_GAMES) +#ifdef MS_XBOX (ext != NULL) && #else SUCCEEDED(PathCchFindExtension(path, cchPath + 1, &ext)) && diff --git a/Modules/mmapmodule.c b/Modules/mmapmodule.c index fb7ddbb403496b..9f411d9682140c 100644 --- a/Modules/mmapmodule.c +++ b/Modules/mmapmodule.c @@ -37,7 +37,7 @@ #endif /* the deprecated posix apis are not available on xbox */ -#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_GAMES) +#ifdef MS_XBOX # define lseek _lseek #endif diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 1cf7a075b2c159..3792d519f68cfa 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -347,7 +347,7 @@ corresponding Unix manual entries for more information on calls."); # define HAVE_PIPE 1 # define HAVE_FSYNC 1 # define fsync _commit -# if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_GAMES) +# ifdef MS_XBOX # define dup2 _dup2 # define umask _umask # define close _close @@ -4479,7 +4479,7 @@ os__path_splitroot_impl(PyObject *module, path_t *path) *p = L'\\'; } -#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_GAMES) +#ifdef MS_XBOX /* this does not handle persistent local storage */ ret = E_FAIL; if ((wcsncmp(buffer, L"G:\\", 3) == 0) || (wcsncmp(buffer, L"D:\\", 3) == 0) || (wcsncmp(buffer, L"T:\\", 3) == 0)) { diff --git a/Objects/fileobject.c b/Objects/fileobject.c index a6928c6d6c2296..9207aa1d5db4a2 100644 --- a/Objects/fileobject.c +++ b/Objects/fileobject.c @@ -6,7 +6,7 @@ #include "pycore_runtime.h" // _PyRuntime /* the deprecated posix apis are not available on xbox */ -#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_GAMES) +#ifdef MS_XBOX # define isatty _isatty # define fileno _fileno #endif diff --git a/Objects/object.c b/Objects/object.c index ee1c40e446e9de..e36a24687e23bb 100644 --- a/Objects/object.c +++ b/Objects/object.c @@ -23,7 +23,7 @@ #endif /* the deprecated posix apis are not available on xbox */ -#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_GAMES) +#ifdef MS_XBOX # define fileno _fileno #endif diff --git a/Objects/obmalloc.c b/Objects/obmalloc.c index 97e3174e5d5a3c..be7ed8df029bee 100644 --- a/Objects/obmalloc.c +++ b/Objects/obmalloc.c @@ -9,7 +9,7 @@ #include /* the deprecated posix apis are not available on xbox */ -#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_GAMES) +#ifdef MS_XBOX # define fileno _fileno #endif diff --git a/PC/pyconfig.h b/PC/pyconfig.h index a34d420ab7ecaa..9b55d2bea52846 100644 --- a/PC/pyconfig.h +++ b/PC/pyconfig.h @@ -76,6 +76,10 @@ WIN32 is still required for the locale module. #define MS_WINDOWS_NON_DESKTOP #endif +#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_GAMES) +#define MS_XBOX +#endif + /* Compiler specific defines */ /* ------------------------------------------------------------------------*/ @@ -498,7 +502,9 @@ Py_NO_ENABLE_SHARED to find out. Also support MS_NO_COREDLL for b/w compat */ /* #define HAVE_CLOCK */ /* Define when any dynamic module loading is enabled */ -#define HAVE_DYNAMIC_LOADING +#ifndef MS_XBOX +# define HAVE_DYNAMIC_LOADING +#endif /* Define if you have ftime. */ #define HAVE_FTIME diff --git a/Parser/myreadline.c b/Parser/myreadline.c index 5a6e5dfa595c47..ac73b8f8e0ba72 100644 --- a/Parser/myreadline.c +++ b/Parser/myreadline.c @@ -17,7 +17,7 @@ # define WIN32_LEAN_AND_MEAN # endif # include "windows.h" -# if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_GAMES) +# ifdef MS_XBOX # define isatty _isatty # define fileno _fileno # endif diff --git a/Parser/tokenizer.c b/Parser/tokenizer.c index f8587bd34da62a..233f6a3bd17529 100644 --- a/Parser/tokenizer.c +++ b/Parser/tokenizer.c @@ -17,7 +17,7 @@ #include "abstract.h" /* the deprecated posix apis are not available on xbox */ -#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_GAMES) +#ifdef MS_XBOX # define fdopen _fdopen # define lseek _lseek # define fileno _fileno diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index 3662cfde6a2ba6..356b473f776dc6 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -14,7 +14,7 @@ #include "clinic/bltinmodule.c.h" /* the deprecated posix apis are not available on xbox */ -#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_GAMES) +#ifdef MS_XBOX # define isatty _isatty # define fileno _fileno #endif diff --git a/Python/fileutils.c b/Python/fileutils.c index 520dba941f34c0..732832477ff186 100644 --- a/Python/fileutils.c +++ b/Python/fileutils.c @@ -41,7 +41,7 @@ int _Py_open_cloexec_works = -1; #endif /* the deprecated posix apis are not available on xbox */ -#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_GAMES) +#ifdef MS_XBOX # define dup _dup # define open _open # define read _read @@ -2030,7 +2030,7 @@ _Py_wrealpath(const wchar_t *path, int _Py_isabs(const wchar_t *path) { -#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_GAMES) +#ifdef MS_XBOX /* this does not handle persistent local storage */ return (wcsncmp(path, L"G:\\", 3) == 0) || (wcsncmp(path, L"D:\\", 3) == 0) diff --git a/Python/initconfig.c b/Python/initconfig.c index be8d8a54ca9a8e..8316277b27646f 100644 --- a/Python/initconfig.c +++ b/Python/initconfig.c @@ -21,7 +21,7 @@ # ifdef HAVE_FCNTL_H # include // O_BINARY # endif -# if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_GAMES) +# ifdef MS_XBOX # define fileno _fileno # endif #endif diff --git a/Python/marshal.c b/Python/marshal.c index 1eb6c2a6b86d94..3b1910b349934c 100644 --- a/Python/marshal.c +++ b/Python/marshal.c @@ -15,7 +15,7 @@ #include "marshal.h" // Py_MARSHAL_VERSION /* the deprecated posix apis are not available on xbox */ -#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_GAMES) +#ifdef MS_XBOX # define fileno _fileno #endif diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index 68985339ee1bf0..296707d269495e 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -57,7 +57,7 @@ extern void _PyIO_Fini(void); #endif /* the deprecated posix apis are not available on xbox */ -#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_GAMES) +#ifdef MS_XBOX # define isatty _isatty # define fileno _fileno #endif diff --git a/Python/sysmodule.c b/Python/sysmodule.c index f62606ece2dbb7..ae622856b7cae6 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -41,7 +41,7 @@ Data members: #define WIN32_LEAN_AND_MEAN #include /* the deprecated posix apis are not available on xbox */ -#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_GAMES) +#ifdef MS_XBOX # define fileno _fileno #endif #endif /* MS_WINDOWS */ diff --git a/Python/traceback.c b/Python/traceback.c index 82611d3cfd1124..4691255c522068 100644 --- a/Python/traceback.c +++ b/Python/traceback.c @@ -24,7 +24,7 @@ #endif /* the deprecated posix apis are not available on xbox */ -#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_GAMES) +#ifdef MS_XBOX # define lseek _lseek #endif From e734492ff2fb39a9fc9f3f25958a828bc2862d20 Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Sun, 26 Feb 2023 00:27:14 +0100 Subject: [PATCH 008/100] cleanup --- Modules/getpath.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Modules/getpath.c b/Modules/getpath.c index fa324b8ebe6d91..bf7bf8b6882536 100644 --- a/Modules/getpath.c +++ b/Modules/getpath.c @@ -220,10 +220,6 @@ getpath_isfile(PyObject *Py_UNUSED(self), PyObject *args) static PyObject * getpath_isxfile(PyObject *Py_UNUSED(self), PyObject *args) { -#ifdef MS_XBOX - /* having other executables on */ - Py_RETURN_FALSE; - PyObject *r = NULL; PyObject *pathobj; const wchar_t *path; From fad23bc3066a651acecdc6b2cb2e5280986499f0 Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Sun, 26 Feb 2023 01:18:08 +0100 Subject: [PATCH 009/100] use winsock2 on xbox --- Modules/selectmodule.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Modules/selectmodule.c b/Modules/selectmodule.c index 4de33ad97c5dbb..15afd72a84c247 100644 --- a/Modules/selectmodule.c +++ b/Modules/selectmodule.c @@ -60,7 +60,11 @@ extern void bzero(void *, int); # ifndef WIN32_LEAN_AND_MEAN # define WIN32_LEAN_AND_MEAN # endif -# include +# ifdef MS_XBOX +# include +# else +# include +# endif #else # define SOCKET int #endif From b6b28ec8d0236c1e93f9a379ad2eddb50c8fda01 Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Sun, 26 Feb 2023 02:45:25 +0100 Subject: [PATCH 010/100] stub winreg --- Modules/_ssl.c | 4 ++ Modules/posixmodule.c | 4 +- PC/pyconfig.h | 12 +++- PC/winreg.c | 148 ++++++++++++++++++++++++++++++++++++++++++ Python/fileutils.c | 19 +++++- 5 files changed, 182 insertions(+), 5 deletions(-) diff --git a/Modules/_ssl.c b/Modules/_ssl.c index 8f03a846aed089..e44ae9ec0f54ba 100644 --- a/Modules/_ssl.c +++ b/Modules/_ssl.c @@ -28,6 +28,10 @@ /* Include symbols from _socket module */ #include "socketmodule.h" +#ifdef MS_XBOX +# include +#endif + #include "_ssl.h" /* Redefined below for Windows debug builds after important #includes */ diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 3792d519f68cfa..0f12b38011187d 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -13903,7 +13903,7 @@ os_set_inheritable_impl(PyObject *module, int fd, int inheritable) } -#ifdef MS_WINDOWS +#ifndef MS_WINDOWS_NON_DESKTOP /*[clinic input] os.get_handle_inheritable -> bool handle: intptr_t @@ -13948,7 +13948,7 @@ os_set_handle_inheritable_impl(PyObject *module, intptr_t handle, } Py_RETURN_NONE; } -#endif /* MS_WINDOWS */ +#endif /* !MS_WINDOWS_NON_DESKTOP */ /*[clinic input] os.get_blocking -> bool diff --git a/PC/pyconfig.h b/PC/pyconfig.h index 9b55d2bea52846..b23a459978cffc 100644 --- a/PC/pyconfig.h +++ b/PC/pyconfig.h @@ -304,7 +304,17 @@ Py_NO_ENABLE_SHARED to find out. Also support MS_NO_COREDLL for b/w compat */ # endif /* Py_BUILD_CORE */ #endif /* MS_COREDLL */ -#if defined(MS_WIN64) +#if defined(MS_XBOX) +# define PLATFORM "xbox" +# define SIZEOF_VOID_P 8 +# define SIZEOF_TIME_T 8 +# define SIZEOF_OFF_T 4 +# define SIZEOF_FPOS_T 8 +# define SIZEOF_HKEY 8 +# define SIZEOF_SIZE_T 8 +# define ALIGNOF_SIZE_T 8 +# define HAVE_LARGEFILE_SUPPORT +#elif defined(MS_WIN64) /* maintain "win32" sys.platform for backward compatibility of Python code, the Win64 API should be close enough to the Win32 API to make this preferable */ diff --git a/PC/winreg.c b/PC/winreg.c index 63b37be526ab80..0bff0f814a30ed 100644 --- a/PC/winreg.c +++ b/PC/winreg.c @@ -143,8 +143,10 @@ PyHKEY_deallocFunc(PyObject *ob) check to fail! */ PyHKEYObject *obkey = (PyHKEYObject *)ob; +#ifndef MS_WINDOWS_NON_DESKTOP if (obkey->hkey) RegCloseKey((HKEY)obkey->hkey); +#endif PyObject_Free(ob); } @@ -388,6 +390,7 @@ PyTypeObject PyHKEY_Type = PyObject * PyHKEY_New(HKEY hInit) { + PyHKEYObject *key = PyObject_New(PyHKEYObject, &PyHKEY_Type); if (key) key->hkey = hInit; @@ -406,7 +409,11 @@ PyHKEY_Close(PyObject *ob_handle) if (PyHKEY_Check(ob_handle)) { ((PyHKEYObject*)ob_handle)->hkey = 0; } +#ifdef MS_WINDOWS_NON_DESKTOP + rc = ERROR_SUCCESS +#else rc = key ? RegCloseKey(key) : ERROR_SUCCESS; +#endif if (rc != ERROR_SUCCESS) PyErr_SetFromWindowsErrWithFunction(rc, "RegCloseKey"); return rc == ERROR_SUCCESS; @@ -478,17 +485,25 @@ PyWinObject_CloseHKEY(PyObject *obHandle) } #if SIZEOF_LONG >= SIZEOF_HKEY else if (PyLong_Check(obHandle)) { +#ifdef MS_WINDOWS_NON_DESKTOP + ok = TRUE; +#else long rc = RegCloseKey((HKEY)PyLong_AsLong(obHandle)); ok = (rc == ERROR_SUCCESS); if (!ok) PyErr_SetFromWindowsErrWithFunction(rc, "RegCloseKey"); +#endif } #else else if (PyLong_Check(obHandle)) { +#ifdef MS_WINDOWS_NON_DESKTOP + ok = TRUE; +#else long rc = RegCloseKey((HKEY)PyLong_AsVoidPtr(obHandle)); ok = (rc == ERROR_SUCCESS); if (!ok) PyErr_SetFromWindowsErrWithFunction(rc, "RegCloseKey"); +#endif } #endif else { @@ -850,6 +865,13 @@ winreg_ConnectRegistry_impl(PyObject *module, const Py_UNICODE *computer_name, HKEY key) /*[clinic end generated code: output=cd4f70fb9ec901fb input=5f98a891a347e68e]*/ { +#ifdef MS_WINDOWS_NON_DESKTOP + (void)module; + (void)key; + (void)computer_name; + PyErr_Format(PyExc_NotImplementedError, "not implemented on this platform"); + return NULL; +#else HKEY retKey; long rc; if (PySys_Audit("winreg.ConnectRegistry", "un", @@ -864,6 +886,7 @@ winreg_ConnectRegistry_impl(PyObject *module, return NULL; } return retKey; +#endif } /*[clinic input] @@ -890,6 +913,13 @@ static HKEY winreg_CreateKey_impl(PyObject *module, HKEY key, const Py_UNICODE *sub_key) /*[clinic end generated code: output=2af13910d56eae26 input=3cdd1622488acea2]*/ { +#ifdef MS_WINDOWS_NON_DESKTOP + (void)module; + (void)key; + (void)sub_key; + PyErr_Format(PyExc_NotImplementedError, "not implemented on this platform"); + return NULL; +#else HKEY retKey; long rc; @@ -908,6 +938,7 @@ winreg_CreateKey_impl(PyObject *module, HKEY key, const Py_UNICODE *sub_key) return NULL; } return retKey; +#endif } /*[clinic input] @@ -940,6 +971,15 @@ winreg_CreateKeyEx_impl(PyObject *module, HKEY key, REGSAM access) /*[clinic end generated code: output=643a70ad6a361a97 input=42c2b03f98406b66]*/ { +#ifdef MS_WINDOWS_NON_DESKTOP + (void)module; + (void)key; + (void)sub_key; + (void)reserved; + (void)access; + PyErr_Format(PyExc_NotImplementedError, "not implemented on this platform"); + return NULL; +#else HKEY retKey; long rc; @@ -959,6 +999,7 @@ winreg_CreateKeyEx_impl(PyObject *module, HKEY key, return NULL; } return retKey; +#endif } /*[clinic input] @@ -983,6 +1024,12 @@ static PyObject * winreg_DeleteKey_impl(PyObject *module, HKEY key, const Py_UNICODE *sub_key) /*[clinic end generated code: output=d2652a84f70e0862 input=b31d225b935e4211]*/ { +#ifdef MS_WINDOWS_NON_DESKTOP + (void)module; + (void)key; + (void)sub_key; + return PyErr_Format(PyExc_NotImplementedError, "not implemented on this platform"); +#else long rc; if (PySys_Audit("winreg.DeleteKey", "nun", (Py_ssize_t)key, sub_key, @@ -995,6 +1042,7 @@ winreg_DeleteKey_impl(PyObject *module, HKEY key, const Py_UNICODE *sub_key) if (rc != ERROR_SUCCESS) return PyErr_SetFromWindowsErrWithFunction(rc, "RegDeleteKey"); Py_RETURN_NONE; +#endif } /*[clinic input] @@ -1030,6 +1078,14 @@ winreg_DeleteKeyEx_impl(PyObject *module, HKEY key, int reserved) /*[clinic end generated code: output=52a1c8b374ebc003 input=a3186db079b3bf85]*/ { +#ifdef MS_WINDOWS_NON_DESKTOP + (void)module; + (void)key; + (void)sub_key; + (void)access; + (void)reserved; + return PyErr_Format(PyExc_NotImplementedError, "not implemented on this platform"); +#else long rc; if (PySys_Audit("winreg.DeleteKey", "nun", (Py_ssize_t)key, sub_key, @@ -1042,6 +1098,7 @@ winreg_DeleteKeyEx_impl(PyObject *module, HKEY key, if (rc != ERROR_SUCCESS) return PyErr_SetFromWindowsErrWithFunction(rc, "RegDeleteKeyEx"); Py_RETURN_NONE; +#endif } /*[clinic input] @@ -1060,6 +1117,12 @@ static PyObject * winreg_DeleteValue_impl(PyObject *module, HKEY key, const Py_UNICODE *value) /*[clinic end generated code: output=56fa9d21f3a54371 input=a78d3407a4197b21]*/ { +#ifdef MS_WINDOWS_NON_DESKTOP + (void)module; + (void)key; + (void)value; + return PyErr_Format(PyExc_NotImplementedError, "not implemented on this platform"); +#else long rc; if (PySys_Audit("winreg.DeleteValue", "nu", (Py_ssize_t)key, value) < 0) { @@ -1072,6 +1135,7 @@ winreg_DeleteValue_impl(PyObject *module, HKEY key, const Py_UNICODE *value) return PyErr_SetFromWindowsErrWithFunction(rc, "RegDeleteValue"); Py_RETURN_NONE; +#endif } /*[clinic input] @@ -1094,6 +1158,12 @@ static PyObject * winreg_EnumKey_impl(PyObject *module, HKEY key, int index) /*[clinic end generated code: output=25a6ec52cd147bc4 input=fad9a7c00ab0e04b]*/ { +#ifdef MS_WINDOWS_NON_DESKTOP + (void)module; + (void)key; + (void)index; + return PyErr_Format(PyExc_NotImplementedError, "not implemented on this platform"); +#else long rc; PyObject *retStr; @@ -1118,6 +1188,7 @@ winreg_EnumKey_impl(PyObject *module, HKEY key, int index) retStr = PyUnicode_FromWideChar(tmpbuf, len); return retStr; /* can be NULL */ +#endif } /*[clinic input] @@ -1149,6 +1220,12 @@ static PyObject * winreg_EnumValue_impl(PyObject *module, HKEY key, int index) /*[clinic end generated code: output=d363b5a06f8789ac input=4414f47a6fb238b5]*/ { +#ifdef MS_WINDOWS_NON_DESKTOP + (void)module; + (void)key; + (void)index; + return PyErr_Format(PyExc_NotImplementedError, "not implemented on this platform"); +#else long rc; wchar_t *retValueBuf; BYTE *tmpBuf; @@ -1225,6 +1302,7 @@ winreg_EnumValue_impl(PyObject *module, HKEY key, int index) PyMem_Free(retValueBuf); PyMem_Free(retDataBuf); return retVal; +#endif } /*[clinic input] @@ -1296,6 +1374,11 @@ static PyObject * winreg_FlushKey_impl(PyObject *module, HKEY key) /*[clinic end generated code: output=e6fc230d4c5dc049 input=f57457c12297d82f]*/ { +#ifdef MS_WINDOWS_NON_DESKTOP + (void)module; + (void)key; + return PyErr_Format(PyExc_NotImplementedError, "not implemented on this platform"); +#else long rc; Py_BEGIN_ALLOW_THREADS rc = RegFlushKey(key); @@ -1303,6 +1386,7 @@ winreg_FlushKey_impl(PyObject *module, HKEY key) if (rc != ERROR_SUCCESS) return PyErr_SetFromWindowsErrWithFunction(rc, "RegFlushKey"); Py_RETURN_NONE; +#endif } @@ -1340,6 +1424,13 @@ winreg_LoadKey_impl(PyObject *module, HKEY key, const Py_UNICODE *sub_key, const Py_UNICODE *file_name) /*[clinic end generated code: output=65f89f2548cb27c7 input=e3b5b45ade311582]*/ { +#ifdef MS_WINDOWS_NON_DESKTOP + (void)module; + (void)key; + (void)sub_key; + (void)file_name; + return PyErr_Format(PyExc_NotImplementedError, "not implemented on this platform"); +#else long rc; if (PySys_Audit("winreg.LoadKey", "nuu", @@ -1352,6 +1443,7 @@ winreg_LoadKey_impl(PyObject *module, HKEY key, const Py_UNICODE *sub_key, if (rc != ERROR_SUCCESS) return PyErr_SetFromWindowsErrWithFunction(rc, "RegLoadKey"); Py_RETURN_NONE; +#endif } /*[clinic input] @@ -1378,6 +1470,15 @@ winreg_OpenKey_impl(PyObject *module, HKEY key, const Py_UNICODE *sub_key, int reserved, REGSAM access) /*[clinic end generated code: output=8849bff2c30104ad input=098505ac36a9ae28]*/ { +#ifdef MS_WINDOWS_NON_DESKTOP + (void)module; + (void)key; + (void)sub_key; + (void)reserved; + (void)access; + PyErr_Format(PyExc_NotImplementedError, "not implemented on this platform"); + return NULL; +#else HKEY retKey; long rc; @@ -1398,6 +1499,7 @@ winreg_OpenKey_impl(PyObject *module, HKEY key, const Py_UNICODE *sub_key, return NULL; } return retKey; +#endif } /*[clinic input] @@ -1437,6 +1539,11 @@ static PyObject * winreg_QueryInfoKey_impl(PyObject *module, HKEY key) /*[clinic end generated code: output=dc657b8356a4f438 input=c3593802390cde1f]*/ { +#ifdef MS_WINDOWS_NON_DESKTOP + (void)module; + (void)key; + return PyErr_Format(PyExc_NotImplementedError, "not implemented on this platform"); +#else long rc; DWORD nSubKeys, nValues; FILETIME ft; @@ -1461,6 +1568,7 @@ winreg_QueryInfoKey_impl(PyObject *module, HKEY key) ret = Py_BuildValue("iiO", nSubKeys, nValues, l); Py_DECREF(l); return ret; +#endif } /*[clinic input] @@ -1488,6 +1596,12 @@ static PyObject * winreg_QueryValue_impl(PyObject *module, HKEY key, const Py_UNICODE *sub_key) /*[clinic end generated code: output=c655810ae50c63a9 input=41cafbbf423b21d6]*/ { +#ifdef MS_WINDOWS_NON_DESKTOP + (void)module; + (void)key; + (void)sub_key; + return PyErr_Format(PyExc_NotImplementedError, "not implemented on this platform"); +#else long rc; PyObject *retStr; wchar_t *retBuf; @@ -1535,6 +1649,7 @@ winreg_QueryValue_impl(PyObject *module, HKEY key, const Py_UNICODE *sub_key) retStr = PyUnicode_FromWideChar(retBuf, wcslen(retBuf)); PyMem_Free(retBuf); return retStr; +#endif } @@ -1559,6 +1674,12 @@ static PyObject * winreg_QueryValueEx_impl(PyObject *module, HKEY key, const Py_UNICODE *name) /*[clinic end generated code: output=f1b85b1c3d887ec7 input=cf366cada4836891]*/ { +#ifdef MS_WINDOWS_NON_DESKTOP + (void)module; + (void)key; + (void)name; + return PyErr_Format(PyExc_NotImplementedError, "not implemented on this platform"); +#else long rc; BYTE *retBuf, *tmp; DWORD bufSize = 0, retSize; @@ -1608,6 +1729,7 @@ winreg_QueryValueEx_impl(PyObject *module, HKEY key, const Py_UNICODE *name) result = Py_BuildValue("Oi", obData, typ); Py_DECREF(obData); return result; +#endif } /*[clinic input] @@ -1636,6 +1758,12 @@ static PyObject * winreg_SaveKey_impl(PyObject *module, HKEY key, const Py_UNICODE *file_name) /*[clinic end generated code: output=ca94b835c88f112b input=da735241f91ac7a2]*/ { +#ifdef MS_WINDOWS_NON_DESKTOP + (void)module; + (void)key; + (void)file_name; + return PyErr_Format(PyExc_NotImplementedError, "not implemented on this platform"); +#else LPSECURITY_ATTRIBUTES pSA = NULL; long rc; @@ -1653,6 +1781,7 @@ winreg_SaveKey_impl(PyObject *module, HKEY key, const Py_UNICODE *file_name) if (rc != ERROR_SUCCESS) return PyErr_SetFromWindowsErrWithFunction(rc, "RegSaveKey"); Py_RETURN_NONE; +#endif } /*[clinic input] @@ -1687,6 +1816,14 @@ winreg_SetValue_impl(PyObject *module, HKEY key, const Py_UNICODE *sub_key, DWORD type, PyObject *value_obj) /*[clinic end generated code: output=d4773dc9c372311a input=bf088494ae2d24fd]*/ { +#ifdef MS_WINDOWS_NON_DESKTOP + (void)module; + (void)key; + (void)sub_key; + (void)type; + (void)value_obj; + return PyErr_Format(PyExc_NotImplementedError, "not implemented on this platform"); +#else Py_ssize_t value_length; long rc; @@ -1719,6 +1856,7 @@ winreg_SetValue_impl(PyObject *module, HKEY key, const Py_UNICODE *sub_key, if (rc != ERROR_SUCCESS) return PyErr_SetFromWindowsErrWithFunction(rc, "RegSetValue"); Py_RETURN_NONE; +#endif } /*[clinic input] @@ -1771,6 +1909,15 @@ winreg_SetValueEx_impl(PyObject *module, HKEY key, DWORD type, PyObject *value) /*[clinic end generated code: output=811b769a66ae11b7 input=900a9e3990bfb196]*/ { +#ifdef MS_WINDOWS_NON_DESKTOP + (void)module; + (void)key; + (void)value_name; + (void)reserved; + (void)type; + (void)value; + return PyErr_Format(PyExc_NotImplementedError, "not implemented on this platform"); +#else BYTE *data; DWORD len; @@ -1797,6 +1944,7 @@ winreg_SetValueEx_impl(PyObject *module, HKEY key, return PyErr_SetFromWindowsErrWithFunction(rc, "RegSetValueEx"); Py_RETURN_NONE; +#endif } /*[clinic input] diff --git a/Python/fileutils.c b/Python/fileutils.c index 732832477ff186..0925c7ab82ffa5 100644 --- a/Python/fileutils.c +++ b/Python/fileutils.c @@ -88,7 +88,9 @@ _Py_device_encoding(int fd) if (!valid) Py_RETURN_NONE; -#if defined(MS_WINDOWS) +#ifdef MS_WINDOWS_NON_DESKTOP + Py_RETURN_NONE; +#elif defined(MS_WINDOWS) UINT cp; if (fd == 0) cp = GetConsoleCP(); @@ -1286,7 +1288,9 @@ _Py_stat(PyObject *path, struct stat *statbuf) static int get_inheritable(int fd, int raise) { -#ifdef MS_WINDOWS +#ifdef MS_WINDOWS_NON_DESKTOP + return 0; +#elif defined(MS_WINDOWS) HANDLE handle; DWORD flags; @@ -1331,6 +1335,16 @@ _Py_get_inheritable(int fd) static int set_inheritable(int fd, int inheritable, int raise, int *atomic_flag_works) { +#ifdef MS_WINDOWS_NON_DESKTOP + if(!inheritable) + return 0; + + if (raise) + PyErr_Format(PyExc_OSError, + "Setting handle as inheritable is unsupported on this platform"); + + return -1; +#else #ifdef MS_WINDOWS HANDLE handle; DWORD flags; @@ -1460,6 +1474,7 @@ set_inheritable(int fd, int inheritable, int raise, int *atomic_flag_works) } return 0; #endif +#endif /* MS_WINDOWS_NON_DESKTOP */ } /* Make the file descriptor non-inheritable. From cdbb1f2c95688082edafb20a9eb988f5f896c342 Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Sun, 26 Feb 2023 02:46:29 +0100 Subject: [PATCH 011/100] rename to MS_GAMES --- Modules/_posixsubprocess.c | 2 +- Modules/_ssl.c | 2 +- Modules/getpath.c | 6 +++--- Modules/mmapmodule.c | 2 +- Modules/posixmodule.c | 4 ++-- Modules/selectmodule.c | 2 +- Objects/fileobject.c | 2 +- Objects/object.c | 2 +- Objects/obmalloc.c | 2 +- PC/pyconfig.h | 6 +++--- Parser/myreadline.c | 2 +- Parser/tokenizer.c | 2 +- Python/bltinmodule.c | 2 +- Python/fileutils.c | 4 ++-- Python/initconfig.c | 2 +- Python/marshal.c | 2 +- Python/pylifecycle.c | 2 +- Python/sysmodule.c | 2 +- Python/traceback.c | 2 +- 19 files changed, 25 insertions(+), 25 deletions(-) diff --git a/Modules/_posixsubprocess.c b/Modules/_posixsubprocess.c index 05815cc52e2063..962d2117774607 100644 --- a/Modules/_posixsubprocess.c +++ b/Modules/_posixsubprocess.c @@ -60,7 +60,7 @@ #endif /* the deprecated posix apis are not available on xbox */ -#ifdef MS_XBOX +#ifdef MS_WINDOWS_GAMES # define dup _dup # define dup2 _dup2 #endif diff --git a/Modules/_ssl.c b/Modules/_ssl.c index e44ae9ec0f54ba..0c504700f48e6a 100644 --- a/Modules/_ssl.c +++ b/Modules/_ssl.c @@ -28,7 +28,7 @@ /* Include symbols from _socket module */ #include "socketmodule.h" -#ifdef MS_XBOX +#ifdef MS_WINDOWS_GAMES # include #endif diff --git a/Modules/getpath.c b/Modules/getpath.c index bf7bf8b6882536..2a2d8108b60ec5 100644 --- a/Modules/getpath.c +++ b/Modules/getpath.c @@ -12,7 +12,7 @@ #ifdef MS_WINDOWS # include // GetFullPathNameW(), MAX_PATH # include -# ifdef MS_XBOX +# ifdef MS_WINDOWS_GAMES # define wcsicmp _wcsicmp # endif #endif @@ -231,13 +231,13 @@ getpath_isxfile(PyObject *Py_UNUSED(self), PyObject *args) if (path) { #ifdef MS_WINDOWS const wchar_t *ext; -#ifdef MS_XBOX +#ifdef MS_WINDOWS_GAMES ext = (cchPath >= 4) ? path + cchPath - 4 : NULL; #endif DWORD attr = GetFileAttributesW(path); r = (attr != INVALID_FILE_ATTRIBUTES) && !(attr & FILE_ATTRIBUTE_DIRECTORY) && -#ifdef MS_XBOX +#ifdef MS_WINDOWS_GAMES (ext != NULL) && #else SUCCEEDED(PathCchFindExtension(path, cchPath + 1, &ext)) && diff --git a/Modules/mmapmodule.c b/Modules/mmapmodule.c index 9f411d9682140c..05176d59a79492 100644 --- a/Modules/mmapmodule.c +++ b/Modules/mmapmodule.c @@ -37,7 +37,7 @@ #endif /* the deprecated posix apis are not available on xbox */ -#ifdef MS_XBOX +#ifdef MS_WINDOWS_GAMES # define lseek _lseek #endif diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 0f12b38011187d..cdc3a4a8e8f945 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -347,7 +347,7 @@ corresponding Unix manual entries for more information on calls."); # define HAVE_PIPE 1 # define HAVE_FSYNC 1 # define fsync _commit -# ifdef MS_XBOX +# ifdef MS_WINDOWS_GAMES # define dup2 _dup2 # define umask _umask # define close _close @@ -4479,7 +4479,7 @@ os__path_splitroot_impl(PyObject *module, path_t *path) *p = L'\\'; } -#ifdef MS_XBOX +#ifdef MS_WINDOWS_GAMES /* this does not handle persistent local storage */ ret = E_FAIL; if ((wcsncmp(buffer, L"G:\\", 3) == 0) || (wcsncmp(buffer, L"D:\\", 3) == 0) || (wcsncmp(buffer, L"T:\\", 3) == 0)) { diff --git a/Modules/selectmodule.c b/Modules/selectmodule.c index 15afd72a84c247..6da071cb268f79 100644 --- a/Modules/selectmodule.c +++ b/Modules/selectmodule.c @@ -60,7 +60,7 @@ extern void bzero(void *, int); # ifndef WIN32_LEAN_AND_MEAN # define WIN32_LEAN_AND_MEAN # endif -# ifdef MS_XBOX +# ifdef MS_WINDOWS_GAMES # include # else # include diff --git a/Objects/fileobject.c b/Objects/fileobject.c index 9207aa1d5db4a2..806bb4d424b709 100644 --- a/Objects/fileobject.c +++ b/Objects/fileobject.c @@ -6,7 +6,7 @@ #include "pycore_runtime.h" // _PyRuntime /* the deprecated posix apis are not available on xbox */ -#ifdef MS_XBOX +#ifdef MS_WINDOWS_GAMES # define isatty _isatty # define fileno _fileno #endif diff --git a/Objects/object.c b/Objects/object.c index e36a24687e23bb..ee089d19f8aa65 100644 --- a/Objects/object.c +++ b/Objects/object.c @@ -23,7 +23,7 @@ #endif /* the deprecated posix apis are not available on xbox */ -#ifdef MS_XBOX +#ifdef MS_WINDOWS_GAMES # define fileno _fileno #endif diff --git a/Objects/obmalloc.c b/Objects/obmalloc.c index be7ed8df029bee..5f9ebd916df400 100644 --- a/Objects/obmalloc.c +++ b/Objects/obmalloc.c @@ -9,7 +9,7 @@ #include /* the deprecated posix apis are not available on xbox */ -#ifdef MS_XBOX +#ifdef MS_WINDOWS_GAMES # define fileno _fileno #endif diff --git a/PC/pyconfig.h b/PC/pyconfig.h index b23a459978cffc..4a6c806d1fc02f 100644 --- a/PC/pyconfig.h +++ b/PC/pyconfig.h @@ -77,7 +77,7 @@ WIN32 is still required for the locale module. #endif #if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_GAMES) -#define MS_XBOX +#define MS_WINDOWS_GAMES #endif /* Compiler specific defines */ @@ -304,7 +304,7 @@ Py_NO_ENABLE_SHARED to find out. Also support MS_NO_COREDLL for b/w compat */ # endif /* Py_BUILD_CORE */ #endif /* MS_COREDLL */ -#if defined(MS_XBOX) +#if defined(MS_WINDOWS_GAMES) # define PLATFORM "xbox" # define SIZEOF_VOID_P 8 # define SIZEOF_TIME_T 8 @@ -512,7 +512,7 @@ Py_NO_ENABLE_SHARED to find out. Also support MS_NO_COREDLL for b/w compat */ /* #define HAVE_CLOCK */ /* Define when any dynamic module loading is enabled */ -#ifndef MS_XBOX +#ifndef MS_WINDOWS_GAMES # define HAVE_DYNAMIC_LOADING #endif diff --git a/Parser/myreadline.c b/Parser/myreadline.c index ac73b8f8e0ba72..80f67b206d8911 100644 --- a/Parser/myreadline.c +++ b/Parser/myreadline.c @@ -17,7 +17,7 @@ # define WIN32_LEAN_AND_MEAN # endif # include "windows.h" -# ifdef MS_XBOX +# ifdef MS_WINDOWS_GAMES # define isatty _isatty # define fileno _fileno # endif diff --git a/Parser/tokenizer.c b/Parser/tokenizer.c index 233f6a3bd17529..5e1a90d79d7d66 100644 --- a/Parser/tokenizer.c +++ b/Parser/tokenizer.c @@ -17,7 +17,7 @@ #include "abstract.h" /* the deprecated posix apis are not available on xbox */ -#ifdef MS_XBOX +#ifdef MS_WINDOWS_GAMES # define fdopen _fdopen # define lseek _lseek # define fileno _fileno diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index 356b473f776dc6..d5cbfdd1d89fd3 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -14,7 +14,7 @@ #include "clinic/bltinmodule.c.h" /* the deprecated posix apis are not available on xbox */ -#ifdef MS_XBOX +#ifdef MS_WINDOWS_GAMES # define isatty _isatty # define fileno _fileno #endif diff --git a/Python/fileutils.c b/Python/fileutils.c index 0925c7ab82ffa5..30bb41e237de0f 100644 --- a/Python/fileutils.c +++ b/Python/fileutils.c @@ -41,7 +41,7 @@ int _Py_open_cloexec_works = -1; #endif /* the deprecated posix apis are not available on xbox */ -#ifdef MS_XBOX +#ifdef MS_WINDOWS_GAMES # define dup _dup # define open _open # define read _read @@ -2045,7 +2045,7 @@ _Py_wrealpath(const wchar_t *path, int _Py_isabs(const wchar_t *path) { -#ifdef MS_XBOX +#ifdef MS_WINDOWS_GAMES /* this does not handle persistent local storage */ return (wcsncmp(path, L"G:\\", 3) == 0) || (wcsncmp(path, L"D:\\", 3) == 0) diff --git a/Python/initconfig.c b/Python/initconfig.c index 8316277b27646f..acc8ee2c2460a9 100644 --- a/Python/initconfig.c +++ b/Python/initconfig.c @@ -21,7 +21,7 @@ # ifdef HAVE_FCNTL_H # include // O_BINARY # endif -# ifdef MS_XBOX +# ifdef MS_WINDOWS_GAMES # define fileno _fileno # endif #endif diff --git a/Python/marshal.c b/Python/marshal.c index 3b1910b349934c..405e7966c9ecce 100644 --- a/Python/marshal.c +++ b/Python/marshal.c @@ -15,7 +15,7 @@ #include "marshal.h" // Py_MARSHAL_VERSION /* the deprecated posix apis are not available on xbox */ -#ifdef MS_XBOX +#ifdef MS_WINDOWS_GAMES # define fileno _fileno #endif diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index 296707d269495e..5e93c20afe4b45 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -57,7 +57,7 @@ extern void _PyIO_Fini(void); #endif /* the deprecated posix apis are not available on xbox */ -#ifdef MS_XBOX +#ifdef MS_WINDOWS_GAMES # define isatty _isatty # define fileno _fileno #endif diff --git a/Python/sysmodule.c b/Python/sysmodule.c index ae622856b7cae6..78ca7a464da65d 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -41,7 +41,7 @@ Data members: #define WIN32_LEAN_AND_MEAN #include /* the deprecated posix apis are not available on xbox */ -#ifdef MS_XBOX +#ifdef MS_WINDOWS_GAMES # define fileno _fileno #endif #endif /* MS_WINDOWS */ diff --git a/Python/traceback.c b/Python/traceback.c index 4691255c522068..5ecabb817c10ef 100644 --- a/Python/traceback.c +++ b/Python/traceback.c @@ -24,7 +24,7 @@ #endif /* the deprecated posix apis are not available on xbox */ -#ifdef MS_XBOX +#ifdef MS_WINDOWS_GAMES # define lseek _lseek #endif From e7622cc4148f39ecf06732ef3be5d675a9737c94 Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Sun, 26 Feb 2023 02:51:07 +0100 Subject: [PATCH 012/100] fix guard --- Modules/posixmodule.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index cdc3a4a8e8f945..b06187e12ed0b1 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -13903,7 +13903,7 @@ os_set_inheritable_impl(PyObject *module, int fd, int inheritable) } -#ifndef MS_WINDOWS_NON_DESKTOP +#if defined(MS_WINDOWS) && !defined(MS_WINDOWS_NON_DESKTOP) /*[clinic input] os.get_handle_inheritable -> bool handle: intptr_t @@ -13948,7 +13948,7 @@ os_set_handle_inheritable_impl(PyObject *module, intptr_t handle, } Py_RETURN_NONE; } -#endif /* !MS_WINDOWS_NON_DESKTOP */ +#endif /* !MS_WINDOWS && !MS_WINDOWS_NON_DESKTOP */ /*[clinic input] os.get_blocking -> bool From 7812891ba98ea385225af9ea9a608f6db581c96d Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Sun, 26 Feb 2023 03:05:06 +0100 Subject: [PATCH 013/100] add missing semicolon --- PC/winreg.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PC/winreg.c b/PC/winreg.c index 0bff0f814a30ed..f3b94c8cf79715 100644 --- a/PC/winreg.c +++ b/PC/winreg.c @@ -410,7 +410,7 @@ PyHKEY_Close(PyObject *ob_handle) ((PyHKEYObject*)ob_handle)->hkey = 0; } #ifdef MS_WINDOWS_NON_DESKTOP - rc = ERROR_SUCCESS + rc = ERROR_SUCCESS; #else rc = key ? RegCloseKey(key) : ERROR_SUCCESS; #endif From 3b005f4e6ed92018751dc98da1da0f2d68a8b296 Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Sun, 26 Feb 2023 05:28:29 +0100 Subject: [PATCH 014/100] remove windows console --- Modules/_io/_iomodule.c | 6 +++--- Modules/_io/_iomodule.h | 6 +++--- Modules/_io/winconsoleio.c | 4 ++-- Modules/_posixsubprocess.c | 6 ------ 4 files changed, 8 insertions(+), 14 deletions(-) diff --git a/Modules/_io/_iomodule.c b/Modules/_io/_iomodule.c index 55b6535eb34b66..64dcc009b2a900 100644 --- a/Modules/_io/_iomodule.c +++ b/Modules/_io/_iomodule.c @@ -317,7 +317,7 @@ _io_open_impl(PyObject *module, PyObject *file, const char *mode, _PyIO_State *state = get_io_state(module); { PyObject *RawIO_class = (PyObject *)state->PyFileIO_Type; -#ifdef MS_WINDOWS +#if defined(MS_WINDOWS) && !defined(MS_WINDOWS_NON_DESKTOP) const PyConfig *config = _Py_GetConfig(); if (!config->legacy_windows_stdio && _PyIO_get_console_type(path_or_fd) != '\0') { RawIO_class = (PyObject *)&PyWindowsConsoleIO_Type; @@ -661,7 +661,7 @@ static PyTypeObject* static_types[] = { // PyRawIOBase_Type(PyIOBase_Type) subclasses &_PyBytesIOBuffer_Type, -#ifdef MS_WINDOWS +#if defined(MS_WINDOWS) && !defined(MS_WINDOWS_NON_DESKTOP) &PyWindowsConsoleIO_Type, #endif }; @@ -719,7 +719,7 @@ PyInit__io(void) } // Set type base classes -#ifdef MS_WINDOWS +#if defined(MS_WINDOWS) && !defined(MS_WINDOWS_NON_DESKTOP) PyWindowsConsoleIO_Type.tp_base = &PyRawIOBase_Type; #endif diff --git a/Modules/_io/_iomodule.h b/Modules/_io/_iomodule.h index 02daef9e85677e..fc43ce603d6a93 100644 --- a/Modules/_io/_iomodule.h +++ b/Modules/_io/_iomodule.h @@ -26,9 +26,9 @@ extern PyType_Spec fileio_spec; extern PyType_Spec stringio_spec; extern PyType_Spec textiowrapper_spec; -#ifdef MS_WINDOWS +#if defined(MS_WINDOWS) && !defined(MS_WINDOWS_NON_DESKTOP) extern PyTypeObject PyWindowsConsoleIO_Type; -#endif /* MS_WINDOWS */ +#endif /* MS_WINDOWS && !MS_WINDOWS_NON_DESKTOP */ /* These functions are used as METH_NOARGS methods, are normally called * with args=NULL, and return a new reference. @@ -178,7 +178,7 @@ find_io_state_by_def(PyTypeObject *type) extern _PyIO_State *_PyIO_get_module_state(void); -#ifdef MS_WINDOWS +#if defined(MS_WINDOWS) && !defined(MS_WINDOWS_NON_DESKTOP) extern char _PyIO_get_console_type(PyObject *); #endif diff --git a/Modules/_io/winconsoleio.c b/Modules/_io/winconsoleio.c index 61c6e184eb3bee..1f9447dc002c11 100644 --- a/Modules/_io/winconsoleio.c +++ b/Modules/_io/winconsoleio.c @@ -11,7 +11,7 @@ #include "pycore_fileutils.h" // _Py_BEGIN_SUPPRESS_IPH #include "pycore_object.h" // _PyObject_GC_UNTRACK() -#ifdef MS_WINDOWS +#if defined(MS_WINDOWS) && !defined(MS_WINDOWS_NON_DESKTOP) #include "structmember.h" // PyMemberDef #ifdef HAVE_SYS_TYPES_H @@ -1176,4 +1176,4 @@ PyTypeObject PyWindowsConsoleIO_Type = { 0, /* tp_finalize */ }; -#endif /* MS_WINDOWS */ +#endif /* MS_WINDOWS && !MS_WINDOWS_NON_DESKTOP */ diff --git a/Modules/_posixsubprocess.c b/Modules/_posixsubprocess.c index 962d2117774607..f3ff39215eab76 100644 --- a/Modules/_posixsubprocess.c +++ b/Modules/_posixsubprocess.c @@ -59,12 +59,6 @@ # endif #endif -/* the deprecated posix apis are not available on xbox */ -#ifdef MS_WINDOWS_GAMES -# define dup _dup -# define dup2 _dup2 -#endif - #if defined(__FreeBSD__) || (defined(__APPLE__) && defined(__MACH__)) || defined(__DragonFly__) # define FD_DIR "/dev/fd" #else From fa526b693cebdca07d63443114707c398dab23ef Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Sun, 26 Feb 2023 05:36:46 +0100 Subject: [PATCH 015/100] do not read version from kernel32.dll --- Python/sysmodule.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 78ca7a464da65d..ce26271fe92016 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -1497,6 +1497,9 @@ static PyStructSequence_Desc windows_version_desc = { static PyObject * _sys_getwindowsversion_from_kernel32() { +#ifdef MS_WINDOWS_NON_DESKTOP + return NULL; +#else HANDLE hKernel32; wchar_t kernel32_path[MAX_PATH]; LPVOID verblock; @@ -1530,6 +1533,7 @@ _sys_getwindowsversion_from_kernel32() realBuild = HIWORD(ffi->dwProductVersionLS); PyMem_RawFree(verblock); return Py_BuildValue("(kkk)", realMajor, realMinor, realBuild); +#endif /* MS_WINDOWS_NON_DESKTOP */ } /* Disable deprecation warnings about GetVersionEx as the result is From 36887bcb06678416ac4a26f08d94c3e8090b41bd Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Sun, 26 Feb 2023 10:44:14 +0100 Subject: [PATCH 016/100] apply part of code review --- Modules/_io/_iomodule.c | 6 +++--- Modules/_io/_iomodule.h | 6 +++--- Modules/_io/winconsoleio.c | 4 ++-- Modules/posixmodule.c | 6 +++++- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/Modules/_io/_iomodule.c b/Modules/_io/_iomodule.c index 64dcc009b2a900..7eec97e2912e98 100644 --- a/Modules/_io/_iomodule.c +++ b/Modules/_io/_iomodule.c @@ -317,7 +317,7 @@ _io_open_impl(PyObject *module, PyObject *file, const char *mode, _PyIO_State *state = get_io_state(module); { PyObject *RawIO_class = (PyObject *)state->PyFileIO_Type; -#if defined(MS_WINDOWS) && !defined(MS_WINDOWS_NON_DESKTOP) +#if defined(MS_WINDOWS) && !defined(MS_WINDOWS_GAMES) const PyConfig *config = _Py_GetConfig(); if (!config->legacy_windows_stdio && _PyIO_get_console_type(path_or_fd) != '\0') { RawIO_class = (PyObject *)&PyWindowsConsoleIO_Type; @@ -661,7 +661,7 @@ static PyTypeObject* static_types[] = { // PyRawIOBase_Type(PyIOBase_Type) subclasses &_PyBytesIOBuffer_Type, -#if defined(MS_WINDOWS) && !defined(MS_WINDOWS_NON_DESKTOP) +#if defined(MS_WINDOWS) && !defined(MS_WINDOWS_GAMES) &PyWindowsConsoleIO_Type, #endif }; @@ -719,7 +719,7 @@ PyInit__io(void) } // Set type base classes -#if defined(MS_WINDOWS) && !defined(MS_WINDOWS_NON_DESKTOP) +#if defined(MS_WINDOWS) && !defined(MS_WINDOWS_GAMES) PyWindowsConsoleIO_Type.tp_base = &PyRawIOBase_Type; #endif diff --git a/Modules/_io/_iomodule.h b/Modules/_io/_iomodule.h index fc43ce603d6a93..8bb627de157d87 100644 --- a/Modules/_io/_iomodule.h +++ b/Modules/_io/_iomodule.h @@ -26,9 +26,9 @@ extern PyType_Spec fileio_spec; extern PyType_Spec stringio_spec; extern PyType_Spec textiowrapper_spec; -#if defined(MS_WINDOWS) && !defined(MS_WINDOWS_NON_DESKTOP) +#if defined(MS_WINDOWS) && !defined(MS_WINDOWS_GAMES) extern PyTypeObject PyWindowsConsoleIO_Type; -#endif /* MS_WINDOWS && !MS_WINDOWS_NON_DESKTOP */ +#endif /* MS_WINDOWS && !MS_WINDOWS_GAMES */ /* These functions are used as METH_NOARGS methods, are normally called * with args=NULL, and return a new reference. @@ -178,7 +178,7 @@ find_io_state_by_def(PyTypeObject *type) extern _PyIO_State *_PyIO_get_module_state(void); -#if defined(MS_WINDOWS) && !defined(MS_WINDOWS_NON_DESKTOP) +#if defined(MS_WINDOWS) && !defined(MS_WINDOWS_GAMES) extern char _PyIO_get_console_type(PyObject *); #endif diff --git a/Modules/_io/winconsoleio.c b/Modules/_io/winconsoleio.c index 1f9447dc002c11..062378e1a5f959 100644 --- a/Modules/_io/winconsoleio.c +++ b/Modules/_io/winconsoleio.c @@ -11,7 +11,7 @@ #include "pycore_fileutils.h" // _Py_BEGIN_SUPPRESS_IPH #include "pycore_object.h" // _PyObject_GC_UNTRACK() -#if defined(MS_WINDOWS) && !defined(MS_WINDOWS_NON_DESKTOP) +#if defined(MS_WINDOWS) && !defined(MS_WINDOWS_GAMES) #include "structmember.h" // PyMemberDef #ifdef HAVE_SYS_TYPES_H @@ -1176,4 +1176,4 @@ PyTypeObject PyWindowsConsoleIO_Type = { 0, /* tp_finalize */ }; -#endif /* MS_WINDOWS && !MS_WINDOWS_NON_DESKTOP */ +#endif /* MS_WINDOWS && !MS_WINDOWS_GAMES */ diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index b06187e12ed0b1..9ce15380969ced 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -8402,7 +8402,7 @@ os_getuid_impl(PyObject *module) #endif /* HAVE_GETUID */ -#if defined(MS_WINDOWS) && !defined(MS_WINDOWS_NON_DESKTOP) +#if defined(MS_WINDOWS) #define HAVE_KILL #endif /* MS_WINDOWS && !MS_WINDOWS_NON_DESKTOP */ @@ -8443,6 +8443,9 @@ os_kill_impl(PyObject *module, pid_t pid, Py_ssize_t signal) DWORD err; HANDLE handle; + /* Console processes which share a common console can be sent CTRL+C or + CTRL+BREAK events, provided they handle said events. */ +#if !defined(MS_WINDOWS_NON_DESKTOP) /* Console processes which share a common console can be sent CTRL+C or CTRL+BREAK events, provided they handle said events. */ if (sig == CTRL_C_EVENT || sig == CTRL_BREAK_EVENT) { @@ -8453,6 +8456,7 @@ os_kill_impl(PyObject *module, pid_t pid, Py_ssize_t signal) else Py_RETURN_NONE; } +#endif /* If the signal is outside of what GenerateConsoleCtrlEvent can use, attempt to open and terminate the process. */ From 6fe30185a94cd6ec9cb382767f98bb0ea731229c Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Sun, 26 Feb 2023 10:45:45 +0100 Subject: [PATCH 017/100] reduce diff --- Modules/posixmodule.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 9ce15380969ced..e72c1b848697df 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -8402,7 +8402,7 @@ os_getuid_impl(PyObject *module) #endif /* HAVE_GETUID */ -#if defined(MS_WINDOWS) +#ifdef MS_WINDOWS #define HAVE_KILL #endif /* MS_WINDOWS && !MS_WINDOWS_NON_DESKTOP */ From 849994086a40625009d52cef810b6948a93ce91c Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Sun, 26 Feb 2023 11:00:01 +0100 Subject: [PATCH 018/100] regenerate argument clinic --- Modules/_io/clinic/winconsoleio.c.h | 42 ++++++++++++++--------------- Modules/clinic/posixmodule.c.h | 14 +++++----- Modules/posixmodule.c | 12 +++------ 3 files changed, 31 insertions(+), 37 deletions(-) diff --git a/Modules/_io/clinic/winconsoleio.c.h b/Modules/_io/clinic/winconsoleio.c.h index df834dbde40f5b..da2d639e00ed32 100644 --- a/Modules/_io/clinic/winconsoleio.c.h +++ b/Modules/_io/clinic/winconsoleio.c.h @@ -8,7 +8,7 @@ preserve #endif -#if defined(MS_WINDOWS) +#if (defined(MS_WINDOWS) && !defined(MS_WINDOWS_GAMES)) PyDoc_STRVAR(_io__WindowsConsoleIO_close__doc__, "close($self, /)\n" @@ -31,9 +31,9 @@ _io__WindowsConsoleIO_close(winconsoleio *self, PyObject *Py_UNUSED(ignored)) return _io__WindowsConsoleIO_close_impl(self); } -#endif /* defined(MS_WINDOWS) */ +#endif /* (defined(MS_WINDOWS) && !defined(MS_WINDOWS_GAMES)) */ -#if defined(MS_WINDOWS) +#if (defined(MS_WINDOWS) && !defined(MS_WINDOWS_GAMES)) PyDoc_STRVAR(_io__WindowsConsoleIO___init____doc__, "_WindowsConsoleIO(file, mode=\'r\', closefd=True, opener=None)\n" @@ -131,9 +131,9 @@ _io__WindowsConsoleIO___init__(PyObject *self, PyObject *args, PyObject *kwargs) return return_value; } -#endif /* defined(MS_WINDOWS) */ +#endif /* (defined(MS_WINDOWS) && !defined(MS_WINDOWS_GAMES)) */ -#if defined(MS_WINDOWS) +#if (defined(MS_WINDOWS) && !defined(MS_WINDOWS_GAMES)) PyDoc_STRVAR(_io__WindowsConsoleIO_fileno__doc__, "fileno($self, /)\n" @@ -153,9 +153,9 @@ _io__WindowsConsoleIO_fileno(winconsoleio *self, PyObject *Py_UNUSED(ignored)) return _io__WindowsConsoleIO_fileno_impl(self); } -#endif /* defined(MS_WINDOWS) */ +#endif /* (defined(MS_WINDOWS) && !defined(MS_WINDOWS_GAMES)) */ -#if defined(MS_WINDOWS) +#if (defined(MS_WINDOWS) && !defined(MS_WINDOWS_GAMES)) PyDoc_STRVAR(_io__WindowsConsoleIO_readable__doc__, "readable($self, /)\n" @@ -175,9 +175,9 @@ _io__WindowsConsoleIO_readable(winconsoleio *self, PyObject *Py_UNUSED(ignored)) return _io__WindowsConsoleIO_readable_impl(self); } -#endif /* defined(MS_WINDOWS) */ +#endif /* (defined(MS_WINDOWS) && !defined(MS_WINDOWS_GAMES)) */ -#if defined(MS_WINDOWS) +#if (defined(MS_WINDOWS) && !defined(MS_WINDOWS_GAMES)) PyDoc_STRVAR(_io__WindowsConsoleIO_writable__doc__, "writable($self, /)\n" @@ -197,9 +197,9 @@ _io__WindowsConsoleIO_writable(winconsoleio *self, PyObject *Py_UNUSED(ignored)) return _io__WindowsConsoleIO_writable_impl(self); } -#endif /* defined(MS_WINDOWS) */ +#endif /* (defined(MS_WINDOWS) && !defined(MS_WINDOWS_GAMES)) */ -#if defined(MS_WINDOWS) +#if (defined(MS_WINDOWS) && !defined(MS_WINDOWS_GAMES)) PyDoc_STRVAR(_io__WindowsConsoleIO_readinto__doc__, "readinto($self, buffer, /)\n" @@ -239,9 +239,9 @@ _io__WindowsConsoleIO_readinto(winconsoleio *self, PyObject *arg) return return_value; } -#endif /* defined(MS_WINDOWS) */ +#endif /* (defined(MS_WINDOWS) && !defined(MS_WINDOWS_GAMES)) */ -#if defined(MS_WINDOWS) +#if (defined(MS_WINDOWS) && !defined(MS_WINDOWS_GAMES)) PyDoc_STRVAR(_io__WindowsConsoleIO_readall__doc__, "readall($self, /)\n" @@ -263,9 +263,9 @@ _io__WindowsConsoleIO_readall(winconsoleio *self, PyObject *Py_UNUSED(ignored)) return _io__WindowsConsoleIO_readall_impl(self); } -#endif /* defined(MS_WINDOWS) */ +#endif /* (defined(MS_WINDOWS) && !defined(MS_WINDOWS_GAMES)) */ -#if defined(MS_WINDOWS) +#if (defined(MS_WINDOWS) && !defined(MS_WINDOWS_GAMES)) PyDoc_STRVAR(_io__WindowsConsoleIO_read__doc__, "read($self, size=-1, /)\n" @@ -305,9 +305,9 @@ _io__WindowsConsoleIO_read(winconsoleio *self, PyObject *const *args, Py_ssize_t return return_value; } -#endif /* defined(MS_WINDOWS) */ +#endif /* (defined(MS_WINDOWS) && !defined(MS_WINDOWS_GAMES)) */ -#if defined(MS_WINDOWS) +#if (defined(MS_WINDOWS) && !defined(MS_WINDOWS_GAMES)) PyDoc_STRVAR(_io__WindowsConsoleIO_write__doc__, "write($self, b, /)\n" @@ -348,9 +348,9 @@ _io__WindowsConsoleIO_write(winconsoleio *self, PyObject *arg) return return_value; } -#endif /* defined(MS_WINDOWS) */ +#endif /* (defined(MS_WINDOWS) && !defined(MS_WINDOWS_GAMES)) */ -#if defined(MS_WINDOWS) +#if (defined(MS_WINDOWS) && !defined(MS_WINDOWS_GAMES)) PyDoc_STRVAR(_io__WindowsConsoleIO_isatty__doc__, "isatty($self, /)\n" @@ -370,7 +370,7 @@ _io__WindowsConsoleIO_isatty(winconsoleio *self, PyObject *Py_UNUSED(ignored)) return _io__WindowsConsoleIO_isatty_impl(self); } -#endif /* defined(MS_WINDOWS) */ +#endif /* (defined(MS_WINDOWS) && !defined(MS_WINDOWS_GAMES)) */ #ifndef _IO__WINDOWSCONSOLEIO_CLOSE_METHODDEF #define _IO__WINDOWSCONSOLEIO_CLOSE_METHODDEF @@ -407,4 +407,4 @@ _io__WindowsConsoleIO_isatty(winconsoleio *self, PyObject *Py_UNUSED(ignored)) #ifndef _IO__WINDOWSCONSOLEIO_ISATTY_METHODDEF #define _IO__WINDOWSCONSOLEIO_ISATTY_METHODDEF #endif /* !defined(_IO__WINDOWSCONSOLEIO_ISATTY_METHODDEF) */ -/*[clinic end generated code: output=4920e9068e0cf08a input=a9049054013a1b77]*/ +/*[clinic end generated code: output=380ec40c9ff821ed input=a9049054013a1b77]*/ diff --git a/Modules/clinic/posixmodule.c.h b/Modules/clinic/posixmodule.c.h index dcd25c28370c93..23ee3e5972dfed 100644 --- a/Modules/clinic/posixmodule.c.h +++ b/Modules/clinic/posixmodule.c.h @@ -1730,7 +1730,7 @@ os__getvolumepathname(PyObject *module, PyObject *const *args, Py_ssize_t nargs, #endif /* defined(MS_WINDOWS) */ -#if defined(MS_WINDOWS) +#if defined(MS_WINDOWS) && !defined(MS_WINDOWS_GAMES) PyDoc_STRVAR(os__path_splitroot__doc__, "_path_splitroot($module, /, path)\n" @@ -1792,7 +1792,7 @@ os__path_splitroot(PyObject *module, PyObject *const *args, Py_ssize_t nargs, Py return return_value; } -#endif /* defined(MS_WINDOWS) */ +#endif /* defined(MS_WINDOWS) && !defined(MS_WINDOWS_GAMES) */ #if defined(MS_WINDOWS) @@ -10332,7 +10332,7 @@ os_set_inheritable(PyObject *module, PyObject *const *args, Py_ssize_t nargs) return return_value; } -#if defined(MS_WINDOWS) +#if (defined(MS_WINDOWS) && !defined(MS_WINDOWS_NON_DESKTOP)) PyDoc_STRVAR(os_get_handle_inheritable__doc__, "get_handle_inheritable($module, handle, /)\n" @@ -10366,9 +10366,9 @@ os_get_handle_inheritable(PyObject *module, PyObject *arg) return return_value; } -#endif /* defined(MS_WINDOWS) */ +#endif /* (defined(MS_WINDOWS) && !defined(MS_WINDOWS_NON_DESKTOP)) */ -#if defined(MS_WINDOWS) +#if (defined(MS_WINDOWS) && !defined(MS_WINDOWS_NON_DESKTOP)) PyDoc_STRVAR(os_set_handle_inheritable__doc__, "set_handle_inheritable($module, handle, inheritable, /)\n" @@ -10400,7 +10400,7 @@ os_set_handle_inheritable(PyObject *module, PyObject *const *args, Py_ssize_t na return return_value; } -#endif /* defined(MS_WINDOWS) */ +#endif /* (defined(MS_WINDOWS) && !defined(MS_WINDOWS_NON_DESKTOP)) */ PyDoc_STRVAR(os_get_blocking__doc__, "get_blocking($module, fd, /)\n" @@ -11796,4 +11796,4 @@ os_waitstatus_to_exitcode(PyObject *module, PyObject *const *args, Py_ssize_t na #ifndef OS_WAITSTATUS_TO_EXITCODE_METHODDEF #define OS_WAITSTATUS_TO_EXITCODE_METHODDEF #endif /* !defined(OS_WAITSTATUS_TO_EXITCODE_METHODDEF) */ -/*[clinic end generated code: output=1b0eb6a76b1a0e28 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=39a9280dd816bbac input=a9049054013a1b77]*/ diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index e72c1b848697df..b20c0ef73c5002 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -4452,6 +4452,7 @@ os__getvolumepathname_impl(PyObject *module, path_t *path) return result; } +#ifndef MS_WINDOWS_GAMES /*[clinic input] os._path_splitroot @@ -4479,18 +4480,9 @@ os__path_splitroot_impl(PyObject *module, path_t *path) *p = L'\\'; } -#ifdef MS_WINDOWS_GAMES - /* this does not handle persistent local storage */ - ret = E_FAIL; - if ((wcsncmp(buffer, L"G:\\", 3) == 0) || (wcsncmp(buffer, L"D:\\", 3) == 0) || (wcsncmp(buffer, L"T:\\", 3) == 0)) { - end = buffer + 3; - ret = S_OK; - } -#else Py_BEGIN_ALLOW_THREADS ret = PathCchSkipRoot(buffer, &end); Py_END_ALLOW_THREADS -#endif if (FAILED(ret)) { result = Py_BuildValue("sO", "", path->object); } else if (end != buffer) { @@ -4507,6 +4499,8 @@ os__path_splitroot_impl(PyObject *module, path_t *path) return result; } +#endif /* MS_WINDOWS_GAMES */ + /*[clinic input] os._path_isdir From 69f0a2cfccbb2663b8b6d58ee0cbc289c8fed0d8 Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Sun, 26 Feb 2023 11:38:14 +0100 Subject: [PATCH 019/100] include winioctl --- Modules/posixmodule.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index b20c0ef73c5002..3c6af26a52ee88 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -10,18 +10,6 @@ #define PY_SSIZE_T_CLEAN #include "Python.h" -// Include before pycore internal headers. FSCTL_GET_REPARSE_POINT -// is not exported by if the WIN32_LEAN_AND_MEAN macro is defined, -// whereas pycore_condvar.h defines the WIN32_LEAN_AND_MEAN macro. -#ifdef MS_WINDOWS -# include -# include -# include // UNLEN -# include "osdefs.h" // SEP -# ifndef MS_WINDOWS_NON_DESKTOP -# define HAVE_SYMLINK -# endif -#endif #ifdef __VXWORKS__ # include "pycore_bitutils.h" // _Py_popcount32() @@ -36,6 +24,17 @@ #include "pycore_pystate.h" // _PyInterpreterState_GET() #include "pycore_signal.h" // Py_NSIG +#ifdef MS_WINDOWS +# include +# include +# include +# include // UNLEN +# include "osdefs.h" // SEP +# ifndef MS_WINDOWS_NON_DESKTOP +# define HAVE_SYMLINK +# endif +#endif + #include "structmember.h" // PyMemberDef #ifndef MS_WINDOWS # include "posixmodule.h" From f43ce54f92cef9ab74b7c0c4031cd24fa4848d1f Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Sun, 26 Feb 2023 11:48:14 +0100 Subject: [PATCH 020/100] exclude dll_directory --- Modules/clinic/posixmodule.c.h | 10 +++++----- Modules/posixmodule.c | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Modules/clinic/posixmodule.c.h b/Modules/clinic/posixmodule.c.h index 23ee3e5972dfed..16e2968b5eb1b1 100644 --- a/Modules/clinic/posixmodule.c.h +++ b/Modules/clinic/posixmodule.c.h @@ -10988,7 +10988,7 @@ os_getrandom(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject #endif /* defined(HAVE_GETRANDOM_SYSCALL) */ -#if defined(MS_WINDOWS) +#if (defined(MS_WINDOWS) && !defined(MS_WINDOWS_NON_DESKTOP)) PyDoc_STRVAR(os__add_dll_directory__doc__, "_add_dll_directory($module, /, path)\n" @@ -11057,9 +11057,9 @@ os__add_dll_directory(PyObject *module, PyObject *const *args, Py_ssize_t nargs, return return_value; } -#endif /* defined(MS_WINDOWS) */ +#endif /* (defined(MS_WINDOWS) && !defined(MS_WINDOWS_NON_DESKTOP)) */ -#if defined(MS_WINDOWS) +#if (defined(MS_WINDOWS) && !defined(MS_WINDOWS_NON_DESKTOP)) PyDoc_STRVAR(os__remove_dll_directory__doc__, "_remove_dll_directory($module, /, cookie)\n" @@ -11120,7 +11120,7 @@ os__remove_dll_directory(PyObject *module, PyObject *const *args, Py_ssize_t nar return return_value; } -#endif /* defined(MS_WINDOWS) */ +#endif /* (defined(MS_WINDOWS) && !defined(MS_WINDOWS_NON_DESKTOP)) */ #if (defined(WIFEXITED) || defined(MS_WINDOWS)) @@ -11796,4 +11796,4 @@ os_waitstatus_to_exitcode(PyObject *module, PyObject *const *args, Py_ssize_t na #ifndef OS_WAITSTATUS_TO_EXITCODE_METHODDEF #define OS_WAITSTATUS_TO_EXITCODE_METHODDEF #endif /* !defined(OS_WAITSTATUS_TO_EXITCODE_METHODDEF) */ -/*[clinic end generated code: output=39a9280dd816bbac input=a9049054013a1b77]*/ +/*[clinic end generated code: output=ae3aca6d4222b790 input=a9049054013a1b77]*/ diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 3c6af26a52ee88..5490d9e1b5f4b1 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -15077,7 +15077,7 @@ os_getrandom_impl(PyObject *module, Py_ssize_t size, int flags) } #endif /* HAVE_GETRANDOM_SYSCALL */ -#ifdef MS_WINDOWS +#if defined(MS_WINDOWS) && !defined(MS_WINDOWS_NON_DESKTOP) /* bpo-36085: Helper functions for managing DLL search directories * on win32 */ @@ -15187,7 +15187,7 @@ os__remove_dll_directory_impl(PyObject *module, PyObject *cookie) Py_RETURN_NONE; } -#endif +#endif /* MS_WINDOWS && !MS_WINDOWS_NON_DESKTOP */ /* Only check if WIFEXITED is available: expect that it comes From 43cf0a5951f6b7229af8de0f039ac41dbe69d616 Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Sun, 26 Feb 2023 12:14:40 +0100 Subject: [PATCH 021/100] patch mscvrtmodule --- Modules/faulthandler.c | 2 +- PC/clinic/msvcrtmodule.c.h | 42 +++++++++++++++++++++++++++++++++++++- PC/msvcrtmodule.c | 22 ++++++++++++++++++++ 3 files changed, 64 insertions(+), 2 deletions(-) diff --git a/Modules/faulthandler.c b/Modules/faulthandler.c index 5309a3728c5e07..ba03e979b5f403 100644 --- a/Modules/faulthandler.c +++ b/Modules/faulthandler.c @@ -953,7 +953,7 @@ faulthandler_unregister_py(PyObject *self, PyObject *args) static void faulthandler_suppress_crash_report(void) { -#ifdef MS_WINDOWS +#if defined(MS_WINDOWS) && !defined(MS_WINDOWS_GAMES) UINT mode; /* Configure Windows to not display the Windows Error Reporting dialog */ diff --git a/PC/clinic/msvcrtmodule.c.h b/PC/clinic/msvcrtmodule.c.h index d808ef0bbd0ffe..704bb7f8fbd4b1 100644 --- a/PC/clinic/msvcrtmodule.c.h +++ b/PC/clinic/msvcrtmodule.c.h @@ -261,6 +261,8 @@ msvcrt_getch(PyObject *module, PyObject *Py_UNUSED(ignored)) return return_value; } +#if !defined(MS_WINDOWS_GAMES) + PyDoc_STRVAR(msvcrt_getwch__doc__, "getwch($module, /)\n" "--\n" @@ -285,6 +287,8 @@ msvcrt_getwch(PyObject *module, PyObject *Py_UNUSED(ignored)) return return_value; } +#endif /* !defined(MS_WINDOWS_GAMES) */ + PyDoc_STRVAR(msvcrt_getche__doc__, "getche($module, /)\n" "--\n" @@ -309,6 +313,8 @@ msvcrt_getche(PyObject *module, PyObject *Py_UNUSED(ignored)) return return_value; } +#if !defined(MS_WINDOWS_GAMES) + PyDoc_STRVAR(msvcrt_getwche__doc__, "getwche($module, /)\n" "--\n" @@ -333,6 +339,8 @@ msvcrt_getwche(PyObject *module, PyObject *Py_UNUSED(ignored)) return return_value; } +#endif /* !defined(MS_WINDOWS_GAMES) */ + PyDoc_STRVAR(msvcrt_putch__doc__, "putch($module, char, /)\n" "--\n" @@ -367,6 +375,8 @@ msvcrt_putch(PyObject *module, PyObject *arg) return return_value; } +#if !defined(MS_WINDOWS_GAMES) + PyDoc_STRVAR(msvcrt_putwch__doc__, "putwch($module, unicode_char, /)\n" "--\n" @@ -403,6 +413,8 @@ msvcrt_putwch(PyObject *module, PyObject *arg) return return_value; } +#endif /* !defined(MS_WINDOWS_GAMES) */ + PyDoc_STRVAR(msvcrt_ungetch__doc__, "ungetch($module, char, /)\n" "--\n" @@ -441,6 +453,8 @@ msvcrt_ungetch(PyObject *module, PyObject *arg) return return_value; } +#if !defined(MS_WINDOWS_GAMES) + PyDoc_STRVAR(msvcrt_ungetwch__doc__, "ungetwch($module, unicode_char, /)\n" "--\n" @@ -477,6 +491,8 @@ msvcrt_ungetwch(PyObject *module, PyObject *arg) return return_value; } +#endif /* !defined(MS_WINDOWS_GAMES) */ + #if defined(_DEBUG) PyDoc_STRVAR(msvcrt_CrtSetReportFile__doc__, @@ -610,6 +626,8 @@ msvcrt_set_error_mode(PyObject *module, PyObject *arg) #endif /* defined(_DEBUG) */ +#if !defined(MS_WINDOWS_NON_DESKTOP) + PyDoc_STRVAR(msvcrt_GetErrorMode__doc__, "GetErrorMode($module, /)\n" "--\n" @@ -628,6 +646,8 @@ msvcrt_GetErrorMode(PyObject *module, PyObject *Py_UNUSED(ignored)) return msvcrt_GetErrorMode_impl(module); } +#endif /* !defined(MS_WINDOWS_NON_DESKTOP) */ + PyDoc_STRVAR(msvcrt_SetErrorMode__doc__, "SetErrorMode($module, mode, /)\n" "--\n" @@ -656,6 +676,22 @@ msvcrt_SetErrorMode(PyObject *module, PyObject *arg) return return_value; } +#ifndef MSVCRT_GETWCH_METHODDEF + #define MSVCRT_GETWCH_METHODDEF +#endif /* !defined(MSVCRT_GETWCH_METHODDEF) */ + +#ifndef MSVCRT_GETWCHE_METHODDEF + #define MSVCRT_GETWCHE_METHODDEF +#endif /* !defined(MSVCRT_GETWCHE_METHODDEF) */ + +#ifndef MSVCRT_PUTWCH_METHODDEF + #define MSVCRT_PUTWCH_METHODDEF +#endif /* !defined(MSVCRT_PUTWCH_METHODDEF) */ + +#ifndef MSVCRT_UNGETWCH_METHODDEF + #define MSVCRT_UNGETWCH_METHODDEF +#endif /* !defined(MSVCRT_UNGETWCH_METHODDEF) */ + #ifndef MSVCRT_CRTSETREPORTFILE_METHODDEF #define MSVCRT_CRTSETREPORTFILE_METHODDEF #endif /* !defined(MSVCRT_CRTSETREPORTFILE_METHODDEF) */ @@ -667,4 +703,8 @@ msvcrt_SetErrorMode(PyObject *module, PyObject *arg) #ifndef MSVCRT_SET_ERROR_MODE_METHODDEF #define MSVCRT_SET_ERROR_MODE_METHODDEF #endif /* !defined(MSVCRT_SET_ERROR_MODE_METHODDEF) */ -/*[clinic end generated code: output=204bae9fee7f6124 input=a9049054013a1b77]*/ + +#ifndef MSVCRT_GETERRORMODE_METHODDEF + #define MSVCRT_GETERRORMODE_METHODDEF +#endif /* !defined(MSVCRT_GETERRORMODE_METHODDEF) */ +/*[clinic end generated code: output=ddb03bbe9ff66ac2 input=a9049054013a1b77]*/ diff --git a/PC/msvcrtmodule.c b/PC/msvcrtmodule.c index 988d9c95aaa22e..7bc4e2f2f94dc8 100644 --- a/PC/msvcrtmodule.c +++ b/PC/msvcrtmodule.c @@ -253,6 +253,8 @@ msvcrt_getch_impl(PyObject *module) return ch; } +#ifndef MS_WINDOWS_GAMES + /*[clinic input] msvcrt.getwch -> wchar_t @@ -271,6 +273,8 @@ msvcrt_getwch_impl(PyObject *module) return ch; } +#endif /* MS_WINDOWS_GAMES */ + /*[clinic input] msvcrt.getche -> byte_char @@ -289,6 +293,8 @@ msvcrt_getche_impl(PyObject *module) return ch; } +#ifndef MS_WINDOWS_GAMES + /*[clinic input] msvcrt.getwche -> wchar_t @@ -307,6 +313,8 @@ msvcrt_getwche_impl(PyObject *module) return ch; } +#endif /* MS_WINDOWS_GAMES */ + /*[clinic input] msvcrt.putch @@ -326,6 +334,8 @@ msvcrt_putch_impl(PyObject *module, char char_value) Py_RETURN_NONE; } +#ifndef MS_WINDOWS_GAMES + /*[clinic input] msvcrt.putwch @@ -346,6 +356,8 @@ msvcrt_putwch_impl(PyObject *module, int unicode_char) } +#endif /* MS_WINDOWS_GAMES */ + /*[clinic input] msvcrt.ungetch @@ -374,6 +386,8 @@ msvcrt_ungetch_impl(PyObject *module, char char_value) Py_RETURN_NONE; } +#ifndef MS_WINDOWS_GAMES + /*[clinic input] msvcrt.ungetwch @@ -398,6 +412,8 @@ msvcrt_ungetwch_impl(PyObject *module, int unicode_char) Py_RETURN_NONE; } +#endif /* MS_WINDOWS_GAMES */ + #ifdef _DEBUG /*[clinic input] msvcrt.CrtSetReportFile -> HANDLE @@ -475,6 +491,8 @@ msvcrt_set_error_mode_impl(PyObject *module, int mode) } #endif /* _DEBUG */ +#ifndef MS_WINDOWS_NON_DESKTOP + /*[clinic input] msvcrt.GetErrorMode @@ -494,6 +512,8 @@ msvcrt_GetErrorMode_impl(PyObject *module) return PyLong_FromUnsignedLong(res); } +#endif /* MS_WINDOWS_NON_DESKTOP */ + /*[clinic input] msvcrt.SetErrorMode @@ -601,10 +621,12 @@ PyInit_msvcrt(void) insertint(d, "LK_NBRLCK", _LK_NBRLCK); insertint(d, "LK_RLCK", _LK_RLCK); insertint(d, "LK_UNLCK", _LK_UNLCK); +#ifndef MS_WINDOWS_GAMES insertint(d, "SEM_FAILCRITICALERRORS", SEM_FAILCRITICALERRORS); insertint(d, "SEM_NOALIGNMENTFAULTEXCEPT", SEM_NOALIGNMENTFAULTEXCEPT); insertint(d, "SEM_NOGPFAULTERRORBOX", SEM_NOGPFAULTERRORBOX); insertint(d, "SEM_NOOPENFILEERRORBOX", SEM_NOOPENFILEERRORBOX); +#endif #ifdef _DEBUG insertint(d, "CRT_WARN", _CRT_WARN); insertint(d, "CRT_ERROR", _CRT_ERROR); From 8f717eaf1aa02a3e7d707c161aa5484592d3465e Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Sun, 26 Feb 2023 12:36:54 +0100 Subject: [PATCH 022/100] patch _winapi --- Modules/_winapi.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/Modules/_winapi.c b/Modules/_winapi.c index f4d982b15d402a..7bafc0ba5a9a7a 100644 --- a/Modules/_winapi.c +++ b/Modules/_winapi.c @@ -39,8 +39,11 @@ #include "structmember.h" // PyMemberDef +#ifndef WINDOWS_LEAN_AND_MEAN #define WINDOWS_LEAN_AND_MEAN +#endif #include "windows.h" +#include #include #include "winreparse.h" @@ -70,13 +73,22 @@ static BOOL (CALLBACK *Py_CancelIoEx)(HANDLE, LPOVERLAPPED); static int check_CancelIoEx() { +#ifdef MS_WINDOWS_GAMES + Py_CancelIoEx = &CancelIoEx; + has_CancelIoEx = TRUE; +#else if (has_CancelIoEx == -1) { - HINSTANCE hKernel32 = GetModuleHandle("KERNEL32"); - * (FARPROC *) &Py_CancelIoEx = GetProcAddress(hKernel32, - "CancelIoEx"); - has_CancelIoEx = (Py_CancelIoEx != NULL); + HINSTANCE hKernel32 = GetModuleHandleA("KERNEL32"); + if (hKernel32) { + * (FARPROC *) &Py_CancelIoEx = GetProcAddress(hKernel32, + "CancelIoEx"); + has_CancelIoEx = (Py_CancelIoEx != NULL); + } else { + has_CancelIoEx = 0; + } } +#endif return has_CancelIoEx; } @@ -655,8 +667,10 @@ _winapi_CreateJunction_impl(PyObject *module, LPCWSTR src_path, cleanup: ret = GetLastError(); - CloseHandle(token); - CloseHandle(junction); + if (token != NULL) + CloseHandle(token); + if (junction != NULL) + CloseHandle(junction); PyMem_RawFree(rdb); if (ret != 0) @@ -2192,8 +2206,10 @@ static int winapi_exec(PyObject *m) WINAPI_CONSTANT(F_DWORD, SEC_NOCACHE); WINAPI_CONSTANT(F_DWORD, SEC_RESERVE); WINAPI_CONSTANT(F_DWORD, SEC_WRITECOMBINE); +#ifndef MS_WINDOWS_NON_DESKTOP WINAPI_CONSTANT(F_DWORD, STARTF_USESHOWWINDOW); WINAPI_CONSTANT(F_DWORD, STARTF_USESTDHANDLES); +#endif WINAPI_CONSTANT(F_DWORD, STD_INPUT_HANDLE); WINAPI_CONSTANT(F_DWORD, STD_OUTPUT_HANDLE); WINAPI_CONSTANT(F_DWORD, STD_ERROR_HANDLE); From 29d5b6593cf00c5c4596766924039226110da2fa Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Sun, 26 Feb 2023 11:43:57 +0000 Subject: [PATCH 023/100] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by?= =?UTF-8?q?=20blurb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../2023-02-26-11-43-56.gh-issue-102255.cRnI5x.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2023-02-26-11-43-56.gh-issue-102255.cRnI5x.rst diff --git a/Misc/NEWS.d/next/Core and Builtins/2023-02-26-11-43-56.gh-issue-102255.cRnI5x.rst b/Misc/NEWS.d/next/Core and Builtins/2023-02-26-11-43-56.gh-issue-102255.cRnI5x.rst new file mode 100644 index 00000000000000..daabc3c15f6ee2 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2023-02-26-11-43-56.gh-issue-102255.cRnI5x.rst @@ -0,0 +1 @@ +Improve build support for the Xbox. Patch by Max Bachmann. From 8a7350073e8728e890f4500b1d3e63abb52b804b Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Sun, 26 Feb 2023 12:58:11 +0100 Subject: [PATCH 024/100] patch out tzset --- Modules/timemodule.c | 4 ++++ Python/pylifecycle.c | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Modules/timemodule.c b/Modules/timemodule.c index 71c5ebd6504367..c1473583b795bc 100644 --- a/Modules/timemodule.c +++ b/Modules/timemodule.c @@ -1137,7 +1137,9 @@ time_tzset(PyObject *self, PyObject *unused) return NULL; } +#ifndef MS_WINDOWS_NON_DESKTOP tzset(); +#endif /* Reset timezone, altzone, daylight and tzname */ if (init_timezone(m) < 0) { @@ -1755,7 +1757,9 @@ init_timezone(PyObject *m) */ #ifdef HAVE_DECL_TZNAME PyObject *otz0, *otz1; +#ifndef MS_WINDOWS_NON_DESKTOP tzset(); +#endif PyModule_AddIntConstant(m, "timezone", _Py_timezone); #ifdef HAVE_ALTZONE PyModule_AddIntConstant(m, "altzone", altzone); diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index 5e93c20afe4b45..18bd148446d5fb 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -2295,7 +2295,7 @@ create_stdio(const PyConfig *config, PyObject* io, raw = Py_NewRef(buf); } -#ifdef MS_WINDOWS +#if defined(MS_WINDOWS) && !defined(MS_WINDOWS_GAMES) /* Windows console IO is always UTF-8 encoded */ PyTypeObject *winconsoleio_type = (PyTypeObject *)_PyImport_GetModuleAttr( &_Py_ID(_io), &_Py_ID(_WindowsConsoleIO)); From 92ae5ef509ef7e7e7ada352dcd1ca9d91dfdea93 Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Sun, 26 Feb 2023 13:09:53 +0100 Subject: [PATCH 025/100] patch support_wsa_no_inherit --- Modules/socketmodule.c | 6 ++++++ Parser/myreadline.c | 4 ++-- Python/initconfig.c | 8 ++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c index 2d300f19436b1a..65d567b8e256ca 100644 --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -5459,6 +5459,7 @@ sock_initobj_impl(PySocketSockObject *self, int family, int type, int proto, return -1; } +#ifndef MS_WINDOWS_NON_DESKTOP if (!support_wsa_no_inherit) { if (!SetHandleInformation((HANDLE)fd, HANDLE_FLAG_INHERIT, 0)) { closesocket(fd); @@ -5466,6 +5467,7 @@ sock_initobj_impl(PySocketSockObject *self, int family, int type, int proto, return -1; } } +#endif #else /* UNIX */ Py_BEGIN_ALLOW_THREADS @@ -7343,7 +7345,11 @@ PyInit__socket(void) #ifdef MS_WINDOWS if (support_wsa_no_inherit == -1) { +#ifdef MS_WINDOWS_NON_DESKTOP + support_wsa_no_inherit = 1; +#else support_wsa_no_inherit = IsWindows7SP1OrGreater(); +#endif } #endif diff --git a/Parser/myreadline.c b/Parser/myreadline.c index 80f67b206d8911..98be9c16dfe12a 100644 --- a/Parser/myreadline.c +++ b/Parser/myreadline.c @@ -114,7 +114,7 @@ my_fgets(PyThreadState* tstate, char *buf, int len, FILE *fp) /* NOTREACHED */ } -#ifdef MS_WINDOWS +#if defined(MS_WINDOWS) && !defined(MS_WINDOWS_GAMES) /* Readline implementation using ReadConsoleW */ extern char _get_console_type(HANDLE handle); @@ -252,7 +252,7 @@ PyOS_StdioReadline(FILE *sys_stdin, FILE *sys_stdout, const char *prompt) PyThreadState *tstate = _PyOS_ReadlineTState; assert(tstate != NULL); -#ifdef MS_WINDOWS +#if defined(MS_WINDOWS) && !defined(MS_WINDOWS_GAMES) const PyConfig *config = _PyInterpreterState_GetConfig(tstate->interp); if (!config->legacy_windows_stdio && sys_stdin == stdin) { HANDLE hStdIn, hStdErr; diff --git a/Python/initconfig.c b/Python/initconfig.c index acc8ee2c2460a9..2706242a66c5e4 100644 --- a/Python/initconfig.c +++ b/Python/initconfig.c @@ -825,8 +825,12 @@ config_init_defaults(PyConfig *config) config->buffered_stdio = 1; config->pathconfig_warnings = 1; #ifdef MS_WINDOWS +#ifdef MS_WINDOWS_GAMES + config->legacy_windows_stdio = 1; +#else config->legacy_windows_stdio = 0; #endif +#endif } @@ -860,8 +864,12 @@ PyConfig_InitIsolatedConfig(PyConfig *config) config->safe_path = 1; config->pathconfig_warnings = 0; #ifdef MS_WINDOWS +#ifdef MS_WINDOWS_GAMES + config->legacy_windows_stdio = 1; +#else config->legacy_windows_stdio = 0; #endif +#endif } From f27fe954e729d78c84ec7260cfdaad4d0add5105 Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Sun, 26 Feb 2023 13:53:59 +0100 Subject: [PATCH 026/100] patch scoketmodule --- Modules/socketmodule.c | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c index 65d567b8e256ca..f019cf625bdb54 100644 --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -348,13 +348,18 @@ remove_unusable_flags(PyObject *m) { PyObject *dict; OSVERSIONINFOEX info; - DWORDLONG dwlConditionMask; dict = PyModule_GetDict(m); if (dict == NULL) { return -1; } - +#ifdef MS_WINDOWS_NON_DESKTOP + info.dwOSVersionInfoSize = sizeof(info); + if (!GetVersionExW((OSVERSIONINFOW*) &info)) { + PyErr_SetFromWindowsErr(0); + return -1; + } +#else /* set to Windows 10, except BuildNumber. */ memset(&info, 0, sizeof(info)); info.dwOSVersionInfoSize = sizeof(info); @@ -362,19 +367,25 @@ remove_unusable_flags(PyObject *m) info.dwMinorVersion = 0; /* set Condition Mask */ - dwlConditionMask = 0; + DWORDLONG dwlConditionMask = 0; VER_SET_CONDITION(dwlConditionMask, VER_MAJORVERSION, VER_GREATER_EQUAL); VER_SET_CONDITION(dwlConditionMask, VER_MINORVERSION, VER_GREATER_EQUAL); VER_SET_CONDITION(dwlConditionMask, VER_BUILDNUMBER, VER_GREATER_EQUAL); +#endif for (int i=0; i= 10) && (info.dwMinorVersion >= 0) && (info.dwBuildNumber >= win_runtime_flags[i].build_number); +#endif + if (isSupported) { break; } else { @@ -497,7 +508,7 @@ remove_unusable_flags(PyObject *m) #endif #endif -#ifdef MS_WINDOWS +#if defined(MS_WINDOWS) && !defined(MS_WINDOWS_NON_DESKTOP) #define sockaddr_rc SOCKADDR_BTH_REDEF #define USE_BLUETOOTH 1 @@ -2874,11 +2885,13 @@ sock_accept(PySocketSockObject *s, PyObject *Py_UNUSED(ignored)) newfd = ctx.result; #ifdef MS_WINDOWS +#ifndef MS_WINDOWS_NON_DESKTOP if (!SetHandleInformation((HANDLE)newfd, HANDLE_FLAG_INHERIT, 0)) { PyErr_SetFromWindowsErr(0); SOCKETCLOSE(newfd); goto finally; } +#endif #else #if defined(HAVE_ACCEPT4) && defined(SOCK_CLOEXEC) @@ -6182,11 +6195,13 @@ socket_dup(PyObject *self, PyObject *fdobj) if (newfd == INVALID_SOCKET) return set_error(); +#ifndef MS_WINDOWS_NON_DESKTOP if (!SetHandleInformation((HANDLE)newfd, HANDLE_FLAG_INHERIT, 0)) { closesocket(newfd); PyErr_SetFromWindowsErr(0); return NULL; } +#endif #else /* On UNIX, dup can be used to duplicate the file descriptor of a socket */ newfd = _Py_dup(fd); From f15d9e201673b4e0b904e76935b33085bb905c51 Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Sun, 26 Feb 2023 14:49:09 +0100 Subject: [PATCH 027/100] PathCchCombineEx is unavailable on xbox --- Python/fileutils.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Python/fileutils.c b/Python/fileutils.c index 30bb41e237de0f..9bee1eb2227fd4 100644 --- a/Python/fileutils.c +++ b/Python/fileutils.c @@ -2139,7 +2139,7 @@ static int join_relfile(wchar_t *buffer, size_t bufsize, const wchar_t *dirname, const wchar_t *relfile) { -#ifdef MS_WINDOWS +#if defined(MS_WINDOWS) && !defined(MS_WINDOWS_GAMES) if (FAILED(PathCchCombineEx(buffer, bufsize, dirname, relfile, PATHCCH_ALLOW_LONG_PATHS))) { return -1; @@ -2528,12 +2528,12 @@ _Py_get_blocking(int fd) success = GetNamedPipeHandleStateW(handle, &mode, NULL, NULL, NULL, NULL, 0); Py_END_ALLOW_THREADS - + if (!success) { PyErr_SetFromWindowsErr(0); return -1; } - + return !(mode & PIPE_NOWAIT); } From d816baa0dd447ea0b51c5abd4367013e6c3b9a38 Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Sun, 26 Feb 2023 14:59:32 +0100 Subject: [PATCH 028/100] patch out remaining funcs --- Modules/mmapmodule.c | 2 +- Modules/posixmodule.c | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Modules/mmapmodule.c b/Modules/mmapmodule.c index 05176d59a79492..b8a8a4c78dd671 100644 --- a/Modules/mmapmodule.c +++ b/Modules/mmapmodule.c @@ -652,7 +652,7 @@ mmap_flush_method(mmap_object *self, PyObject *args) if (self->access == ACCESS_READ || self->access == ACCESS_COPY) Py_RETURN_NONE; -#ifdef MS_WINDOWS +#if defined(MS_WINDOWS) && !defined(MS_WINDOWS_GAMES) if (!FlushViewOfFile(self->data+offset, size)) { PyErr_SetFromWindowsErr(GetLastError()); return NULL; diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 5490d9e1b5f4b1..4c6d2d6b148635 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -13829,7 +13829,9 @@ os_cpu_count_impl(PyObject *module) { int ncpu = 0; #ifdef MS_WINDOWS +#ifndef MS_WINDOWS_NON_DESKTOP ncpu = GetActiveProcessorCount(ALL_PROCESSOR_GROUPS); +#endif #elif defined(__hpux) ncpu = mpctl(MPC_GETNUMSPUS, NULL, NULL); #elif defined(HAVE_SYSCONF) && defined(_SC_NPROCESSORS_ONLN) From ed17e03f534fc78f51bbd4f577a7b785c4870a24 Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Sun, 26 Feb 2023 18:11:15 +0100 Subject: [PATCH 029/100] apply code review --- Modules/_winapi.c | 34 ++-------------------------------- Modules/posixmodule.c | 4 ++-- 2 files changed, 4 insertions(+), 34 deletions(-) diff --git a/Modules/_winapi.c b/Modules/_winapi.c index 7bafc0ba5a9a7a..4882c8cd674a02 100644 --- a/Modules/_winapi.c +++ b/Modules/_winapi.c @@ -66,32 +66,6 @@ #define T_HANDLE T_POINTER -/* Grab CancelIoEx dynamically from kernel32 */ -static int has_CancelIoEx = -1; -static BOOL (CALLBACK *Py_CancelIoEx)(HANDLE, LPOVERLAPPED); - -static int -check_CancelIoEx() -{ -#ifdef MS_WINDOWS_GAMES - Py_CancelIoEx = &CancelIoEx; - has_CancelIoEx = TRUE; -#else - if (has_CancelIoEx == -1) - { - HINSTANCE hKernel32 = GetModuleHandleA("KERNEL32"); - if (hKernel32) { - * (FARPROC *) &Py_CancelIoEx = GetProcAddress(hKernel32, - "CancelIoEx"); - has_CancelIoEx = (Py_CancelIoEx != NULL); - } else { - has_CancelIoEx = 0; - } - } -#endif - return has_CancelIoEx; -} - typedef struct { PyTypeObject *overlapped_type; } WinApiState; @@ -146,8 +120,7 @@ overlapped_dealloc(OverlappedObject *self) PyObject_GC_UnTrack(self); if (self->pending) { - if (check_CancelIoEx() && - Py_CancelIoEx(self->handle, &self->overlapped) && + if (CancelIoEx(self->handle, &self->overlapped) && GetOverlappedResult(self->handle, &self->overlapped, &bytes, TRUE)) { /* The operation is no longer pending -- nothing to do. */ @@ -318,10 +291,7 @@ _winapi_Overlapped_cancel_impl(OverlappedObject *self) if (self->pending) { Py_BEGIN_ALLOW_THREADS - if (check_CancelIoEx()) - res = Py_CancelIoEx(self->handle, &self->overlapped); - else - res = CancelIo(self->handle); + res = CancelIoEx(self->handle, &self->overlapped); Py_END_ALLOW_THREADS } diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 7208b8b646dbe8..1fd432b5f3c0c8 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -8438,7 +8438,7 @@ os_kill_impl(PyObject *module, pid_t pid, Py_ssize_t signal) /* Console processes which share a common console can be sent CTRL+C or CTRL+BREAK events, provided they handle said events. */ -#if !defined(MS_WINDOWS_NON_DESKTOP) +#if !defined(MS_WINDOWS_GAMES) /* Console processes which share a common console can be sent CTRL+C or CTRL+BREAK events, provided they handle said events. */ if (sig == CTRL_C_EVENT || sig == CTRL_BREAK_EVENT) { @@ -15078,7 +15078,7 @@ os_getrandom_impl(PyObject *module, Py_ssize_t size, int flags) } #endif /* HAVE_GETRANDOM_SYSCALL */ -#if defined(MS_WINDOWS) && !defined(MS_WINDOWS_NON_DESKTOP) +#if defined(MS_WINDOWS) && !defined(MS_WINDOWS_GAMES) /* bpo-36085: Helper functions for managing DLL search directories * on win32 */ From c360b4ab82013bb3f5e316f4ca9a838485363506 Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Sun, 26 Feb 2023 18:14:57 +0100 Subject: [PATCH 030/100] cleanup --- Modules/posixmodule.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 1fd432b5f3c0c8..5c492041d094c4 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -313,7 +313,7 @@ corresponding Unix manual entries for more information on calls."); # include #endif -#if defined(MS_WINDOWS) && !defined(MS_WINDOWS_NON_DESKTOP) +#if defined(MS_WINDOWS) && !defined(MS_WINDOWS_GAMES) # define TERMSIZE_USE_CONIO #elif defined(HAVE_SYS_IOCTL_H) # include @@ -323,7 +323,7 @@ corresponding Unix manual entries for more information on calls."); # if defined(TIOCGWINSZ) # define TERMSIZE_USE_IOCTL # endif -#endif /* MS_WINDOWS && !MS_WINDOWS_NON_DESKTOP */ +#endif /* MS_WINDOWS && !MS_WINDOWS_GAMES */ /* Various compilers have only certain posix functions */ /* XXX Gosh I wish these were all moved into pyconfig.h */ @@ -8397,7 +8397,7 @@ os_getuid_impl(PyObject *module) #ifdef MS_WINDOWS #define HAVE_KILL -#endif /* MS_WINDOWS && !MS_WINDOWS_NON_DESKTOP */ +#endif /* MS_WINDOWS */ #ifdef HAVE_KILL /*[clinic input] @@ -15188,7 +15188,7 @@ os__remove_dll_directory_impl(PyObject *module, PyObject *cookie) Py_RETURN_NONE; } -#endif /* MS_WINDOWS && !MS_WINDOWS_NON_DESKTOP */ +#endif /* MS_WINDOWS && !MS_WINDOWS_GAMES */ /* Only check if WIFEXITED is available: expect that it comes From 3b5b119461c0b0bbfc206f8e2e9080156e04a203 Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Sun, 26 Feb 2023 18:24:16 +0100 Subject: [PATCH 031/100] remove unneded defined --- Modules/getpath.c | 3 --- Modules/mmapmodule.c | 5 ----- Modules/posixmodule.c | 6 ------ Objects/fileobject.c | 6 ------ Objects/object.c | 5 ----- Objects/obmalloc.c | 5 ----- Parser/myreadline.c | 4 ---- Parser/tokenizer.c | 7 ------- Python/bltinmodule.c | 6 ------ Python/fileutils.c | 11 ----------- Python/initconfig.c | 3 --- Python/marshal.c | 5 ----- Python/pylifecycle.c | 6 ------ Python/sysmodule.c | 4 ---- Python/traceback.c | 5 ----- 15 files changed, 81 deletions(-) diff --git a/Modules/getpath.c b/Modules/getpath.c index 2a2d8108b60ec5..f365492377fa95 100644 --- a/Modules/getpath.c +++ b/Modules/getpath.c @@ -12,9 +12,6 @@ #ifdef MS_WINDOWS # include // GetFullPathNameW(), MAX_PATH # include -# ifdef MS_WINDOWS_GAMES -# define wcsicmp _wcsicmp -# endif #endif #ifdef __APPLE__ diff --git a/Modules/mmapmodule.c b/Modules/mmapmodule.c index b8a8a4c78dd671..f8609458244cba 100644 --- a/Modules/mmapmodule.c +++ b/Modules/mmapmodule.c @@ -36,11 +36,6 @@ # endif /* HAVE_FCNTL_H */ #endif -/* the deprecated posix apis are not available on xbox */ -#ifdef MS_WINDOWS_GAMES -# define lseek _lseek -#endif - #ifdef MS_WINDOWS #include static int diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 5c492041d094c4..161e92225b1400 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -346,12 +346,6 @@ corresponding Unix manual entries for more information on calls."); # define HAVE_PIPE 1 # define HAVE_FSYNC 1 # define fsync _commit -# ifdef MS_WINDOWS_GAMES -# define dup2 _dup2 -# define umask _umask -# define close _close -# define isatty _isatty -# endif #endif /* ! __WATCOMC__ || __QNX__ */ /*[clinic input] diff --git a/Objects/fileobject.c b/Objects/fileobject.c index 806bb4d424b709..e99e155f2b8c98 100644 --- a/Objects/fileobject.c +++ b/Objects/fileobject.c @@ -5,12 +5,6 @@ #include "pycore_call.h" // _PyObject_CallNoArgs() #include "pycore_runtime.h" // _PyRuntime -/* the deprecated posix apis are not available on xbox */ -#ifdef MS_WINDOWS_GAMES -# define isatty _isatty -# define fileno _fileno -#endif - #if defined(HAVE_GETC_UNLOCKED) && !defined(_Py_MEMORY_SANITIZER) /* clang MemorySanitizer doesn't yet understand getc_unlocked. */ #define GETC(f) getc_unlocked(f) diff --git a/Objects/object.c b/Objects/object.c index ee089d19f8aa65..446c7b1f5f0302 100644 --- a/Objects/object.c +++ b/Objects/object.c @@ -22,11 +22,6 @@ # error "Py_LIMITED_API macro must not be defined" #endif -/* the deprecated posix apis are not available on xbox */ -#ifdef MS_WINDOWS_GAMES -# define fileno _fileno -#endif - #ifdef __cplusplus extern "C" { #endif diff --git a/Objects/obmalloc.c b/Objects/obmalloc.c index 5f9ebd916df400..5e1bcda1d976bb 100644 --- a/Objects/obmalloc.c +++ b/Objects/obmalloc.c @@ -8,11 +8,6 @@ #include // malloc() #include -/* the deprecated posix apis are not available on xbox */ -#ifdef MS_WINDOWS_GAMES -# define fileno _fileno -#endif - #undef uint #define uint pymem_uint diff --git a/Parser/myreadline.c b/Parser/myreadline.c index 98be9c16dfe12a..7800574ac04dfa 100644 --- a/Parser/myreadline.c +++ b/Parser/myreadline.c @@ -17,10 +17,6 @@ # define WIN32_LEAN_AND_MEAN # endif # include "windows.h" -# ifdef MS_WINDOWS_GAMES -# define isatty _isatty -# define fileno _fileno -# endif #endif /* MS_WINDOWS */ diff --git a/Parser/tokenizer.c b/Parser/tokenizer.c index 5e1a90d79d7d66..463c0e00ca1411 100644 --- a/Parser/tokenizer.c +++ b/Parser/tokenizer.c @@ -16,13 +16,6 @@ #include "fileobject.h" #include "abstract.h" -/* the deprecated posix apis are not available on xbox */ -#ifdef MS_WINDOWS_GAMES -# define fdopen _fdopen -# define lseek _lseek -# define fileno _fileno -#endif - /* Alternate tab spacing */ #define ALTTABSIZE 1 diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index d5cbfdd1d89fd3..53439ab16040c4 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -13,12 +13,6 @@ #include "clinic/bltinmodule.c.h" -/* the deprecated posix apis are not available on xbox */ -#ifdef MS_WINDOWS_GAMES -# define isatty _isatty -# define fileno _fileno -#endif - static PyObject* update_bases(PyObject *bases, PyObject *const *args, Py_ssize_t nargs) { diff --git a/Python/fileutils.c b/Python/fileutils.c index 9bee1eb2227fd4..47b4102e8b40ea 100644 --- a/Python/fileutils.c +++ b/Python/fileutils.c @@ -40,17 +40,6 @@ extern int winerror_to_errno(int); int _Py_open_cloexec_works = -1; #endif -/* the deprecated posix apis are not available on xbox */ -#ifdef MS_WINDOWS_GAMES -# define dup _dup -# define open _open -# define read _read -# define write _write -# define isatty _isatty -# define close _close -# define fileno _fileno -#endif - // The value must be the same in unicodeobject.c. #define MAX_UNICODE 0x10ffff diff --git a/Python/initconfig.c b/Python/initconfig.c index 2706242a66c5e4..6da289d0ec315a 100644 --- a/Python/initconfig.c +++ b/Python/initconfig.c @@ -21,9 +21,6 @@ # ifdef HAVE_FCNTL_H # include // O_BINARY # endif -# ifdef MS_WINDOWS_GAMES -# define fileno _fileno -# endif #endif /* --- Command line options --------------------------------------- */ diff --git a/Python/marshal.c b/Python/marshal.c index 405e7966c9ecce..94e79d4392ae6d 100644 --- a/Python/marshal.c +++ b/Python/marshal.c @@ -14,11 +14,6 @@ #include "pycore_hashtable.h" // _Py_hashtable_t #include "marshal.h" // Py_MARSHAL_VERSION -/* the deprecated posix apis are not available on xbox */ -#ifdef MS_WINDOWS_GAMES -# define fileno _fileno -#endif - /*[clinic input] module marshal [clinic start generated code]*/ diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index 18bd148446d5fb..fb7177b0d74dc1 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -56,12 +56,6 @@ extern void _PyIO_Fini(void); # undef BYTE #endif -/* the deprecated posix apis are not available on xbox */ -#ifdef MS_WINDOWS_GAMES -# define isatty _isatty -# define fileno _fileno -#endif - #define PUTS(fd, str) _Py_write_noraise(fd, str, (int)strlen(str)) diff --git a/Python/sysmodule.c b/Python/sysmodule.c index ce26271fe92016..074f8d8ab85dd9 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -40,10 +40,6 @@ Data members: #ifdef MS_WINDOWS #define WIN32_LEAN_AND_MEAN #include -/* the deprecated posix apis are not available on xbox */ -#ifdef MS_WINDOWS_GAMES -# define fileno _fileno -#endif #endif /* MS_WINDOWS */ #ifdef MS_COREDLL diff --git a/Python/traceback.c b/Python/traceback.c index 5ecabb817c10ef..31b85e77575efa 100644 --- a/Python/traceback.c +++ b/Python/traceback.c @@ -23,11 +23,6 @@ # include #endif -/* the deprecated posix apis are not available on xbox */ -#ifdef MS_WINDOWS_GAMES -# define lseek _lseek -#endif - #define OFF(x) offsetof(PyTracebackObject, x) #define PUTS(fd, str) _Py_write_noraise(fd, str, (int)strlen(str)) From 975191a7b18c67be9817a951e125e8db15d26788 Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Sun, 26 Feb 2023 18:25:07 +0100 Subject: [PATCH 032/100] regenerate argument clinic --- Modules/clinic/posixmodule.c.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Modules/clinic/posixmodule.c.h b/Modules/clinic/posixmodule.c.h index 16e2968b5eb1b1..99777c4937a2cb 100644 --- a/Modules/clinic/posixmodule.c.h +++ b/Modules/clinic/posixmodule.c.h @@ -10988,7 +10988,7 @@ os_getrandom(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject #endif /* defined(HAVE_GETRANDOM_SYSCALL) */ -#if (defined(MS_WINDOWS) && !defined(MS_WINDOWS_NON_DESKTOP)) +#if (defined(MS_WINDOWS) && !defined(MS_WINDOWS_GAMES)) PyDoc_STRVAR(os__add_dll_directory__doc__, "_add_dll_directory($module, /, path)\n" @@ -11057,9 +11057,9 @@ os__add_dll_directory(PyObject *module, PyObject *const *args, Py_ssize_t nargs, return return_value; } -#endif /* (defined(MS_WINDOWS) && !defined(MS_WINDOWS_NON_DESKTOP)) */ +#endif /* (defined(MS_WINDOWS) && !defined(MS_WINDOWS_GAMES)) */ -#if (defined(MS_WINDOWS) && !defined(MS_WINDOWS_NON_DESKTOP)) +#if (defined(MS_WINDOWS) && !defined(MS_WINDOWS_GAMES)) PyDoc_STRVAR(os__remove_dll_directory__doc__, "_remove_dll_directory($module, /, cookie)\n" @@ -11120,7 +11120,7 @@ os__remove_dll_directory(PyObject *module, PyObject *const *args, Py_ssize_t nar return return_value; } -#endif /* (defined(MS_WINDOWS) && !defined(MS_WINDOWS_NON_DESKTOP)) */ +#endif /* (defined(MS_WINDOWS) && !defined(MS_WINDOWS_GAMES)) */ #if (defined(WIFEXITED) || defined(MS_WINDOWS)) @@ -11796,4 +11796,4 @@ os_waitstatus_to_exitcode(PyObject *module, PyObject *const *args, Py_ssize_t na #ifndef OS_WAITSTATUS_TO_EXITCODE_METHODDEF #define OS_WAITSTATUS_TO_EXITCODE_METHODDEF #endif /* !defined(OS_WAITSTATUS_TO_EXITCODE_METHODDEF) */ -/*[clinic end generated code: output=ae3aca6d4222b790 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=5e962e56a50329e7 input=a9049054013a1b77]*/ From 91a95f2c1283638997753136317e6b245171cfca Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Sun, 26 Feb 2023 18:44:44 +0100 Subject: [PATCH 033/100] remove unused function --- Modules/posixmodule.c | 26 -------------------------- 1 file changed, 26 deletions(-) diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 161e92225b1400..74f8864bc52897 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -1508,32 +1508,6 @@ _Py_Sigset_Converter(PyObject *obj, void *addr) } #endif /* HAVE_SIGSET_T */ -#ifdef MS_WINDOWS - -static int -win32_get_reparse_tag(HANDLE reparse_point_handle, ULONG *reparse_tag) -{ - char target_buffer[_Py_MAXIMUM_REPARSE_DATA_BUFFER_SIZE]; - _Py_REPARSE_DATA_BUFFER *rdb = (_Py_REPARSE_DATA_BUFFER *)target_buffer; - DWORD n_bytes_returned; - - if (0 == DeviceIoControl( - reparse_point_handle, - FSCTL_GET_REPARSE_POINT, - NULL, 0, /* in buffer */ - target_buffer, sizeof(target_buffer), - &n_bytes_returned, - NULL)) /* we're not using OVERLAPPED_IO */ - return FALSE; - - if (reparse_tag) - *reparse_tag = rdb->ReparseTag; - - return TRUE; -} - -#endif /* MS_WINDOWS */ - /* Return a dictionary corresponding to the POSIX environment table */ #if defined(WITH_NEXT_FRAMEWORK) || (defined(__APPLE__) && defined(Py_ENABLE_SHARED)) /* On Darwin/MacOSX a shared library or framework has no access to From 3be5fa71f14e05427d5ff82e19cda95e306413b2 Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Sun, 26 Feb 2023 19:17:33 +0100 Subject: [PATCH 034/100] use processsnapshot api --- Modules/posixmodule.c | 49 ++++++++++++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 17 deletions(-) diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 74f8864bc52897..2881dc48b47051 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -333,8 +333,11 @@ corresponding Unix manual entries for more information on calls."); # include #elif defined( _MSC_VER) /* Microsoft compiler */ -# ifndef MS_WINDOWS_NON_DESKTOP +# ifndef MS_WINDOWS_GAMING # define HAVE_GETPPID 1 +# endif /* MS_WINDOWS_GAMING */ + +# ifndef MS_WINDOWS_NON_DESKTOP # define HAVE_GETLOGIN 1 # define HAVE_SPAWNV 1 # define HAVE_EXECV 1 @@ -8241,32 +8244,39 @@ os_setpgrp_impl(PyObject *module) #ifdef HAVE_GETPPID #ifdef MS_WINDOWS -#include +#include static PyObject* win32_getppid() { - HANDLE snapshot; + PSS_THREAD_ENTRY thread; PyObject* result = NULL; - BOOL have_record; - PROCESSENTRY32 pe; - + HPSS snapshot = NULL; + HPSSWALK walk = NULL; DWORD mypid = GetCurrentProcessId(); /* This function never fails */ + HANDLE myhandle = GetCurrentProcess(); + + if (PssCaptureSnapshot(myhandle, PSS_CAPTURE_THREADS, 0, &snapshot) != ERROR_SUCCESS) + { + result = PyErr_SetFromWindowsErr(GetLastError()); + goto exit; + } - snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); - if (snapshot == INVALID_HANDLE_VALUE) - return PyErr_SetFromWindowsErr(GetLastError()); + if (PssWalkMarkerCreate(NULL, &walk) != ERROR_SUCCESS) + { + result = PyErr_SetFromWindowsErr(GetLastError()); + goto exit; + } - pe.dwSize = sizeof(pe); - have_record = Process32First(snapshot, &pe); - while (have_record) { - if (mypid == pe.th32ProcessID) { + while (PssWalkSnapshot(snapshot, PSS_WALK_THREADS, walk, &thread, sizeof(thread)) == ERROR_SUCCESS) + { + if (mypid == thread.ProcessId) { /* We could cache the ulong value in a static variable. */ - result = PyLong_FromUnsignedLong(pe.th32ParentProcessID); + if (PssWalkSnapshot(snapshot, PSS_WALK_THREADS, walk, &thread, sizeof(thread)) == ERROR_SUCCESS) + result = PyLong_FromUnsignedLong(thread.ProcessId); + break; } - - have_record = Process32Next(snapshot, &pe); } /* If our loop exits and our pid was not found (result will be NULL) @@ -8275,7 +8285,12 @@ win32_getppid() if (!result) result = PyErr_SetFromWindowsErr(GetLastError()); - CloseHandle(snapshot); +exit: + if (walk) + PssWalkMarkerFree(walk); + + if (snapshot) + PssFreeSnapshot(myhandle, snapshot); return result; } From 6bd12071f3ceb703026e6ec327c721c40de994d7 Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Sun, 26 Feb 2023 19:20:58 +0100 Subject: [PATCH 035/100] simplify implementation --- Modules/getpath.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/Modules/getpath.c b/Modules/getpath.c index f365492377fa95..2f20521592ce2e 100644 --- a/Modules/getpath.c +++ b/Modules/getpath.c @@ -227,19 +227,11 @@ getpath_isxfile(PyObject *Py_UNUSED(self), PyObject *args) path = PyUnicode_AsWideCharString(pathobj, &cchPath); if (path) { #ifdef MS_WINDOWS - const wchar_t *ext; -#ifdef MS_WINDOWS_GAMES - ext = (cchPath >= 4) ? path + cchPath - 4 : NULL; -#endif DWORD attr = GetFileAttributesW(path); r = (attr != INVALID_FILE_ATTRIBUTES) && !(attr & FILE_ATTRIBUTE_DIRECTORY) && -#ifdef MS_WINDOWS_GAMES - (ext != NULL) && -#else - SUCCEEDED(PathCchFindExtension(path, cchPath + 1, &ext)) && -#endif - (CompareStringOrdinal(ext, -1, L".exe", -1, 1 /* ignore case */) == CSTR_EQUAL) + (cchPath >= 4) && + (CompareStringOrdinal(path + cchPath - 4, -1, L".exe", -1, 1 /* ignore case */) == CSTR_EQUAL) ? Py_True : Py_False; #else struct stat st; From ca98366f8f6b2c3fd85fb322c3f104cf19ab9085 Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Sun, 26 Feb 2023 19:47:59 +0100 Subject: [PATCH 036/100] simplify implementation --- Modules/posixmodule.c | 50 ++++++++----------------------------------- 1 file changed, 9 insertions(+), 41 deletions(-) diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 2881dc48b47051..4117678478dacb 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -333,11 +333,8 @@ corresponding Unix manual entries for more information on calls."); # include #elif defined( _MSC_VER) /* Microsoft compiler */ -# ifndef MS_WINDOWS_GAMING -# define HAVE_GETPPID 1 -# endif /* MS_WINDOWS_GAMING */ - # ifndef MS_WINDOWS_NON_DESKTOP +# define HAVE_GETPPID 1 # define HAVE_GETLOGIN 1 # define HAVE_SPAWNV 1 # define HAVE_EXECV 1 @@ -8249,49 +8246,20 @@ os_setpgrp_impl(PyObject *module) static PyObject* win32_getppid() { - PSS_THREAD_ENTRY thread; PyObject* result = NULL; - HPSS snapshot = NULL; - HPSSWALK walk = NULL; - DWORD mypid = GetCurrentProcessId(); /* This function never fails */ HANDLE myhandle = GetCurrentProcess(); - if (PssCaptureSnapshot(myhandle, PSS_CAPTURE_THREADS, 0, &snapshot) != ERROR_SUCCESS) - { - result = PyErr_SetFromWindowsErr(GetLastError()); - goto exit; - } - - if (PssWalkMarkerCreate(NULL, &walk) != ERROR_SUCCESS) - { - result = PyErr_SetFromWindowsErr(GetLastError()); - goto exit; - } - - while (PssWalkSnapshot(snapshot, PSS_WALK_THREADS, walk, &thread, sizeof(thread)) == ERROR_SUCCESS) - { - if (mypid == thread.ProcessId) { - /* We could cache the ulong value in a static variable. */ - if (PssWalkSnapshot(snapshot, PSS_WALK_THREADS, walk, &thread, sizeof(thread)) == ERROR_SUCCESS) - result = PyLong_FromUnsignedLong(thread.ProcessId); - - break; - } - } + HPSS snapshot = NULL; + if (PssCaptureSnapshot(myhandle, PSS_CAPTURE_NONE, 0, &snapshot) != ERROR_SUCCESS) + return PyErr_SetFromWindowsErr(GetLastError()); - /* If our loop exits and our pid was not found (result will be NULL) - * then GetLastError will return ERROR_NO_MORE_FILES. This is an - * error anyway, so let's raise it. */ - if (!result) + PSS_PROCESS_INFORMATION info; + if (PssQuerySnapshot(snapshot, PSS_QUERY_PROCESS_INFORMATION, &info, sizeof(info)) != ERROR_SUCCESS) + result = PyLong_FromUnsignedLong(info.ParentProcessId); + else result = PyErr_SetFromWindowsErr(GetLastError()); -exit: - if (walk) - PssWalkMarkerFree(walk); - - if (snapshot) - PssFreeSnapshot(myhandle, snapshot); - + PssFreeSnapshot(myhandle, snapshot); return result; } #endif /*MS_WINDOWS*/ From fac3431d559ac033e9ec3fb26e096e39835b5491 Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Sun, 26 Feb 2023 20:12:51 +0100 Subject: [PATCH 037/100] follow pep7 --- Modules/posixmodule.c | 21 ++++++++++++++------- Python/fileutils.c | 6 ++++-- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 4117678478dacb..c470ce19a01181 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -8246,20 +8246,27 @@ os_setpgrp_impl(PyObject *module) static PyObject* win32_getppid() { + DWORD error; PyObject* result = NULL; - HANDLE myhandle = GetCurrentProcess(); + HANDLE process = GetCurrentProcess(); HPSS snapshot = NULL; - if (PssCaptureSnapshot(myhandle, PSS_CAPTURE_NONE, 0, &snapshot) != ERROR_SUCCESS) - return PyErr_SetFromWindowsErr(GetLastError()); + error = PssCaptureSnapshot(process, PSS_CAPTURE_NONE, 0, &snapshot); + if (error != ERROR_SUCCESS) { + return PyErr_SetFromWindowsErr(error); + } PSS_PROCESS_INFORMATION info; - if (PssQuerySnapshot(snapshot, PSS_QUERY_PROCESS_INFORMATION, &info, sizeof(info)) != ERROR_SUCCESS) + error = PssQuerySnapshot( + snapshot, PSS_QUERY_PROCESS_INFORMATION, &info, sizeof(info) + ); + if (error != ERROR_SUCCESS) { result = PyLong_FromUnsignedLong(info.ParentProcessId); - else - result = PyErr_SetFromWindowsErr(GetLastError()); + } else { + result = PyErr_SetFromWindowsErr(error); + } - PssFreeSnapshot(myhandle, snapshot); + PssFreeSnapshot(process, snapshot); return result; } #endif /*MS_WINDOWS*/ diff --git a/Python/fileutils.c b/Python/fileutils.c index 47b4102e8b40ea..20a8b026cd0dff 100644 --- a/Python/fileutils.c +++ b/Python/fileutils.c @@ -1325,12 +1325,14 @@ static int set_inheritable(int fd, int inheritable, int raise, int *atomic_flag_works) { #ifdef MS_WINDOWS_NON_DESKTOP - if(!inheritable) + if(!inheritable) { return 0; + } - if (raise) + if (raise) { PyErr_Format(PyExc_OSError, "Setting handle as inheritable is unsupported on this platform"); + } return -1; #else From c1bf0e26114fe07533a7e221b1ab0a70b8410ffd Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Sun, 26 Feb 2023 20:17:29 +0100 Subject: [PATCH 038/100] follow pep7 --- Modules/socketmodule.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c index 623b8fc62f770f..b1a7c58b7d7636 100644 --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -383,7 +383,9 @@ remove_unusable_flags(PyObject *m) VER_MAJORVERSION|VER_MINORVERSION|VER_BUILDNUMBER, dwlConditionMask); #else - BOOL isSupported = (info.dwMajorVersion >= 10) && (info.dwMinorVersion >= 0) && (info.dwBuildNumber >= win_runtime_flags[i].build_number); + BOOL isSupported = info.dwMajorVersion >= 10 && + info.dwMinorVersion >= 0 && + info.dwBuildNumber >= win_runtime_flags[i].build_number; #endif if (isSupported) { break; From ace99f6ce776036d1917afae0249edd7bdf8b015 Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Sun, 26 Feb 2023 20:23:18 +0100 Subject: [PATCH 039/100] Update Modules/posixmodule.c Co-authored-by: Eryk Sun --- Modules/posixmodule.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index c470ce19a01181..578f66767d71cf 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -8257,12 +8257,12 @@ win32_getppid() } PSS_PROCESS_INFORMATION info; - error = PssQuerySnapshot( - snapshot, PSS_QUERY_PROCESS_INFORMATION, &info, sizeof(info) - ); + error = PssQuerySnapshot(snapshot, PSS_QUERY_PROCESS_INFORMATION, &info, + sizeof(info)); if (error != ERROR_SUCCESS) { result = PyLong_FromUnsignedLong(info.ParentProcessId); - } else { + } + else { result = PyErr_SetFromWindowsErr(error); } From e83d398eca23b2546c1e5e7474f6abd03a35939d Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Sun, 26 Feb 2023 20:57:03 +0100 Subject: [PATCH 040/100] remove duplicated comment --- Modules/posixmodule.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 578f66767d71cf..49f30d888b2715 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -8394,8 +8394,6 @@ os_kill_impl(PyObject *module, pid_t pid, Py_ssize_t signal) DWORD err; HANDLE handle; - /* Console processes which share a common console can be sent CTRL+C or - CTRL+BREAK events, provided they handle said events. */ #if !defined(MS_WINDOWS_GAMES) /* Console processes which share a common console can be sent CTRL+C or CTRL+BREAK events, provided they handle said events. */ @@ -8404,8 +8402,9 @@ os_kill_impl(PyObject *module, pid_t pid, Py_ssize_t signal) err = GetLastError(); PyErr_SetFromWindowsErr(err); } - else + else { Py_RETURN_NONE; + } } #endif From 76ea310365ff49514b0823a3983056ff47dec0e7 Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Sun, 26 Feb 2023 21:02:12 +0100 Subject: [PATCH 041/100] test error message as well --- Lib/test/test_os.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py index deea207bfdadd9..ea78f230cb2954 100644 --- a/Lib/test/test_os.py +++ b/Lib/test/test_os.py @@ -3066,9 +3066,11 @@ class PidTests(unittest.TestCase): def test_getppid(self): p = subprocess.Popen([sys.executable, '-c', 'import os; print(os.getppid())'], - stdout=subprocess.PIPE) - stdout, _ = p.communicate() + stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + stdout, error = p.communicate() # We are the parent of our subprocess + self.assertEqual(error, b'') self.assertEqual(int(stdout), os.getpid()) def check_waitpid(self, code, exitcode, callback=None): From 2f1d19cdb0bf7607e4a7e3d2cc83e49e2c70f460 Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Sun, 26 Feb 2023 21:06:31 +0100 Subject: [PATCH 042/100] fix condition --- Modules/posixmodule.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 49f30d888b2715..79e3c5faab31a3 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -8259,7 +8259,7 @@ win32_getppid() PSS_PROCESS_INFORMATION info; error = PssQuerySnapshot(snapshot, PSS_QUERY_PROCESS_INFORMATION, &info, sizeof(info)); - if (error != ERROR_SUCCESS) { + if (error == ERROR_SUCCESS) { result = PyLong_FromUnsignedLong(info.ParentProcessId); } else { From 559199ffca78dfaed9eccea4c9e6f055eab2e133 Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Sun, 26 Feb 2023 21:31:40 +0100 Subject: [PATCH 043/100] use sys._base_executable --- Lib/test/test_os.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py index ea78f230cb2954..a3cd2eac7a3e37 100644 --- a/Lib/test/test_os.py +++ b/Lib/test/test_os.py @@ -3064,7 +3064,7 @@ def test_device_encoding(self): class PidTests(unittest.TestCase): @unittest.skipUnless(hasattr(os, 'getppid'), "test needs os.getppid") def test_getppid(self): - p = subprocess.Popen([sys.executable, '-c', + p = subprocess.Popen([sys._base_executable, '-c', 'import os; print(os.getppid())'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) From b119bf5f439d41ad9c764265827e4f1ad49a3bae Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Sun, 26 Feb 2023 23:01:33 +0100 Subject: [PATCH 044/100] do not build mmap on unsupported platforms --- Modules/mmapmodule.c | 4 ++++ PC/config.c | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/Modules/mmapmodule.c b/Modules/mmapmodule.c index f8609458244cba..f2ec118922743d 100644 --- a/Modules/mmapmodule.c +++ b/Modules/mmapmodule.c @@ -29,6 +29,8 @@ #include "structmember.h" // PyMemberDef #include // offsetof() +#if !defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES) + #ifndef MS_WINDOWS #define UNIX # ifdef HAVE_FCNTL_H @@ -1724,3 +1726,5 @@ PyInit_mmap(void) { return PyModuleDef_Init(&mmapmodule); } + +#endif /* !MS_WINDOWS_NON_DESKTOP || MS_WINDOWS_GAMES */ diff --git a/PC/config.c b/PC/config.c index b1481d79e6508d..9d9d97a80b0ab4 100644 --- a/PC/config.c +++ b/PC/config.c @@ -43,7 +43,9 @@ extern PyObject* PyInit__collections(void); extern PyObject* PyInit__heapq(void); extern PyObject* PyInit__bisect(void); extern PyObject* PyInit__symtable(void); +#if !defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES) extern PyObject* PyInit_mmap(void); +#endif extern PyObject* PyInit__csv(void); extern PyObject* PyInit__sre(void); extern PyObject* PyInit_winreg(void); @@ -122,7 +124,9 @@ struct _inittab _PyImport_Inittab[] = { {"itertools", PyInit_itertools}, {"_collections", PyInit__collections}, {"_symtable", PyInit__symtable}, +#if !defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES) {"mmap", PyInit_mmap}, +#endif {"_csv", PyInit__csv}, {"_sre", PyInit__sre}, {"winreg", PyInit_winreg}, From 1dd69e8444a1b7f47b4c1205cb91e5f4c211ab55 Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Mon, 27 Feb 2023 01:45:14 +0100 Subject: [PATCH 045/100] Apply suggestions from code review Co-authored-by: Eryk Sun --- PC/msvcrtmodule.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/PC/msvcrtmodule.c b/PC/msvcrtmodule.c index 7bc4e2f2f94dc8..3a6eeabb3e2cb6 100644 --- a/PC/msvcrtmodule.c +++ b/PC/msvcrtmodule.c @@ -253,7 +253,7 @@ msvcrt_getch_impl(PyObject *module) return ch; } -#ifndef MS_WINDOWS_GAMES +#ifndef MS_WINDOWS_NON_DESKTOP /*[clinic input] msvcrt.getwch -> wchar_t @@ -273,7 +273,7 @@ msvcrt_getwch_impl(PyObject *module) return ch; } -#endif /* MS_WINDOWS_GAMES */ +#endif /* MS_WINDOWS_NON_DESKTOP */ /*[clinic input] msvcrt.getche -> byte_char @@ -293,7 +293,7 @@ msvcrt_getche_impl(PyObject *module) return ch; } -#ifndef MS_WINDOWS_GAMES +#ifndef MS_WINDOWS_NON_DESKTOP /*[clinic input] msvcrt.getwche -> wchar_t @@ -313,7 +313,7 @@ msvcrt_getwche_impl(PyObject *module) return ch; } -#endif /* MS_WINDOWS_GAMES */ +#endif /* MS_WINDOWS_NON_DESKTOP */ /*[clinic input] msvcrt.putch @@ -334,7 +334,7 @@ msvcrt_putch_impl(PyObject *module, char char_value) Py_RETURN_NONE; } -#ifndef MS_WINDOWS_GAMES +#ifndef MS_WINDOWS_NON_DESKTOP /*[clinic input] msvcrt.putwch @@ -356,7 +356,7 @@ msvcrt_putwch_impl(PyObject *module, int unicode_char) } -#endif /* MS_WINDOWS_GAMES */ +#endif /* MS_WINDOWS_NON_DESKTOP */ /*[clinic input] msvcrt.ungetch @@ -386,7 +386,7 @@ msvcrt_ungetch_impl(PyObject *module, char char_value) Py_RETURN_NONE; } -#ifndef MS_WINDOWS_GAMES +#ifndef MS_WINDOWS_NON_DESKTOP /*[clinic input] msvcrt.ungetwch @@ -412,7 +412,7 @@ msvcrt_ungetwch_impl(PyObject *module, int unicode_char) Py_RETURN_NONE; } -#endif /* MS_WINDOWS_GAMES */ +#endif /* MS_WINDOWS_NON_DESKTOP */ #ifdef _DEBUG /*[clinic input] @@ -491,7 +491,7 @@ msvcrt_set_error_mode_impl(PyObject *module, int mode) } #endif /* _DEBUG */ -#ifndef MS_WINDOWS_NON_DESKTOP +#ifndef MS_WINDOWS_GAMES /*[clinic input] msvcrt.GetErrorMode @@ -512,7 +512,7 @@ msvcrt_GetErrorMode_impl(PyObject *module) return PyLong_FromUnsignedLong(res); } -#endif /* MS_WINDOWS_NON_DESKTOP */ +#endif /* MS_WINDOWS_GAMES */ /*[clinic input] msvcrt.SetErrorMode From a1e6dbacc4ce20b093170b2cd69657dfd6ce4831 Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Mon, 27 Feb 2023 11:58:04 +0100 Subject: [PATCH 046/100] add inheritable back --- Modules/clinic/posixmodule.c.h | 10 +++++----- Modules/posixmodule.c | 8 ++++++-- Python/fileutils.c | 22 ++++++---------------- 3 files changed, 17 insertions(+), 23 deletions(-) diff --git a/Modules/clinic/posixmodule.c.h b/Modules/clinic/posixmodule.c.h index 99777c4937a2cb..b95ad9b52dc1be 100644 --- a/Modules/clinic/posixmodule.c.h +++ b/Modules/clinic/posixmodule.c.h @@ -10332,7 +10332,7 @@ os_set_inheritable(PyObject *module, PyObject *const *args, Py_ssize_t nargs) return return_value; } -#if (defined(MS_WINDOWS) && !defined(MS_WINDOWS_NON_DESKTOP)) +#if defined(MS_WINDOWS) PyDoc_STRVAR(os_get_handle_inheritable__doc__, "get_handle_inheritable($module, handle, /)\n" @@ -10366,9 +10366,9 @@ os_get_handle_inheritable(PyObject *module, PyObject *arg) return return_value; } -#endif /* (defined(MS_WINDOWS) && !defined(MS_WINDOWS_NON_DESKTOP)) */ +#endif /* defined(MS_WINDOWS) */ -#if (defined(MS_WINDOWS) && !defined(MS_WINDOWS_NON_DESKTOP)) +#if defined(MS_WINDOWS) PyDoc_STRVAR(os_set_handle_inheritable__doc__, "set_handle_inheritable($module, handle, inheritable, /)\n" @@ -10400,7 +10400,7 @@ os_set_handle_inheritable(PyObject *module, PyObject *const *args, Py_ssize_t na return return_value; } -#endif /* (defined(MS_WINDOWS) && !defined(MS_WINDOWS_NON_DESKTOP)) */ +#endif /* defined(MS_WINDOWS) */ PyDoc_STRVAR(os_get_blocking__doc__, "get_blocking($module, fd, /)\n" @@ -11796,4 +11796,4 @@ os_waitstatus_to_exitcode(PyObject *module, PyObject *const *args, Py_ssize_t na #ifndef OS_WAITSTATUS_TO_EXITCODE_METHODDEF #define OS_WAITSTATUS_TO_EXITCODE_METHODDEF #endif /* !defined(OS_WAITSTATUS_TO_EXITCODE_METHODDEF) */ -/*[clinic end generated code: output=5e962e56a50329e7 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=b0f2b074f9ddc243 input=a9049054013a1b77]*/ diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 79e3c5faab31a3..a201eb3d3145cd 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -13859,7 +13859,11 @@ os_set_inheritable_impl(PyObject *module, int fd, int inheritable) } -#if defined(MS_WINDOWS) && !defined(MS_WINDOWS_NON_DESKTOP) +#ifdef MS_WINDOWS +#ifndef HANDLE_FLAG_INHERIT +#define HANDLE_FLAG_INHERIT 0x00000001 +#endif + /*[clinic input] os.get_handle_inheritable -> bool handle: intptr_t @@ -13904,7 +13908,7 @@ os_set_handle_inheritable_impl(PyObject *module, intptr_t handle, } Py_RETURN_NONE; } -#endif /* !MS_WINDOWS && !MS_WINDOWS_NON_DESKTOP */ +#endif /* MS_WINDOWS */ /*[clinic input] os.get_blocking -> bool diff --git a/Python/fileutils.c b/Python/fileutils.c index 20a8b026cd0dff..71d95963090c28 100644 --- a/Python/fileutils.c +++ b/Python/fileutils.c @@ -1272,14 +1272,17 @@ _Py_stat(PyObject *path, struct stat *statbuf) #endif } +#ifdef MS_WINDOWS +#ifndef HANDLE_FLAG_INHERIT +#define HANDLE_FLAG_INHERIT 0x00000001 +#endif +#endif /* This function MUST be kept async-signal-safe on POSIX when raise=0. */ static int get_inheritable(int fd, int raise) { -#ifdef MS_WINDOWS_NON_DESKTOP - return 0; -#elif defined(MS_WINDOWS) +#ifdef MS_WINDOWS HANDLE handle; DWORD flags; @@ -1324,18 +1327,6 @@ _Py_get_inheritable(int fd) static int set_inheritable(int fd, int inheritable, int raise, int *atomic_flag_works) { -#ifdef MS_WINDOWS_NON_DESKTOP - if(!inheritable) { - return 0; - } - - if (raise) { - PyErr_Format(PyExc_OSError, - "Setting handle as inheritable is unsupported on this platform"); - } - - return -1; -#else #ifdef MS_WINDOWS HANDLE handle; DWORD flags; @@ -1465,7 +1456,6 @@ set_inheritable(int fd, int inheritable, int raise, int *atomic_flag_works) } return 0; #endif -#endif /* MS_WINDOWS_NON_DESKTOP */ } /* Make the file descriptor non-inheritable. From 7a459887ef0d83e48ce35abdb582d59ed1beaacc Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Mon, 27 Feb 2023 11:59:55 +0100 Subject: [PATCH 047/100] Update Python/fileutils.c Co-authored-by: Eryk Sun --- Python/fileutils.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/Python/fileutils.c b/Python/fileutils.c index 71d95963090c28..b54a83df381b3c 100644 --- a/Python/fileutils.c +++ b/Python/fileutils.c @@ -2028,9 +2028,16 @@ _Py_isabs(const wchar_t *path) { #ifdef MS_WINDOWS_GAMES /* this does not handle persistent local storage */ - return (wcsncmp(path, L"G:\\", 3) == 0) - || (wcsncmp(path, L"D:\\", 3) == 0) - || (wcsncmp(path, L"T:\\", 3) == 0); + if (path[0] == SEP || path[0] == ALTSEP) { + // Check for an absolute UNC path. + return path[1] == SEP || path[1] == ALTSEP; + } + else { + // Check for an absolute drive path. + return ((path[0]) && + (path[1] == L':') && + (path[2] == SEP || path[2] == ALTSEP)); + } #elif defined(MS_WINDOWS) const wchar_t *tail; HRESULT hr = PathCchSkipRoot(path, &tail); From 846f8eba4e81417fd3bd731f2a3cda17208e61d6 Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Mon, 27 Feb 2023 12:03:43 +0100 Subject: [PATCH 048/100] Update Python/fileutils.c Co-authored-by: Eryk Sun --- Python/fileutils.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Python/fileutils.c b/Python/fileutils.c index b54a83df381b3c..4d1768a00bbe7e 100644 --- a/Python/fileutils.c +++ b/Python/fileutils.c @@ -77,7 +77,7 @@ _Py_device_encoding(int fd) if (!valid) Py_RETURN_NONE; -#ifdef MS_WINDOWS_NON_DESKTOP +#ifdef MS_WINDOWS_GAMES Py_RETURN_NONE; #elif defined(MS_WINDOWS) UINT cp; From a56f2150e923d40448c9dde7d1d430cb579f3196 Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Mon, 27 Feb 2023 13:52:07 +0100 Subject: [PATCH 049/100] add back some winreg APIs --- PC/clinic/msvcrtmodule.c.h | 22 ++++---- PC/config.c | 4 +- PC/config_minimal.c | 4 ++ PC/winreg.c | 111 ++----------------------------------- 4 files changed, 23 insertions(+), 118 deletions(-) diff --git a/PC/clinic/msvcrtmodule.c.h b/PC/clinic/msvcrtmodule.c.h index 704bb7f8fbd4b1..0c044ddc40da52 100644 --- a/PC/clinic/msvcrtmodule.c.h +++ b/PC/clinic/msvcrtmodule.c.h @@ -261,7 +261,7 @@ msvcrt_getch(PyObject *module, PyObject *Py_UNUSED(ignored)) return return_value; } -#if !defined(MS_WINDOWS_GAMES) +#if !defined(MS_WINDOWS_NON_DESKTOP) PyDoc_STRVAR(msvcrt_getwch__doc__, "getwch($module, /)\n" @@ -287,7 +287,7 @@ msvcrt_getwch(PyObject *module, PyObject *Py_UNUSED(ignored)) return return_value; } -#endif /* !defined(MS_WINDOWS_GAMES) */ +#endif /* !defined(MS_WINDOWS_NON_DESKTOP) */ PyDoc_STRVAR(msvcrt_getche__doc__, "getche($module, /)\n" @@ -313,7 +313,7 @@ msvcrt_getche(PyObject *module, PyObject *Py_UNUSED(ignored)) return return_value; } -#if !defined(MS_WINDOWS_GAMES) +#if !defined(MS_WINDOWS_NON_DESKTOP) PyDoc_STRVAR(msvcrt_getwche__doc__, "getwche($module, /)\n" @@ -339,7 +339,7 @@ msvcrt_getwche(PyObject *module, PyObject *Py_UNUSED(ignored)) return return_value; } -#endif /* !defined(MS_WINDOWS_GAMES) */ +#endif /* !defined(MS_WINDOWS_NON_DESKTOP) */ PyDoc_STRVAR(msvcrt_putch__doc__, "putch($module, char, /)\n" @@ -375,7 +375,7 @@ msvcrt_putch(PyObject *module, PyObject *arg) return return_value; } -#if !defined(MS_WINDOWS_GAMES) +#if !defined(MS_WINDOWS_NON_DESKTOP) PyDoc_STRVAR(msvcrt_putwch__doc__, "putwch($module, unicode_char, /)\n" @@ -413,7 +413,7 @@ msvcrt_putwch(PyObject *module, PyObject *arg) return return_value; } -#endif /* !defined(MS_WINDOWS_GAMES) */ +#endif /* !defined(MS_WINDOWS_NON_DESKTOP) */ PyDoc_STRVAR(msvcrt_ungetch__doc__, "ungetch($module, char, /)\n" @@ -453,7 +453,7 @@ msvcrt_ungetch(PyObject *module, PyObject *arg) return return_value; } -#if !defined(MS_WINDOWS_GAMES) +#if !defined(MS_WINDOWS_NON_DESKTOP) PyDoc_STRVAR(msvcrt_ungetwch__doc__, "ungetwch($module, unicode_char, /)\n" @@ -491,7 +491,7 @@ msvcrt_ungetwch(PyObject *module, PyObject *arg) return return_value; } -#endif /* !defined(MS_WINDOWS_GAMES) */ +#endif /* !defined(MS_WINDOWS_NON_DESKTOP) */ #if defined(_DEBUG) @@ -626,7 +626,7 @@ msvcrt_set_error_mode(PyObject *module, PyObject *arg) #endif /* defined(_DEBUG) */ -#if !defined(MS_WINDOWS_NON_DESKTOP) +#if !defined(MS_WINDOWS_GAMES) PyDoc_STRVAR(msvcrt_GetErrorMode__doc__, "GetErrorMode($module, /)\n" @@ -646,7 +646,7 @@ msvcrt_GetErrorMode(PyObject *module, PyObject *Py_UNUSED(ignored)) return msvcrt_GetErrorMode_impl(module); } -#endif /* !defined(MS_WINDOWS_NON_DESKTOP) */ +#endif /* !defined(MS_WINDOWS_GAMES) */ PyDoc_STRVAR(msvcrt_SetErrorMode__doc__, "SetErrorMode($module, mode, /)\n" @@ -707,4 +707,4 @@ msvcrt_SetErrorMode(PyObject *module, PyObject *arg) #ifndef MSVCRT_GETERRORMODE_METHODDEF #define MSVCRT_GETERRORMODE_METHODDEF #endif /* !defined(MSVCRT_GETERRORMODE_METHODDEF) */ -/*[clinic end generated code: output=ddb03bbe9ff66ac2 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=50255b8b9a685dcf input=a9049054013a1b77]*/ diff --git a/PC/config.c b/PC/config.c index 9d9d97a80b0ab4..5e0b694d8e2508 100644 --- a/PC/config.c +++ b/PC/config.c @@ -45,10 +45,10 @@ extern PyObject* PyInit__bisect(void); extern PyObject* PyInit__symtable(void); #if !defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES) extern PyObject* PyInit_mmap(void); +extern PyObject* PyInit_winreg(void); #endif extern PyObject* PyInit__csv(void); extern PyObject* PyInit__sre(void); -extern PyObject* PyInit_winreg(void); extern PyObject* PyInit__struct(void); extern PyObject* PyInit__datetime(void); extern PyObject* PyInit__functools(void); @@ -126,10 +126,10 @@ struct _inittab _PyImport_Inittab[] = { {"_symtable", PyInit__symtable}, #if !defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES) {"mmap", PyInit_mmap}, + {"winreg", PyInit_winreg}, #endif {"_csv", PyInit__csv}, {"_sre", PyInit__sre}, - {"winreg", PyInit_winreg}, {"_struct", PyInit__struct}, {"_datetime", PyInit__datetime}, {"_functools", PyInit__functools}, diff --git a/PC/config_minimal.c b/PC/config_minimal.c index 928a4efd32e132..b83a6ff105b798 100644 --- a/PC/config_minimal.c +++ b/PC/config_minimal.c @@ -14,7 +14,9 @@ extern PyObject* PyInit__tracemalloc(void); extern PyObject* PyInit_gc(void); extern PyObject* PyInit_nt(void); extern PyObject* PyInit__signal(void); +#if !defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES) extern PyObject* PyInit_winreg(void); +#endif extern PyObject* PyInit__ast(void); extern PyObject* PyInit__io(void); @@ -35,7 +37,9 @@ struct _inittab _PyImport_Inittab[] = { {"_tokenize", PyInit__tokenize}, {"_tracemalloc", PyInit__tracemalloc}, +#if !defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES) {"winreg", PyInit_winreg}, +#endif /* This module "lives in" with marshal.c */ {"marshal", PyMarshal_Init}, diff --git a/PC/winreg.c b/PC/winreg.c index f3b94c8cf79715..6d753a72b20ab0 100644 --- a/PC/winreg.c +++ b/PC/winreg.c @@ -18,6 +18,8 @@ #include "structmember.h" // PyMemberDef #include +#if !defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES) + static BOOL PyHKEY_AsHKEY(PyObject *ob, HKEY *pRes, BOOL bNoneOK); static BOOL clinic_HKEY_converter(PyObject *ob, void *p); static PyObject *PyHKEY_FromHKEY(HKEY h); @@ -143,10 +145,8 @@ PyHKEY_deallocFunc(PyObject *ob) check to fail! */ PyHKEYObject *obkey = (PyHKEYObject *)ob; -#ifndef MS_WINDOWS_NON_DESKTOP if (obkey->hkey) RegCloseKey((HKEY)obkey->hkey); -#endif PyObject_Free(ob); } @@ -390,7 +390,6 @@ PyTypeObject PyHKEY_Type = PyObject * PyHKEY_New(HKEY hInit) { - PyHKEYObject *key = PyObject_New(PyHKEYObject, &PyHKEY_Type); if (key) key->hkey = hInit; @@ -409,11 +408,7 @@ PyHKEY_Close(PyObject *ob_handle) if (PyHKEY_Check(ob_handle)) { ((PyHKEYObject*)ob_handle)->hkey = 0; } -#ifdef MS_WINDOWS_NON_DESKTOP - rc = ERROR_SUCCESS; -#else rc = key ? RegCloseKey(key) : ERROR_SUCCESS; -#endif if (rc != ERROR_SUCCESS) PyErr_SetFromWindowsErrWithFunction(rc, "RegCloseKey"); return rc == ERROR_SUCCESS; @@ -485,25 +480,17 @@ PyWinObject_CloseHKEY(PyObject *obHandle) } #if SIZEOF_LONG >= SIZEOF_HKEY else if (PyLong_Check(obHandle)) { -#ifdef MS_WINDOWS_NON_DESKTOP - ok = TRUE; -#else long rc = RegCloseKey((HKEY)PyLong_AsLong(obHandle)); ok = (rc == ERROR_SUCCESS); if (!ok) PyErr_SetFromWindowsErrWithFunction(rc, "RegCloseKey"); -#endif } #else else if (PyLong_Check(obHandle)) { -#ifdef MS_WINDOWS_NON_DESKTOP - ok = TRUE; -#else long rc = RegCloseKey((HKEY)PyLong_AsVoidPtr(obHandle)); ok = (rc == ERROR_SUCCESS); if (!ok) PyErr_SetFromWindowsErrWithFunction(rc, "RegCloseKey"); -#endif } #endif else { @@ -576,7 +563,7 @@ Py2Reg(PyObject *value, DWORD typ, BYTE **retDataBuf, DWORD *retDataSize) { Py_ssize_t i,j; switch (typ) { - case REG_DWORD: + case REG_DWORD: { if (value != Py_None && !PyLong_Check(value)) { return FALSE; @@ -600,7 +587,7 @@ Py2Reg(PyObject *value, DWORD typ, BYTE **retDataBuf, DWORD *retDataSize) *retDataSize = sizeof(DWORD); break; } - case REG_QWORD: + case REG_QWORD: { if (value != Py_None && !PyLong_Check(value)) { return FALSE; @@ -913,13 +900,6 @@ static HKEY winreg_CreateKey_impl(PyObject *module, HKEY key, const Py_UNICODE *sub_key) /*[clinic end generated code: output=2af13910d56eae26 input=3cdd1622488acea2]*/ { -#ifdef MS_WINDOWS_NON_DESKTOP - (void)module; - (void)key; - (void)sub_key; - PyErr_Format(PyExc_NotImplementedError, "not implemented on this platform"); - return NULL; -#else HKEY retKey; long rc; @@ -938,7 +918,6 @@ winreg_CreateKey_impl(PyObject *module, HKEY key, const Py_UNICODE *sub_key) return NULL; } return retKey; -#endif } /*[clinic input] @@ -971,15 +950,6 @@ winreg_CreateKeyEx_impl(PyObject *module, HKEY key, REGSAM access) /*[clinic end generated code: output=643a70ad6a361a97 input=42c2b03f98406b66]*/ { -#ifdef MS_WINDOWS_NON_DESKTOP - (void)module; - (void)key; - (void)sub_key; - (void)reserved; - (void)access; - PyErr_Format(PyExc_NotImplementedError, "not implemented on this platform"); - return NULL; -#else HKEY retKey; long rc; @@ -999,7 +969,6 @@ winreg_CreateKeyEx_impl(PyObject *module, HKEY key, return NULL; } return retKey; -#endif } /*[clinic input] @@ -1024,12 +993,6 @@ static PyObject * winreg_DeleteKey_impl(PyObject *module, HKEY key, const Py_UNICODE *sub_key) /*[clinic end generated code: output=d2652a84f70e0862 input=b31d225b935e4211]*/ { -#ifdef MS_WINDOWS_NON_DESKTOP - (void)module; - (void)key; - (void)sub_key; - return PyErr_Format(PyExc_NotImplementedError, "not implemented on this platform"); -#else long rc; if (PySys_Audit("winreg.DeleteKey", "nun", (Py_ssize_t)key, sub_key, @@ -1042,7 +1005,6 @@ winreg_DeleteKey_impl(PyObject *module, HKEY key, const Py_UNICODE *sub_key) if (rc != ERROR_SUCCESS) return PyErr_SetFromWindowsErrWithFunction(rc, "RegDeleteKey"); Py_RETURN_NONE; -#endif } /*[clinic input] @@ -1078,14 +1040,6 @@ winreg_DeleteKeyEx_impl(PyObject *module, HKEY key, int reserved) /*[clinic end generated code: output=52a1c8b374ebc003 input=a3186db079b3bf85]*/ { -#ifdef MS_WINDOWS_NON_DESKTOP - (void)module; - (void)key; - (void)sub_key; - (void)access; - (void)reserved; - return PyErr_Format(PyExc_NotImplementedError, "not implemented on this platform"); -#else long rc; if (PySys_Audit("winreg.DeleteKey", "nun", (Py_ssize_t)key, sub_key, @@ -1098,7 +1052,6 @@ winreg_DeleteKeyEx_impl(PyObject *module, HKEY key, if (rc != ERROR_SUCCESS) return PyErr_SetFromWindowsErrWithFunction(rc, "RegDeleteKeyEx"); Py_RETURN_NONE; -#endif } /*[clinic input] @@ -1117,12 +1070,6 @@ static PyObject * winreg_DeleteValue_impl(PyObject *module, HKEY key, const Py_UNICODE *value) /*[clinic end generated code: output=56fa9d21f3a54371 input=a78d3407a4197b21]*/ { -#ifdef MS_WINDOWS_NON_DESKTOP - (void)module; - (void)key; - (void)value; - return PyErr_Format(PyExc_NotImplementedError, "not implemented on this platform"); -#else long rc; if (PySys_Audit("winreg.DeleteValue", "nu", (Py_ssize_t)key, value) < 0) { @@ -1135,7 +1082,6 @@ winreg_DeleteValue_impl(PyObject *module, HKEY key, const Py_UNICODE *value) return PyErr_SetFromWindowsErrWithFunction(rc, "RegDeleteValue"); Py_RETURN_NONE; -#endif } /*[clinic input] @@ -1158,12 +1104,6 @@ static PyObject * winreg_EnumKey_impl(PyObject *module, HKEY key, int index) /*[clinic end generated code: output=25a6ec52cd147bc4 input=fad9a7c00ab0e04b]*/ { -#ifdef MS_WINDOWS_NON_DESKTOP - (void)module; - (void)key; - (void)index; - return PyErr_Format(PyExc_NotImplementedError, "not implemented on this platform"); -#else long rc; PyObject *retStr; @@ -1188,7 +1128,6 @@ winreg_EnumKey_impl(PyObject *module, HKEY key, int index) retStr = PyUnicode_FromWideChar(tmpbuf, len); return retStr; /* can be NULL */ -#endif } /*[clinic input] @@ -1220,12 +1159,6 @@ static PyObject * winreg_EnumValue_impl(PyObject *module, HKEY key, int index) /*[clinic end generated code: output=d363b5a06f8789ac input=4414f47a6fb238b5]*/ { -#ifdef MS_WINDOWS_NON_DESKTOP - (void)module; - (void)key; - (void)index; - return PyErr_Format(PyExc_NotImplementedError, "not implemented on this platform"); -#else long rc; wchar_t *retValueBuf; BYTE *tmpBuf; @@ -1302,7 +1235,6 @@ winreg_EnumValue_impl(PyObject *module, HKEY key, int index) PyMem_Free(retValueBuf); PyMem_Free(retDataBuf); return retVal; -#endif } /*[clinic input] @@ -1470,15 +1402,6 @@ winreg_OpenKey_impl(PyObject *module, HKEY key, const Py_UNICODE *sub_key, int reserved, REGSAM access) /*[clinic end generated code: output=8849bff2c30104ad input=098505ac36a9ae28]*/ { -#ifdef MS_WINDOWS_NON_DESKTOP - (void)module; - (void)key; - (void)sub_key; - (void)reserved; - (void)access; - PyErr_Format(PyExc_NotImplementedError, "not implemented on this platform"); - return NULL; -#else HKEY retKey; long rc; @@ -1499,7 +1422,6 @@ winreg_OpenKey_impl(PyObject *module, HKEY key, const Py_UNICODE *sub_key, return NULL; } return retKey; -#endif } /*[clinic input] @@ -1539,11 +1461,6 @@ static PyObject * winreg_QueryInfoKey_impl(PyObject *module, HKEY key) /*[clinic end generated code: output=dc657b8356a4f438 input=c3593802390cde1f]*/ { -#ifdef MS_WINDOWS_NON_DESKTOP - (void)module; - (void)key; - return PyErr_Format(PyExc_NotImplementedError, "not implemented on this platform"); -#else long rc; DWORD nSubKeys, nValues; FILETIME ft; @@ -1568,7 +1485,6 @@ winreg_QueryInfoKey_impl(PyObject *module, HKEY key) ret = Py_BuildValue("iiO", nSubKeys, nValues, l); Py_DECREF(l); return ret; -#endif } /*[clinic input] @@ -1674,12 +1590,6 @@ static PyObject * winreg_QueryValueEx_impl(PyObject *module, HKEY key, const Py_UNICODE *name) /*[clinic end generated code: output=f1b85b1c3d887ec7 input=cf366cada4836891]*/ { -#ifdef MS_WINDOWS_NON_DESKTOP - (void)module; - (void)key; - (void)name; - return PyErr_Format(PyExc_NotImplementedError, "not implemented on this platform"); -#else long rc; BYTE *retBuf, *tmp; DWORD bufSize = 0, retSize; @@ -1729,7 +1639,6 @@ winreg_QueryValueEx_impl(PyObject *module, HKEY key, const Py_UNICODE *name) result = Py_BuildValue("Oi", obData, typ); Py_DECREF(obData); return result; -#endif } /*[clinic input] @@ -1909,15 +1818,6 @@ winreg_SetValueEx_impl(PyObject *module, HKEY key, DWORD type, PyObject *value) /*[clinic end generated code: output=811b769a66ae11b7 input=900a9e3990bfb196]*/ { -#ifdef MS_WINDOWS_NON_DESKTOP - (void)module; - (void)key; - (void)value_name; - (void)reserved; - (void)type; - (void)value; - return PyErr_Format(PyExc_NotImplementedError, "not implemented on this platform"); -#else BYTE *data; DWORD len; @@ -1944,7 +1844,6 @@ winreg_SetValueEx_impl(PyObject *module, HKEY key, return PyErr_SetFromWindowsErrWithFunction(rc, "RegSetValueEx"); Py_RETURN_NONE; -#endif } /*[clinic input] @@ -2235,3 +2134,5 @@ PyMODINIT_FUNC PyInit_winreg(void) ADD_INT(REG_RESOURCE_REQUIREMENTS_LIST); return m; } + +#endif /* !MS_WINDOWS_NON_DESKTOP || MS_WINDOWS_GAMES */ From 191cab2f0b09994527f16c4395f8d9f14dca5b84 Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Mon, 27 Feb 2023 14:24:41 +0100 Subject: [PATCH 050/100] regenerate argument clinic --- PC/clinic/winreg.c.h | 218 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 217 insertions(+), 1 deletion(-) diff --git a/PC/clinic/winreg.c.h b/PC/clinic/winreg.c.h index 2834d9967a7726..b10813e1e75dd4 100644 --- a/PC/clinic/winreg.c.h +++ b/PC/clinic/winreg.c.h @@ -8,6 +8,8 @@ preserve #endif +#if (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) + PyDoc_STRVAR(winreg_HKEYType_Close__doc__, "Close($self, /)\n" "--\n" @@ -28,6 +30,10 @@ winreg_HKEYType_Close(PyHKEYObject *self, PyObject *Py_UNUSED(ignored)) return winreg_HKEYType_Close_impl(self); } +#endif /* (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) */ + +#if (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) + PyDoc_STRVAR(winreg_HKEYType_Detach__doc__, "Detach($self, /)\n" "--\n" @@ -54,6 +60,10 @@ winreg_HKEYType_Detach(PyHKEYObject *self, PyObject *Py_UNUSED(ignored)) return winreg_HKEYType_Detach_impl(self); } +#endif /* (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) */ + +#if (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) + PyDoc_STRVAR(winreg_HKEYType___enter____doc__, "__enter__($self, /)\n" "--\n" @@ -77,6 +87,10 @@ winreg_HKEYType___enter__(PyHKEYObject *self, PyObject *Py_UNUSED(ignored)) return return_value; } +#endif /* (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) */ + +#if (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) + PyDoc_STRVAR(winreg_HKEYType___exit____doc__, "__exit__($self, /, exc_type, exc_value, traceback)\n" "--\n" @@ -136,6 +150,10 @@ winreg_HKEYType___exit__(PyHKEYObject *self, PyObject *const *args, Py_ssize_t n return return_value; } +#endif /* (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) */ + +#if (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) + PyDoc_STRVAR(winreg_CloseKey__doc__, "CloseKey($module, hkey, /)\n" "--\n" @@ -151,6 +169,10 @@ PyDoc_STRVAR(winreg_CloseKey__doc__, #define WINREG_CLOSEKEY_METHODDEF \ {"CloseKey", (PyCFunction)winreg_CloseKey, METH_O, winreg_CloseKey__doc__}, +#endif /* (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) */ + +#if (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) + PyDoc_STRVAR(winreg_ConnectRegistry__doc__, "ConnectRegistry($module, computer_name, key, /)\n" "--\n" @@ -213,6 +235,10 @@ winreg_ConnectRegistry(PyObject *module, PyObject *const *args, Py_ssize_t nargs return return_value; } +#endif /* (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) */ + +#if (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) + PyDoc_STRVAR(winreg_CreateKey__doc__, "CreateKey($module, key, sub_key, /)\n" "--\n" @@ -278,6 +304,10 @@ winreg_CreateKey(PyObject *module, PyObject *const *args, Py_ssize_t nargs) return return_value; } +#endif /* (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) */ + +#if (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) + PyDoc_STRVAR(winreg_CreateKeyEx__doc__, "CreateKeyEx($module, /, key, sub_key, reserved=0,\n" " access=winreg.KEY_WRITE)\n" @@ -398,6 +428,10 @@ winreg_CreateKeyEx(PyObject *module, PyObject *const *args, Py_ssize_t nargs, Py return return_value; } +#endif /* (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) */ + +#if (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) + PyDoc_STRVAR(winreg_DeleteKey__doc__, "DeleteKey($module, key, sub_key, /)\n" "--\n" @@ -452,6 +486,10 @@ winreg_DeleteKey(PyObject *module, PyObject *const *args, Py_ssize_t nargs) return return_value; } +#endif /* (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) */ + +#if (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) + PyDoc_STRVAR(winreg_DeleteKeyEx__doc__, "DeleteKeyEx($module, /, key, sub_key, access=winreg.KEY_WOW64_64KEY,\n" " reserved=0)\n" @@ -565,6 +603,10 @@ winreg_DeleteKeyEx(PyObject *module, PyObject *const *args, Py_ssize_t nargs, Py return return_value; } +#endif /* (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) */ + +#if (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) + PyDoc_STRVAR(winreg_DeleteValue__doc__, "DeleteValue($module, key, value, /)\n" "--\n" @@ -617,6 +659,10 @@ winreg_DeleteValue(PyObject *module, PyObject *const *args, Py_ssize_t nargs) return return_value; } +#endif /* (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) */ + +#if (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) + PyDoc_STRVAR(winreg_EnumKey__doc__, "EnumKey($module, key, index, /)\n" "--\n" @@ -661,6 +707,10 @@ winreg_EnumKey(PyObject *module, PyObject *const *args, Py_ssize_t nargs) return return_value; } +#endif /* (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) */ + +#if (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) + PyDoc_STRVAR(winreg_EnumValue__doc__, "EnumValue($module, key, index, /)\n" "--\n" @@ -714,6 +764,10 @@ winreg_EnumValue(PyObject *module, PyObject *const *args, Py_ssize_t nargs) return return_value; } +#endif /* (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) */ + +#if (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) + PyDoc_STRVAR(winreg_ExpandEnvironmentStrings__doc__, "ExpandEnvironmentStrings($module, string, /)\n" "--\n" @@ -750,6 +804,10 @@ winreg_ExpandEnvironmentStrings(PyObject *module, PyObject *arg) return return_value; } +#endif /* (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) */ + +#if (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) + PyDoc_STRVAR(winreg_FlushKey__doc__, "FlushKey($module, key, /)\n" "--\n" @@ -790,6 +848,10 @@ winreg_FlushKey(PyObject *module, PyObject *arg) return return_value; } +#endif /* (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) */ + +#if (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) + PyDoc_STRVAR(winreg_LoadKey__doc__, "LoadKey($module, key, sub_key, file_name, /)\n" "--\n" @@ -866,6 +928,10 @@ winreg_LoadKey(PyObject *module, PyObject *const *args, Py_ssize_t nargs) return return_value; } +#endif /* (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) */ + +#if (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) + PyDoc_STRVAR(winreg_OpenKey__doc__, "OpenKey($module, /, key, sub_key, reserved=0, access=winreg.KEY_READ)\n" "--\n" @@ -979,6 +1045,10 @@ winreg_OpenKey(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObje return return_value; } +#endif /* (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) */ + +#if (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) + PyDoc_STRVAR(winreg_OpenKeyEx__doc__, "OpenKeyEx($module, /, key, sub_key, reserved=0, access=winreg.KEY_READ)\n" "--\n" @@ -1092,6 +1162,10 @@ winreg_OpenKeyEx(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyOb return return_value; } +#endif /* (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) */ + +#if (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) + PyDoc_STRVAR(winreg_QueryInfoKey__doc__, "QueryInfoKey($module, key, /)\n" "--\n" @@ -1128,6 +1202,10 @@ winreg_QueryInfoKey(PyObject *module, PyObject *arg) return return_value; } +#endif /* (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) */ + +#if (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) + PyDoc_STRVAR(winreg_QueryValue__doc__, "QueryValue($module, key, sub_key, /)\n" "--\n" @@ -1189,6 +1267,10 @@ winreg_QueryValue(PyObject *module, PyObject *const *args, Py_ssize_t nargs) return return_value; } +#endif /* (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) */ + +#if (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) + PyDoc_STRVAR(winreg_QueryValueEx__doc__, "QueryValueEx($module, key, name, /)\n" "--\n" @@ -1246,6 +1328,10 @@ winreg_QueryValueEx(PyObject *module, PyObject *const *args, Py_ssize_t nargs) return return_value; } +#endif /* (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) */ + +#if (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) + PyDoc_STRVAR(winreg_SaveKey__doc__, "SaveKey($module, key, file_name, /)\n" "--\n" @@ -1303,6 +1389,10 @@ winreg_SaveKey(PyObject *module, PyObject *const *args, Py_ssize_t nargs) return return_value; } +#endif /* (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) */ + +#if (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) + PyDoc_STRVAR(winreg_SetValue__doc__, "SetValue($module, key, sub_key, type, value, /)\n" "--\n" @@ -1384,6 +1474,10 @@ winreg_SetValue(PyObject *module, PyObject *const *args, Py_ssize_t nargs) return return_value; } +#endif /* (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) */ + +#if (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) + PyDoc_STRVAR(winreg_SetValueEx__doc__, "SetValueEx($module, key, value_name, reserved, type, value, /)\n" "--\n" @@ -1478,6 +1572,10 @@ winreg_SetValueEx(PyObject *module, PyObject *const *args, Py_ssize_t nargs) return return_value; } +#endif /* (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) */ + +#if (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) + PyDoc_STRVAR(winreg_DisableReflectionKey__doc__, "DisableReflectionKey($module, key, /)\n" "--\n" @@ -1514,6 +1612,10 @@ winreg_DisableReflectionKey(PyObject *module, PyObject *arg) return return_value; } +#endif /* (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) */ + +#if (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) + PyDoc_STRVAR(winreg_EnableReflectionKey__doc__, "EnableReflectionKey($module, key, /)\n" "--\n" @@ -1548,6 +1650,10 @@ winreg_EnableReflectionKey(PyObject *module, PyObject *arg) return return_value; } +#endif /* (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) */ + +#if (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) + PyDoc_STRVAR(winreg_QueryReflectionKey__doc__, "QueryReflectionKey($module, key, /)\n" "--\n" @@ -1579,4 +1685,114 @@ winreg_QueryReflectionKey(PyObject *module, PyObject *arg) exit: return return_value; } -/*[clinic end generated code: output=7e817dc5edc914d3 input=a9049054013a1b77]*/ + +#endif /* (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) */ + +#ifndef WINREG_HKEYTYPE_CLOSE_METHODDEF + #define WINREG_HKEYTYPE_CLOSE_METHODDEF +#endif /* !defined(WINREG_HKEYTYPE_CLOSE_METHODDEF) */ + +#ifndef WINREG_HKEYTYPE_DETACH_METHODDEF + #define WINREG_HKEYTYPE_DETACH_METHODDEF +#endif /* !defined(WINREG_HKEYTYPE_DETACH_METHODDEF) */ + +#ifndef WINREG_HKEYTYPE___ENTER___METHODDEF + #define WINREG_HKEYTYPE___ENTER___METHODDEF +#endif /* !defined(WINREG_HKEYTYPE___ENTER___METHODDEF) */ + +#ifndef WINREG_HKEYTYPE___EXIT___METHODDEF + #define WINREG_HKEYTYPE___EXIT___METHODDEF +#endif /* !defined(WINREG_HKEYTYPE___EXIT___METHODDEF) */ + +#ifndef WINREG_CLOSEKEY_METHODDEF + #define WINREG_CLOSEKEY_METHODDEF +#endif /* !defined(WINREG_CLOSEKEY_METHODDEF) */ + +#ifndef WINREG_CONNECTREGISTRY_METHODDEF + #define WINREG_CONNECTREGISTRY_METHODDEF +#endif /* !defined(WINREG_CONNECTREGISTRY_METHODDEF) */ + +#ifndef WINREG_CREATEKEY_METHODDEF + #define WINREG_CREATEKEY_METHODDEF +#endif /* !defined(WINREG_CREATEKEY_METHODDEF) */ + +#ifndef WINREG_CREATEKEYEX_METHODDEF + #define WINREG_CREATEKEYEX_METHODDEF +#endif /* !defined(WINREG_CREATEKEYEX_METHODDEF) */ + +#ifndef WINREG_DELETEKEY_METHODDEF + #define WINREG_DELETEKEY_METHODDEF +#endif /* !defined(WINREG_DELETEKEY_METHODDEF) */ + +#ifndef WINREG_DELETEKEYEX_METHODDEF + #define WINREG_DELETEKEYEX_METHODDEF +#endif /* !defined(WINREG_DELETEKEYEX_METHODDEF) */ + +#ifndef WINREG_DELETEVALUE_METHODDEF + #define WINREG_DELETEVALUE_METHODDEF +#endif /* !defined(WINREG_DELETEVALUE_METHODDEF) */ + +#ifndef WINREG_ENUMKEY_METHODDEF + #define WINREG_ENUMKEY_METHODDEF +#endif /* !defined(WINREG_ENUMKEY_METHODDEF) */ + +#ifndef WINREG_ENUMVALUE_METHODDEF + #define WINREG_ENUMVALUE_METHODDEF +#endif /* !defined(WINREG_ENUMVALUE_METHODDEF) */ + +#ifndef WINREG_EXPANDENVIRONMENTSTRINGS_METHODDEF + #define WINREG_EXPANDENVIRONMENTSTRINGS_METHODDEF +#endif /* !defined(WINREG_EXPANDENVIRONMENTSTRINGS_METHODDEF) */ + +#ifndef WINREG_FLUSHKEY_METHODDEF + #define WINREG_FLUSHKEY_METHODDEF +#endif /* !defined(WINREG_FLUSHKEY_METHODDEF) */ + +#ifndef WINREG_LOADKEY_METHODDEF + #define WINREG_LOADKEY_METHODDEF +#endif /* !defined(WINREG_LOADKEY_METHODDEF) */ + +#ifndef WINREG_OPENKEY_METHODDEF + #define WINREG_OPENKEY_METHODDEF +#endif /* !defined(WINREG_OPENKEY_METHODDEF) */ + +#ifndef WINREG_OPENKEYEX_METHODDEF + #define WINREG_OPENKEYEX_METHODDEF +#endif /* !defined(WINREG_OPENKEYEX_METHODDEF) */ + +#ifndef WINREG_QUERYINFOKEY_METHODDEF + #define WINREG_QUERYINFOKEY_METHODDEF +#endif /* !defined(WINREG_QUERYINFOKEY_METHODDEF) */ + +#ifndef WINREG_QUERYVALUE_METHODDEF + #define WINREG_QUERYVALUE_METHODDEF +#endif /* !defined(WINREG_QUERYVALUE_METHODDEF) */ + +#ifndef WINREG_QUERYVALUEEX_METHODDEF + #define WINREG_QUERYVALUEEX_METHODDEF +#endif /* !defined(WINREG_QUERYVALUEEX_METHODDEF) */ + +#ifndef WINREG_SAVEKEY_METHODDEF + #define WINREG_SAVEKEY_METHODDEF +#endif /* !defined(WINREG_SAVEKEY_METHODDEF) */ + +#ifndef WINREG_SETVALUE_METHODDEF + #define WINREG_SETVALUE_METHODDEF +#endif /* !defined(WINREG_SETVALUE_METHODDEF) */ + +#ifndef WINREG_SETVALUEEX_METHODDEF + #define WINREG_SETVALUEEX_METHODDEF +#endif /* !defined(WINREG_SETVALUEEX_METHODDEF) */ + +#ifndef WINREG_DISABLEREFLECTIONKEY_METHODDEF + #define WINREG_DISABLEREFLECTIONKEY_METHODDEF +#endif /* !defined(WINREG_DISABLEREFLECTIONKEY_METHODDEF) */ + +#ifndef WINREG_ENABLEREFLECTIONKEY_METHODDEF + #define WINREG_ENABLEREFLECTIONKEY_METHODDEF +#endif /* !defined(WINREG_ENABLEREFLECTIONKEY_METHODDEF) */ + +#ifndef WINREG_QUERYREFLECTIONKEY_METHODDEF + #define WINREG_QUERYREFLECTIONKEY_METHODDEF +#endif /* !defined(WINREG_QUERYREFLECTIONKEY_METHODDEF) */ +/*[clinic end generated code: output=24dacec92f5e6660 input=a9049054013a1b77]*/ From 144280edafe64e3e4761989e8f68e4509ea54e5a Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Mon, 27 Feb 2023 15:56:40 +0100 Subject: [PATCH 051/100] do not name platform xbox --- PC/pyconfig.h | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/PC/pyconfig.h b/PC/pyconfig.h index 4a6c806d1fc02f..2d651172d53e63 100644 --- a/PC/pyconfig.h +++ b/PC/pyconfig.h @@ -304,17 +304,7 @@ Py_NO_ENABLE_SHARED to find out. Also support MS_NO_COREDLL for b/w compat */ # endif /* Py_BUILD_CORE */ #endif /* MS_COREDLL */ -#if defined(MS_WINDOWS_GAMES) -# define PLATFORM "xbox" -# define SIZEOF_VOID_P 8 -# define SIZEOF_TIME_T 8 -# define SIZEOF_OFF_T 4 -# define SIZEOF_FPOS_T 8 -# define SIZEOF_HKEY 8 -# define SIZEOF_SIZE_T 8 -# define ALIGNOF_SIZE_T 8 -# define HAVE_LARGEFILE_SUPPORT -#elif defined(MS_WIN64) +#ifdef MS_WIN64 /* maintain "win32" sys.platform for backward compatibility of Python code, the Win64 API should be close enough to the Win32 API to make this preferable */ From ca9f7d9b633568e208e7c1a533e6b852a78b116f Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Mon, 27 Feb 2023 20:30:50 +0100 Subject: [PATCH 052/100] exclude functions --- PC/clinic/winreg.c.h | 38 +++++++++++------------ PC/winreg.c | 72 +++++++++++++++++--------------------------- 2 files changed, 46 insertions(+), 64 deletions(-) diff --git a/PC/clinic/winreg.c.h b/PC/clinic/winreg.c.h index b10813e1e75dd4..1938fcff19c853 100644 --- a/PC/clinic/winreg.c.h +++ b/PC/clinic/winreg.c.h @@ -171,7 +171,7 @@ PyDoc_STRVAR(winreg_CloseKey__doc__, #endif /* (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) */ -#if (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) +#if (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) && !defined(MS_WINDOWS_GAMES) PyDoc_STRVAR(winreg_ConnectRegistry__doc__, "ConnectRegistry($module, computer_name, key, /)\n" @@ -235,7 +235,7 @@ winreg_ConnectRegistry(PyObject *module, PyObject *const *args, Py_ssize_t nargs return return_value; } -#endif /* (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) */ +#endif /* (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) && !defined(MS_WINDOWS_GAMES) */ #if (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) @@ -806,7 +806,7 @@ winreg_ExpandEnvironmentStrings(PyObject *module, PyObject *arg) #endif /* (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) */ -#if (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) +#if (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) && !defined(MS_WINDOWS_GAMES) PyDoc_STRVAR(winreg_FlushKey__doc__, "FlushKey($module, key, /)\n" @@ -848,9 +848,9 @@ winreg_FlushKey(PyObject *module, PyObject *arg) return return_value; } -#endif /* (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) */ +#endif /* (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) && !defined(MS_WINDOWS_GAMES) */ -#if (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) +#if (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) && !defined(MS_WINDOWS_GAMES) PyDoc_STRVAR(winreg_LoadKey__doc__, "LoadKey($module, key, sub_key, file_name, /)\n" @@ -928,7 +928,7 @@ winreg_LoadKey(PyObject *module, PyObject *const *args, Py_ssize_t nargs) return return_value; } -#endif /* (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) */ +#endif /* (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) && !defined(MS_WINDOWS_GAMES) */ #if (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) @@ -1204,7 +1204,7 @@ winreg_QueryInfoKey(PyObject *module, PyObject *arg) #endif /* (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) */ -#if (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) +#if (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) && !defined(MS_WINDOWS_GAMES) PyDoc_STRVAR(winreg_QueryValue__doc__, "QueryValue($module, key, sub_key, /)\n" @@ -1267,7 +1267,7 @@ winreg_QueryValue(PyObject *module, PyObject *const *args, Py_ssize_t nargs) return return_value; } -#endif /* (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) */ +#endif /* (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) && !defined(MS_WINDOWS_GAMES) */ #if (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) @@ -1330,7 +1330,7 @@ winreg_QueryValueEx(PyObject *module, PyObject *const *args, Py_ssize_t nargs) #endif /* (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) */ -#if (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) +#if (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) && !defined(MS_WINDOWS_GAMES) PyDoc_STRVAR(winreg_SaveKey__doc__, "SaveKey($module, key, file_name, /)\n" @@ -1389,9 +1389,9 @@ winreg_SaveKey(PyObject *module, PyObject *const *args, Py_ssize_t nargs) return return_value; } -#endif /* (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) */ +#endif /* (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) && !defined(MS_WINDOWS_GAMES) */ -#if (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) +#if (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) && !defined(MS_WINDOWS_GAMES) PyDoc_STRVAR(winreg_SetValue__doc__, "SetValue($module, key, sub_key, type, value, /)\n" @@ -1474,7 +1474,7 @@ winreg_SetValue(PyObject *module, PyObject *const *args, Py_ssize_t nargs) return return_value; } -#endif /* (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) */ +#endif /* (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) && !defined(MS_WINDOWS_GAMES) */ #if (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) @@ -1574,7 +1574,7 @@ winreg_SetValueEx(PyObject *module, PyObject *const *args, Py_ssize_t nargs) #endif /* (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) */ -#if (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) +#if (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) && !defined(MS_WINDOWS_GAMES) PyDoc_STRVAR(winreg_DisableReflectionKey__doc__, "DisableReflectionKey($module, key, /)\n" @@ -1612,9 +1612,9 @@ winreg_DisableReflectionKey(PyObject *module, PyObject *arg) return return_value; } -#endif /* (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) */ +#endif /* (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) && !defined(MS_WINDOWS_GAMES) */ -#if (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) +#if (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) && !defined(MS_WINDOWS_GAMES) PyDoc_STRVAR(winreg_EnableReflectionKey__doc__, "EnableReflectionKey($module, key, /)\n" @@ -1650,9 +1650,9 @@ winreg_EnableReflectionKey(PyObject *module, PyObject *arg) return return_value; } -#endif /* (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) */ +#endif /* (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) && !defined(MS_WINDOWS_GAMES) */ -#if (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) +#if (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) && !defined(MS_WINDOWS_GAMES) PyDoc_STRVAR(winreg_QueryReflectionKey__doc__, "QueryReflectionKey($module, key, /)\n" @@ -1686,7 +1686,7 @@ winreg_QueryReflectionKey(PyObject *module, PyObject *arg) return return_value; } -#endif /* (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) */ +#endif /* (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) && !defined(MS_WINDOWS_GAMES) */ #ifndef WINREG_HKEYTYPE_CLOSE_METHODDEF #define WINREG_HKEYTYPE_CLOSE_METHODDEF @@ -1795,4 +1795,4 @@ winreg_QueryReflectionKey(PyObject *module, PyObject *arg) #ifndef WINREG_QUERYREFLECTIONKEY_METHODDEF #define WINREG_QUERYREFLECTIONKEY_METHODDEF #endif /* !defined(WINREG_QUERYREFLECTIONKEY_METHODDEF) */ -/*[clinic end generated code: output=24dacec92f5e6660 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=be95e7a8d3498fc6 input=a9049054013a1b77]*/ diff --git a/PC/winreg.c b/PC/winreg.c index 6d753a72b20ab0..f46222ad211d00 100644 --- a/PC/winreg.c +++ b/PC/winreg.c @@ -831,6 +831,8 @@ winreg_CloseKey(PyObject *module, PyObject *hkey) Py_RETURN_NONE; } +#ifndef MS_WINDOWS_GAMES + /*[clinic input] winreg.ConnectRegistry -> HKEY @@ -852,13 +854,6 @@ winreg_ConnectRegistry_impl(PyObject *module, const Py_UNICODE *computer_name, HKEY key) /*[clinic end generated code: output=cd4f70fb9ec901fb input=5f98a891a347e68e]*/ { -#ifdef MS_WINDOWS_NON_DESKTOP - (void)module; - (void)key; - (void)computer_name; - PyErr_Format(PyExc_NotImplementedError, "not implemented on this platform"); - return NULL; -#else HKEY retKey; long rc; if (PySys_Audit("winreg.ConnectRegistry", "un", @@ -873,9 +868,10 @@ winreg_ConnectRegistry_impl(PyObject *module, return NULL; } return retKey; -#endif } +#endif /* MS_WINDOWS_GAMES */ + /*[clinic input] winreg.CreateKey -> HKEY @@ -1282,6 +1278,8 @@ winreg_ExpandEnvironmentStrings_impl(PyObject *module, return o; } +#ifndef MS_WINDOWS_GAMES + /*[clinic input] winreg.FlushKey @@ -1306,11 +1304,6 @@ static PyObject * winreg_FlushKey_impl(PyObject *module, HKEY key) /*[clinic end generated code: output=e6fc230d4c5dc049 input=f57457c12297d82f]*/ { -#ifdef MS_WINDOWS_NON_DESKTOP - (void)module; - (void)key; - return PyErr_Format(PyExc_NotImplementedError, "not implemented on this platform"); -#else long rc; Py_BEGIN_ALLOW_THREADS rc = RegFlushKey(key); @@ -1318,9 +1311,11 @@ winreg_FlushKey_impl(PyObject *module, HKEY key) if (rc != ERROR_SUCCESS) return PyErr_SetFromWindowsErrWithFunction(rc, "RegFlushKey"); Py_RETURN_NONE; -#endif } +#endif /* MS_WINDOWS_GAMES */ + +#ifndef MS_WINDOWS_GAMES /*[clinic input] winreg.LoadKey @@ -1356,13 +1351,6 @@ winreg_LoadKey_impl(PyObject *module, HKEY key, const Py_UNICODE *sub_key, const Py_UNICODE *file_name) /*[clinic end generated code: output=65f89f2548cb27c7 input=e3b5b45ade311582]*/ { -#ifdef MS_WINDOWS_NON_DESKTOP - (void)module; - (void)key; - (void)sub_key; - (void)file_name; - return PyErr_Format(PyExc_NotImplementedError, "not implemented on this platform"); -#else long rc; if (PySys_Audit("winreg.LoadKey", "nuu", @@ -1375,9 +1363,10 @@ winreg_LoadKey_impl(PyObject *module, HKEY key, const Py_UNICODE *sub_key, if (rc != ERROR_SUCCESS) return PyErr_SetFromWindowsErrWithFunction(rc, "RegLoadKey"); Py_RETURN_NONE; -#endif } +#endif /* MS_WINDOWS_GAMES */ + /*[clinic input] winreg.OpenKey -> HKEY @@ -1487,6 +1476,8 @@ winreg_QueryInfoKey_impl(PyObject *module, HKEY key) return ret; } +#ifndef MS_WINDOWS_GAMES + /*[clinic input] winreg.QueryValue @@ -1512,12 +1503,6 @@ static PyObject * winreg_QueryValue_impl(PyObject *module, HKEY key, const Py_UNICODE *sub_key) /*[clinic end generated code: output=c655810ae50c63a9 input=41cafbbf423b21d6]*/ { -#ifdef MS_WINDOWS_NON_DESKTOP - (void)module; - (void)key; - (void)sub_key; - return PyErr_Format(PyExc_NotImplementedError, "not implemented on this platform"); -#else long rc; PyObject *retStr; wchar_t *retBuf; @@ -1565,9 +1550,10 @@ winreg_QueryValue_impl(PyObject *module, HKEY key, const Py_UNICODE *sub_key) retStr = PyUnicode_FromWideChar(retBuf, wcslen(retBuf)); PyMem_Free(retBuf); return retStr; -#endif } +#endif /* MS_WINDOWS_GAMES */ + /*[clinic input] winreg.QueryValueEx @@ -1641,6 +1627,8 @@ winreg_QueryValueEx_impl(PyObject *module, HKEY key, const Py_UNICODE *name) return result; } +#ifndef MS_WINDOWS_GAMES + /*[clinic input] winreg.SaveKey @@ -1667,12 +1655,6 @@ static PyObject * winreg_SaveKey_impl(PyObject *module, HKEY key, const Py_UNICODE *file_name) /*[clinic end generated code: output=ca94b835c88f112b input=da735241f91ac7a2]*/ { -#ifdef MS_WINDOWS_NON_DESKTOP - (void)module; - (void)key; - (void)file_name; - return PyErr_Format(PyExc_NotImplementedError, "not implemented on this platform"); -#else LPSECURITY_ATTRIBUTES pSA = NULL; long rc; @@ -1690,9 +1672,12 @@ winreg_SaveKey_impl(PyObject *module, HKEY key, const Py_UNICODE *file_name) if (rc != ERROR_SUCCESS) return PyErr_SetFromWindowsErrWithFunction(rc, "RegSaveKey"); Py_RETURN_NONE; -#endif } +#endif /* MS_WINDOWS_GAMES */ + +#ifndef MS_WINDOWS_GAMES + /*[clinic input] winreg.SetValue @@ -1725,14 +1710,6 @@ winreg_SetValue_impl(PyObject *module, HKEY key, const Py_UNICODE *sub_key, DWORD type, PyObject *value_obj) /*[clinic end generated code: output=d4773dc9c372311a input=bf088494ae2d24fd]*/ { -#ifdef MS_WINDOWS_NON_DESKTOP - (void)module; - (void)key; - (void)sub_key; - (void)type; - (void)value_obj; - return PyErr_Format(PyExc_NotImplementedError, "not implemented on this platform"); -#else Py_ssize_t value_length; long rc; @@ -1765,9 +1742,10 @@ winreg_SetValue_impl(PyObject *module, HKEY key, const Py_UNICODE *sub_key, if (rc != ERROR_SUCCESS) return PyErr_SetFromWindowsErrWithFunction(rc, "RegSetValue"); Py_RETURN_NONE; -#endif } +#endif /* MS_WINDOWS_GAMES */ + /*[clinic input] winreg.SetValueEx @@ -1846,6 +1824,8 @@ winreg_SetValueEx_impl(PyObject *module, HKEY key, Py_RETURN_NONE; } +#ifndef MS_WINDOWS_GAMES + /*[clinic input] winreg.DisableReflectionKey @@ -1994,6 +1974,8 @@ winreg_QueryReflectionKey_impl(PyObject *module, HKEY key) return PyBool_FromLong(result); } +#endif /* MS_WINDOWS_GAMES */ + static struct PyMethodDef winreg_methods[] = { WINREG_CLOSEKEY_METHODDEF WINREG_CONNECTREGISTRY_METHODDEF From 30c0818dccb29da215a3da6ae8319d3c4a8a282d Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Mon, 27 Feb 2023 21:14:05 +0100 Subject: [PATCH 053/100] implement without nt._path_splitroot --- Lib/importlib/_bootstrap_external.py | 98 ++++++++++++++++++++-------- 1 file changed, 69 insertions(+), 29 deletions(-) diff --git a/Lib/importlib/_bootstrap_external.py b/Lib/importlib/_bootstrap_external.py index 954401cfa85ed3..64d6b283e25b26 100644 --- a/Lib/importlib/_bootstrap_external.py +++ b/Lib/importlib/_bootstrap_external.py @@ -93,35 +93,75 @@ def _unpack_uint16(data): if _MS_WINDOWS: - def _path_join(*path_parts): - """Replacement for os.path.join().""" - if not path_parts: - return "" - if len(path_parts) == 1: - return path_parts[0] - root = "" - path = [] - for new_root, tail in map(_os._path_splitroot, path_parts): - if new_root.startswith(path_sep_tuple) or new_root.endswith(path_sep_tuple): - root = new_root.rstrip(path_separators) or root - path = [path_sep + tail] - elif new_root.endswith(':'): - if root.casefold() != new_root.casefold(): - # Drive relative paths have to be resolved by the OS, so we reset the - # tail but do not add a path_sep prefix. - root = new_root - path = [tail] - else: - path.append(tail) + def _path_splitroot(p): + """Replacement for os.path.splitroot().""" + sep = '\\' + altsep = '/' + colon = ':' + unc_prefix = '\\\\?\\UNC\\' + empty = '' + normp = p.replace(altsep, sep) + if normp[:1] == sep: + if normp[1:2] == sep: + # UNC drives, e.g. \\server\share or \\?\UNC\server\share + # Device drives, e.g. \\.\device or \\?\device + start = 8 if normp[:8].upper() == unc_prefix else 2 + index = normp.find(sep, start) + if index == -1: + return p, empty, empty + index2 = normp.find(sep, index + 1) + if index2 == -1: + return p, empty, empty + return p[:index2], p[index2:index2 + 1], p[index2 + 1:] + else: + # Relative path with root, e.g. \Windows + return empty, p[:1], p[1:] + elif normp[1:2] == colon: + if normp[2:3] == sep: + # Absolute drive-letter path, e.g. X:\Windows + return p[:2], p[2:3], p[3:] else: - root = new_root or root - path.append(tail) - path = [p.rstrip(path_separators) for p in path if p] - if len(path) == 1 and not path[0]: - # Avoid losing the root's trailing separator when joining with nothing - return root + path_sep - return root + path_sep.join(path) + # Relative path with drive, e.g. X:Windows + return p[:2], empty, p[2:] + else: + # Relative path, e.g. Windows + return empty, empty, p + def _path_join(path, *paths): + """Replacement for os.path.join().""" + sep = '\\' + seps = '\\/' + colon = ':' + if not paths: + path[:0] + sep #23780: Ensure compatible data type even if p is null. + result_drive, result_root, result_path = _path_splitroot(path) + for p in paths: + p_drive, p_root, p_path = _path_splitroot(p) + if p_root: + # Second path is absolute + if p_drive or not result_drive: + result_drive = p_drive + result_root = p_root + result_path = p_path + continue + elif p_drive and p_drive != result_drive: + if p_drive.lower() != result_drive.lower(): + # Different drives => ignore the first path entirely + result_drive = p_drive + result_root = p_root + result_path = p_path + continue + # Same drive in different case + result_drive = p_drive + # Second path is relative to the first + if result_path and result_path[-1] not in seps: + result_path = result_path + sep + result_path = result_path + p_path + ## add separator between UNC and non-absolute path + if (result_path and not result_root and + result_drive and result_drive[-1:] != colon): + return result_drive + sep + result_path + return result_drive + result_root + result_path else: def _path_join(*path_parts): """Replacement for os.path.join().""" @@ -173,8 +213,8 @@ def _path_isabs(path): """Replacement for os.path.isabs.""" if not path: return False - root = _os._path_splitroot(path)[0].replace('/', '\\') - return len(root) > 1 and (root.startswith('\\\\') or root.endswith('\\')) + root = path[:3].replace('/', '\\') + return root.startswith('\\\\') or root.startswith(':\\', 1) else: def _path_isabs(path): From 6ebb05bf9660e73dae9f70aa91a930e8be97c3e9 Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Mon, 27 Feb 2023 22:21:48 +0100 Subject: [PATCH 054/100] Update Modules/socketmodule.c Co-authored-by: Steve Dower --- Modules/socketmodule.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c index b1a7c58b7d7636..a6d0afc0447563 100644 --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -383,9 +383,10 @@ remove_unusable_flags(PyObject *m) VER_MAJORVERSION|VER_MINORVERSION|VER_BUILDNUMBER, dwlConditionMask); #else - BOOL isSupported = info.dwMajorVersion >= 10 && - info.dwMinorVersion >= 0 && - info.dwBuildNumber >= win_runtime_flags[i].build_number; + BOOL isSupported = info.dwMajorVersion > 10 || + (info.dwMajorVersion == 10 && info.dwMinorVersion > 0) || + (info.dwMajorVersion == 10 && info.dwMinorVersion == 0 && + info.dwBuildNumber >= win_runtime_flags[i].build_number); #endif if (isSupported) { break; From fc5c64207620d628f65e5fa25e33eb1d7bc5cfe0 Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Mon, 27 Feb 2023 22:31:06 +0100 Subject: [PATCH 055/100] apply some code review change requests --- Modules/selectmodule.c | 6 +----- Modules/socketmodule.c | 4 ---- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/Modules/selectmodule.c b/Modules/selectmodule.c index 6da071cb268f79..5a1e40d0b4a482 100644 --- a/Modules/selectmodule.c +++ b/Modules/selectmodule.c @@ -60,11 +60,7 @@ extern void bzero(void *, int); # ifndef WIN32_LEAN_AND_MEAN # define WIN32_LEAN_AND_MEAN # endif -# ifdef MS_WINDOWS_GAMES -# include -# else -# include -# endif +# include #else # define SOCKET int #endif diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c index a6d0afc0447563..a5d7da4f488b93 100644 --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -7362,11 +7362,7 @@ PyInit__socket(void) #ifdef MS_WINDOWS if (support_wsa_no_inherit == -1) { -#ifdef MS_WINDOWS_NON_DESKTOP support_wsa_no_inherit = 1; -#else - support_wsa_no_inherit = IsWindows7SP1OrGreater(); -#endif } #endif From 5f286a7e16c543ab6a2cd73b8a2332bb532268a7 Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Mon, 27 Feb 2023 22:55:43 +0100 Subject: [PATCH 056/100] get rid of support_wsa_no_inherit --- Modules/socketmodule.c | 37 +++---------------------------------- 1 file changed, 3 insertions(+), 34 deletions(-) diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c index a5d7da4f488b93..f3b0a39758f41a 100644 --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -620,11 +620,6 @@ select_error(void) # define SUPPRESS_DEPRECATED_CALL #endif -#ifdef MS_WINDOWS -/* Does WSASocket() support the WSA_FLAG_NO_HANDLE_INHERIT flag? */ -static int support_wsa_no_inherit = -1; -#endif - /* Convenience function to raise an error according to errno and return a NULL pointer from a function. */ @@ -5454,35 +5449,15 @@ sock_initobj_impl(PySocketSockObject *self, int family, int type, int proto, #endif Py_BEGIN_ALLOW_THREADS - if (support_wsa_no_inherit) { - fd = WSASocketW(family, type, proto, - NULL, 0, - WSA_FLAG_OVERLAPPED | WSA_FLAG_NO_HANDLE_INHERIT); - if (fd == INVALID_SOCKET) { - /* Windows 7 or Windows 2008 R2 without SP1 or the hotfix */ - support_wsa_no_inherit = 0; - fd = socket(family, type, proto); - } - } - else { - fd = socket(family, type, proto); - } + fd = WSASocketW(family, type, proto, + NULL, 0, + WSA_FLAG_OVERLAPPED | WSA_FLAG_NO_HANDLE_INHERIT); Py_END_ALLOW_THREADS if (fd == INVALID_SOCKET) { set_error(); return -1; } - -#ifndef MS_WINDOWS_NON_DESKTOP - if (!support_wsa_no_inherit) { - if (!SetHandleInformation((HANDLE)fd, HANDLE_FLAG_INHERIT, 0)) { - closesocket(fd); - PyErr_SetFromWindowsErr(0); - return -1; - } - } -#endif #else /* UNIX */ Py_BEGIN_ALLOW_THREADS @@ -7360,12 +7335,6 @@ PyInit__socket(void) if (!os_init()) return NULL; -#ifdef MS_WINDOWS - if (support_wsa_no_inherit == -1) { - support_wsa_no_inherit = 1; - } -#endif - Py_SET_TYPE(&sock_type, &PyType_Type); m = PyModule_Create(&socketmodule); if (m == NULL) From 3be5e3cc39ad4f525909d02beb10b7ab2f0971f5 Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Tue, 28 Feb 2023 00:07:48 +0100 Subject: [PATCH 057/100] implement _path_splitroot --- Lib/importlib/_bootstrap_external.py | 228 ++++++++------------------- Modules/clinic/posixmodule.c.h | 6 +- Modules/posixmodule.c | 26 ++- 3 files changed, 91 insertions(+), 169 deletions(-) diff --git a/Lib/importlib/_bootstrap_external.py b/Lib/importlib/_bootstrap_external.py index 64d6b283e25b26..b6c6716e907734 100644 --- a/Lib/importlib/_bootstrap_external.py +++ b/Lib/importlib/_bootstrap_external.py @@ -93,75 +93,35 @@ def _unpack_uint16(data): if _MS_WINDOWS: - def _path_splitroot(p): - """Replacement for os.path.splitroot().""" - sep = '\\' - altsep = '/' - colon = ':' - unc_prefix = '\\\\?\\UNC\\' - empty = '' - normp = p.replace(altsep, sep) - if normp[:1] == sep: - if normp[1:2] == sep: - # UNC drives, e.g. \\server\share or \\?\UNC\server\share - # Device drives, e.g. \\.\device or \\?\device - start = 8 if normp[:8].upper() == unc_prefix else 2 - index = normp.find(sep, start) - if index == -1: - return p, empty, empty - index2 = normp.find(sep, index + 1) - if index2 == -1: - return p, empty, empty - return p[:index2], p[index2:index2 + 1], p[index2 + 1:] - else: - # Relative path with root, e.g. \Windows - return empty, p[:1], p[1:] - elif normp[1:2] == colon: - if normp[2:3] == sep: - # Absolute drive-letter path, e.g. X:\Windows - return p[:2], p[2:3], p[3:] + def _path_join(*path_parts): + """Replacement for os.path.join().""" + if not path_parts: + return "" + if len(path_parts) == 1: + return path_parts[0] + root = "" + path = [] + for new_root, tail in map(_os._path_splitroot, path_parts): + if new_root.startswith(path_sep_tuple) or new_root.endswith(path_sep_tuple): + root = new_root.rstrip(path_separators) or root + path = [path_sep + tail] + elif new_root.endswith(':'): + if root.casefold() != new_root.casefold(): + # Drive relative paths have to be resolved by the OS, so we reset the + # tail but do not add a path_sep prefix. + root = new_root + path = [tail] + else: + path.append(tail) else: - # Relative path with drive, e.g. X:Windows - return p[:2], empty, p[2:] - else: - # Relative path, e.g. Windows - return empty, empty, p + root = new_root or root + path.append(tail) + path = [p.rstrip(path_separators) for p in path if p] + if len(path) == 1 and not path[0]: + # Avoid losing the root's trailing separator when joining with nothing + return root + path_sep + return root + path_sep.join(path) - def _path_join(path, *paths): - """Replacement for os.path.join().""" - sep = '\\' - seps = '\\/' - colon = ':' - if not paths: - path[:0] + sep #23780: Ensure compatible data type even if p is null. - result_drive, result_root, result_path = _path_splitroot(path) - for p in paths: - p_drive, p_root, p_path = _path_splitroot(p) - if p_root: - # Second path is absolute - if p_drive or not result_drive: - result_drive = p_drive - result_root = p_root - result_path = p_path - continue - elif p_drive and p_drive != result_drive: - if p_drive.lower() != result_drive.lower(): - # Different drives => ignore the first path entirely - result_drive = p_drive - result_root = p_root - result_path = p_path - continue - # Same drive in different case - result_drive = p_drive - # Second path is relative to the first - if result_path and result_path[-1] not in seps: - result_path = result_path + sep - result_path = result_path + p_path - ## add separator between UNC and non-absolute path - if (result_path and not result_root and - result_drive and result_drive[-1:] != colon): - return result_drive + sep + result_path - return result_drive + result_root + result_path else: def _path_join(*path_parts): """Replacement for os.path.join().""" @@ -213,8 +173,8 @@ def _path_isabs(path): """Replacement for os.path.isabs.""" if not path: return False - root = path[:3].replace('/', '\\') - return root.startswith('\\\\') or root.startswith(':\\', 1) + root = _os._path_splitroot(path)[0].replace('/', '\\') + return len(root) > 1 and (root.startswith('\\\\') or root.endswith('\\')) else: def _path_isabs(path): @@ -222,22 +182,12 @@ def _path_isabs(path): return path.startswith(path_separators) -def _path_abspath(path): - """Replacement for os.path.abspath.""" - if not _path_isabs(path): - for sep in path_separators: - path = path.removeprefix(f".{sep}") - return _path_join(_os.getcwd(), path) - else: - return path - - def _write_atomic(path, data, mode=0o666): """Best-effort function to write data to a path atomically. Be prepared to handle a FileExistsError if concurrent writing of the temporary file is attempted.""" # id() is used to generate a pseudo-random filename. - path_tmp = f'{path}.{id(path)}' + path_tmp = '{}.{}'.format(path, id(path)) fd = _os.open(path_tmp, _os.O_EXCL | _os.O_CREAT | _os.O_WRONLY, mode & 0o666) try: @@ -461,22 +411,10 @@ def _write_atomic(path, data, mode=0o666): # Python 3.12a1 3505 (Specialization/Cache for FOR_ITER) # Python 3.12a1 3506 (Add BINARY_SLICE and STORE_SLICE instructions) # Python 3.12a1 3507 (Set lineno of module's RESUME to 0) -# Python 3.12a1 3508 (Add CLEANUP_THROW) -# Python 3.12a1 3509 (Conditional jumps only jump forward) -# Python 3.12a2 3510 (FOR_ITER leaves iterator on the stack) -# Python 3.12a2 3511 (Add STOPITERATION_ERROR instruction) -# Python 3.12a2 3512 (Remove all unused consts from code objects) -# Python 3.12a4 3513 (Add CALL_INTRINSIC_1 instruction, removed STOPITERATION_ERROR, PRINT_EXPR, IMPORT_STAR) -# Python 3.12a4 3514 (Remove ASYNC_GEN_WRAP, LIST_TO_TUPLE, and UNARY_POSITIVE) -# Python 3.12a5 3515 (Embed jump mask in COMPARE_OP oparg) -# Python 3.12a5 3516 (Add COMPARE_AND_BRANCH instruction) -# Python 3.12a5 3517 (Change YIELD_VALUE oparg to exception block depth) -# Python 3.12a5 3518 (Add RETURN_CONST instruction) -# Python 3.12a5 3519 (Modify SEND instruction) -# Python 3.12a5 3520 (Remove PREP_RERAISE_STAR, add CALL_INTRINSIC_2) # Python 3.13 will start with 3550 +# # MAGIC must change whenever the bytecode emitted by the compiler may no # longer be understood by older implementations of the eval loop (usually # due to the addition of new opcodes). @@ -486,7 +424,7 @@ def _write_atomic(path, data, mode=0o666): # Whenever MAGIC_NUMBER is changed, the ranges in the magic_values array # in PC/launcher.c must also be updated. -MAGIC_NUMBER = (3520).to_bytes(2, 'little') + b'\r\n' +MAGIC_NUMBER = (3507).to_bytes(2, 'little') + b'\r\n' _RAW_MAGIC_NUMBER = int.from_bytes(MAGIC_NUMBER, 'little') # For import.c @@ -543,8 +481,8 @@ def cache_from_source(path, debug_override=None, *, optimization=None): optimization = str(optimization) if optimization != '': if not optimization.isalnum(): - raise ValueError(f'{optimization!r} is not alphanumeric') - almost_filename = f'{almost_filename}.{_OPT}{optimization}' + raise ValueError('{!r} is not alphanumeric'.format(optimization)) + almost_filename = '{}.{}{}'.format(almost_filename, _OPT, optimization) filename = almost_filename + BYTECODE_SUFFIXES[0] if sys.pycache_prefix is not None: # We need an absolute path to the py file to avoid the possibility of @@ -555,7 +493,8 @@ def cache_from_source(path, debug_override=None, *, optimization=None): # make it absolute (`C:\Somewhere\Foo\Bar`), then make it root-relative # (`Somewhere\Foo\Bar`), so we end up placing the bytecode file in an # unambiguous `C:\Bytecode\Somewhere\Foo\Bar\`. - head = _path_abspath(head) + if not _path_isabs(head): + head = _path_join(_os.getcwd(), head) # Strip initial drive from a Windows path. We know we have an absolute # path here, so the second part of the check rules out a POSIX path that @@ -702,8 +641,8 @@ def _find_module_shim(self, fullname): # return None. loader, portions = self.find_loader(fullname) if loader is None and len(portions): - msg = f'Not importing directory {portions[0]}: missing __init__' - _warnings.warn(msg, ImportWarning) + msg = 'Not importing directory {}: missing __init__' + _warnings.warn(msg.format(portions[0]), ImportWarning) return loader @@ -801,7 +740,7 @@ def _compile_bytecode(data, name=None, bytecode_path=None, source_path=None): _imp._fix_co_filename(code, source_path) return code else: - raise ImportError(f'Non-code object in {bytecode_path!r}', + raise ImportError('Non-code object in {!r}'.format(bytecode_path), name=name, path=bytecode_path) @@ -868,10 +807,11 @@ def spec_from_file_location(name, location=None, *, loader=None, pass else: location = _os.fspath(location) - try: - location = _path_abspath(location) - except OSError: - pass + if not _path_isabs(location): + try: + location = _path_join(_os.getcwd(), location) + except OSError: + pass # If the location is on the filesystem, but doesn't actually exist, # we could return None here, indicating that the location is not @@ -913,54 +853,6 @@ def spec_from_file_location(name, location=None, *, loader=None, return spec -def _bless_my_loader(module_globals): - """Helper function for _warnings.c - - See GH#97850 for details. - """ - # 2022-10-06(warsaw): For now, this helper is only used in _warnings.c and - # that use case only has the module globals. This function could be - # extended to accept either that or a module object. However, in the - # latter case, it would be better to raise certain exceptions when looking - # at a module, which should have either a __loader__ or __spec__.loader. - # For backward compatibility, it is possible that we'll get an empty - # dictionary for the module globals, and that cannot raise an exception. - if not isinstance(module_globals, dict): - return None - - missing = object() - loader = module_globals.get('__loader__', None) - spec = module_globals.get('__spec__', missing) - - if loader is None: - if spec is missing: - # If working with a module: - # raise AttributeError('Module globals is missing a __spec__') - return None - elif spec is None: - raise ValueError('Module globals is missing a __spec__.loader') - - spec_loader = getattr(spec, 'loader', missing) - - if spec_loader in (missing, None): - if loader is None: - exc = AttributeError if spec_loader is missing else ValueError - raise exc('Module globals is missing a __spec__.loader') - _warnings.warn( - 'Module globals is missing a __spec__.loader', - DeprecationWarning) - spec_loader = loader - - assert spec_loader is not None - if loader is not None and loader != spec_loader: - _warnings.warn( - 'Module globals; __loader__ != __spec__.loader', - DeprecationWarning) - return loader - - return spec_loader - - # Loaders ##################################################################### class WindowsRegistryFinder: @@ -1050,8 +942,8 @@ def exec_module(self, module): """Execute the module.""" code = self.get_code(module.__name__) if code is None: - raise ImportError(f'cannot load module {module.__name__!r} when ' - 'get_code() returns None') + raise ImportError('cannot load module {!r} when get_code() ' + 'returns None'.format(module.__name__)) _bootstrap._call_with_frames_removed(exec, code, module.__dict__) def load_module(self, fullname): @@ -1192,8 +1084,7 @@ def get_code(self, fullname): source_mtime is not None): if hash_based: if source_hash is None: - source_hash = _imp.source_hash(_RAW_MAGIC_NUMBER, - source_bytes) + source_hash = _imp.source_hash(source_bytes) data = _code_to_hash_pyc(code_object, source_hash, check_source) else: data = _code_to_timestamp_pyc(code_object, source_mtime, @@ -1437,7 +1328,7 @@ def __len__(self): return len(self._recalculate()) def __repr__(self): - return f'_NamespacePath({self._path!r})' + return '_NamespacePath({!r})'.format(self._path) def __contains__(self, item): return item in self._recalculate() @@ -1448,11 +1339,22 @@ def append(self, item): # This class is actually exposed publicly in a namespace package's __loader__ # attribute, so it should be available through a non-private name. -# https://github.com/python/cpython/issues/92054 +# https://bugs.python.org/issue35673 class NamespaceLoader: def __init__(self, name, path, path_finder): self._path = _NamespacePath(name, path, path_finder) + @staticmethod + def module_repr(module): + """Return repr for the module. + + The method is deprecated. The import machinery does the job itself. + + """ + _warnings.warn("NamespaceLoader.module_repr() is deprecated and " + "slated for removal in Python 3.12", DeprecationWarning) + return ''.format(module.__name__) + def is_package(self, fullname): return True @@ -1672,8 +1574,10 @@ def __init__(self, path, *loader_details): # Base (directory) path if not path or path == '.': self.path = _os.getcwd() + elif not _path_isabs(path): + self.path = _path_join(_os.getcwd(), path) else: - self.path = _path_abspath(path) + self.path = path self._path_mtime = -1 self._path_cache = set() self._relaxed_path_cache = set() @@ -1778,7 +1682,7 @@ def _fill_cache(self): for item in contents: name, dot, suffix = item.partition('.') if dot: - new_name = f'{name}.{suffix.lower()}' + new_name = '{}.{}'.format(name, suffix.lower()) else: new_name = name lower_suffix_contents.add(new_name) @@ -1805,7 +1709,7 @@ def path_hook_for_FileFinder(path): return path_hook_for_FileFinder def __repr__(self): - return f'FileFinder({self.path!r})' + return 'FileFinder({!r})'.format(self.path) # Import setup ############################################################### @@ -1823,8 +1727,6 @@ def _fix_up_module(ns, name, pathname, cpathname=None): loader = SourceFileLoader(name, pathname) if not spec: spec = spec_from_file_location(name, pathname, loader=loader) - if cpathname: - spec.cached = _path_abspath(cpathname) try: ns['__spec__'] = spec ns['__loader__'] = loader diff --git a/Modules/clinic/posixmodule.c.h b/Modules/clinic/posixmodule.c.h index b95ad9b52dc1be..102e0228eea252 100644 --- a/Modules/clinic/posixmodule.c.h +++ b/Modules/clinic/posixmodule.c.h @@ -1730,7 +1730,7 @@ os__getvolumepathname(PyObject *module, PyObject *const *args, Py_ssize_t nargs, #endif /* defined(MS_WINDOWS) */ -#if defined(MS_WINDOWS) && !defined(MS_WINDOWS_GAMES) +#if defined(MS_WINDOWS) PyDoc_STRVAR(os__path_splitroot__doc__, "_path_splitroot($module, /, path)\n" @@ -1792,7 +1792,7 @@ os__path_splitroot(PyObject *module, PyObject *const *args, Py_ssize_t nargs, Py return return_value; } -#endif /* defined(MS_WINDOWS) && !defined(MS_WINDOWS_GAMES) */ +#endif /* defined(MS_WINDOWS) */ #if defined(MS_WINDOWS) @@ -11796,4 +11796,4 @@ os_waitstatus_to_exitcode(PyObject *module, PyObject *const *args, Py_ssize_t na #ifndef OS_WAITSTATUS_TO_EXITCODE_METHODDEF #define OS_WAITSTATUS_TO_EXITCODE_METHODDEF #endif /* !defined(OS_WAITSTATUS_TO_EXITCODE_METHODDEF) */ -/*[clinic end generated code: output=b0f2b074f9ddc243 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=c65f0b8b54f5ef41 input=a9049054013a1b77]*/ diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index a201eb3d3145cd..6f4427e0435d49 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -4419,7 +4419,6 @@ os__getvolumepathname_impl(PyObject *module, path_t *path) return result; } -#ifndef MS_WINDOWS_GAMES /*[clinic input] os._path_splitroot @@ -4447,9 +4446,32 @@ os__path_splitroot_impl(PyObject *module, path_t *path) *p = L'\\'; } +#if MS_WINDOWS_GAMES + /* network share */ + if (buffer[0] == L'\\' && buffer[1] == L'\\') { + end = buffer + 2; + for (int i = 0; i < 2; ++i) { + end = wcschr(end, '\\'); + if (end == NULL) { + break; + } + end++; + } + ret = (end != NULL) ? S_OK : E_INVALIDARG; + } + /* Check for absolute drive path */ + else if (buffer[0] && buffer[1] == L':' && buffer[2] == L'\\') { + end = buffer + 3; + ret = S_OK; + } + else { + ret = E_INVALIDARG; + } +#else Py_BEGIN_ALLOW_THREADS ret = PathCchSkipRoot(buffer, &end); Py_END_ALLOW_THREADS +#endif if (FAILED(ret)) { result = Py_BuildValue("sO", "", path->object); } else if (end != buffer) { @@ -4466,8 +4488,6 @@ os__path_splitroot_impl(PyObject *module, path_t *path) return result; } -#endif /* MS_WINDOWS_GAMES */ - /*[clinic input] os._path_isdir From 2a2a8fdf8bc9d2921e7440903c53ae42fd30be1a Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Tue, 28 Feb 2023 05:42:21 +0100 Subject: [PATCH 058/100] fix revert of changes to _bootstrap_external --- Lib/importlib/_bootstrap_external.py | 130 +++++++++++++++++++-------- 1 file changed, 94 insertions(+), 36 deletions(-) diff --git a/Lib/importlib/_bootstrap_external.py b/Lib/importlib/_bootstrap_external.py index b6c6716e907734..954401cfa85ed3 100644 --- a/Lib/importlib/_bootstrap_external.py +++ b/Lib/importlib/_bootstrap_external.py @@ -182,12 +182,22 @@ def _path_isabs(path): return path.startswith(path_separators) +def _path_abspath(path): + """Replacement for os.path.abspath.""" + if not _path_isabs(path): + for sep in path_separators: + path = path.removeprefix(f".{sep}") + return _path_join(_os.getcwd(), path) + else: + return path + + def _write_atomic(path, data, mode=0o666): """Best-effort function to write data to a path atomically. Be prepared to handle a FileExistsError if concurrent writing of the temporary file is attempted.""" # id() is used to generate a pseudo-random filename. - path_tmp = '{}.{}'.format(path, id(path)) + path_tmp = f'{path}.{id(path)}' fd = _os.open(path_tmp, _os.O_EXCL | _os.O_CREAT | _os.O_WRONLY, mode & 0o666) try: @@ -411,10 +421,22 @@ def _write_atomic(path, data, mode=0o666): # Python 3.12a1 3505 (Specialization/Cache for FOR_ITER) # Python 3.12a1 3506 (Add BINARY_SLICE and STORE_SLICE instructions) # Python 3.12a1 3507 (Set lineno of module's RESUME to 0) +# Python 3.12a1 3508 (Add CLEANUP_THROW) +# Python 3.12a1 3509 (Conditional jumps only jump forward) +# Python 3.12a2 3510 (FOR_ITER leaves iterator on the stack) +# Python 3.12a2 3511 (Add STOPITERATION_ERROR instruction) +# Python 3.12a2 3512 (Remove all unused consts from code objects) +# Python 3.12a4 3513 (Add CALL_INTRINSIC_1 instruction, removed STOPITERATION_ERROR, PRINT_EXPR, IMPORT_STAR) +# Python 3.12a4 3514 (Remove ASYNC_GEN_WRAP, LIST_TO_TUPLE, and UNARY_POSITIVE) +# Python 3.12a5 3515 (Embed jump mask in COMPARE_OP oparg) +# Python 3.12a5 3516 (Add COMPARE_AND_BRANCH instruction) +# Python 3.12a5 3517 (Change YIELD_VALUE oparg to exception block depth) +# Python 3.12a5 3518 (Add RETURN_CONST instruction) +# Python 3.12a5 3519 (Modify SEND instruction) +# Python 3.12a5 3520 (Remove PREP_RERAISE_STAR, add CALL_INTRINSIC_2) # Python 3.13 will start with 3550 -# # MAGIC must change whenever the bytecode emitted by the compiler may no # longer be understood by older implementations of the eval loop (usually # due to the addition of new opcodes). @@ -424,7 +446,7 @@ def _write_atomic(path, data, mode=0o666): # Whenever MAGIC_NUMBER is changed, the ranges in the magic_values array # in PC/launcher.c must also be updated. -MAGIC_NUMBER = (3507).to_bytes(2, 'little') + b'\r\n' +MAGIC_NUMBER = (3520).to_bytes(2, 'little') + b'\r\n' _RAW_MAGIC_NUMBER = int.from_bytes(MAGIC_NUMBER, 'little') # For import.c @@ -481,8 +503,8 @@ def cache_from_source(path, debug_override=None, *, optimization=None): optimization = str(optimization) if optimization != '': if not optimization.isalnum(): - raise ValueError('{!r} is not alphanumeric'.format(optimization)) - almost_filename = '{}.{}{}'.format(almost_filename, _OPT, optimization) + raise ValueError(f'{optimization!r} is not alphanumeric') + almost_filename = f'{almost_filename}.{_OPT}{optimization}' filename = almost_filename + BYTECODE_SUFFIXES[0] if sys.pycache_prefix is not None: # We need an absolute path to the py file to avoid the possibility of @@ -493,8 +515,7 @@ def cache_from_source(path, debug_override=None, *, optimization=None): # make it absolute (`C:\Somewhere\Foo\Bar`), then make it root-relative # (`Somewhere\Foo\Bar`), so we end up placing the bytecode file in an # unambiguous `C:\Bytecode\Somewhere\Foo\Bar\`. - if not _path_isabs(head): - head = _path_join(_os.getcwd(), head) + head = _path_abspath(head) # Strip initial drive from a Windows path. We know we have an absolute # path here, so the second part of the check rules out a POSIX path that @@ -641,8 +662,8 @@ def _find_module_shim(self, fullname): # return None. loader, portions = self.find_loader(fullname) if loader is None and len(portions): - msg = 'Not importing directory {}: missing __init__' - _warnings.warn(msg.format(portions[0]), ImportWarning) + msg = f'Not importing directory {portions[0]}: missing __init__' + _warnings.warn(msg, ImportWarning) return loader @@ -740,7 +761,7 @@ def _compile_bytecode(data, name=None, bytecode_path=None, source_path=None): _imp._fix_co_filename(code, source_path) return code else: - raise ImportError('Non-code object in {!r}'.format(bytecode_path), + raise ImportError(f'Non-code object in {bytecode_path!r}', name=name, path=bytecode_path) @@ -807,11 +828,10 @@ def spec_from_file_location(name, location=None, *, loader=None, pass else: location = _os.fspath(location) - if not _path_isabs(location): - try: - location = _path_join(_os.getcwd(), location) - except OSError: - pass + try: + location = _path_abspath(location) + except OSError: + pass # If the location is on the filesystem, but doesn't actually exist, # we could return None here, indicating that the location is not @@ -853,6 +873,54 @@ def spec_from_file_location(name, location=None, *, loader=None, return spec +def _bless_my_loader(module_globals): + """Helper function for _warnings.c + + See GH#97850 for details. + """ + # 2022-10-06(warsaw): For now, this helper is only used in _warnings.c and + # that use case only has the module globals. This function could be + # extended to accept either that or a module object. However, in the + # latter case, it would be better to raise certain exceptions when looking + # at a module, which should have either a __loader__ or __spec__.loader. + # For backward compatibility, it is possible that we'll get an empty + # dictionary for the module globals, and that cannot raise an exception. + if not isinstance(module_globals, dict): + return None + + missing = object() + loader = module_globals.get('__loader__', None) + spec = module_globals.get('__spec__', missing) + + if loader is None: + if spec is missing: + # If working with a module: + # raise AttributeError('Module globals is missing a __spec__') + return None + elif spec is None: + raise ValueError('Module globals is missing a __spec__.loader') + + spec_loader = getattr(spec, 'loader', missing) + + if spec_loader in (missing, None): + if loader is None: + exc = AttributeError if spec_loader is missing else ValueError + raise exc('Module globals is missing a __spec__.loader') + _warnings.warn( + 'Module globals is missing a __spec__.loader', + DeprecationWarning) + spec_loader = loader + + assert spec_loader is not None + if loader is not None and loader != spec_loader: + _warnings.warn( + 'Module globals; __loader__ != __spec__.loader', + DeprecationWarning) + return loader + + return spec_loader + + # Loaders ##################################################################### class WindowsRegistryFinder: @@ -942,8 +1010,8 @@ def exec_module(self, module): """Execute the module.""" code = self.get_code(module.__name__) if code is None: - raise ImportError('cannot load module {!r} when get_code() ' - 'returns None'.format(module.__name__)) + raise ImportError(f'cannot load module {module.__name__!r} when ' + 'get_code() returns None') _bootstrap._call_with_frames_removed(exec, code, module.__dict__) def load_module(self, fullname): @@ -1084,7 +1152,8 @@ def get_code(self, fullname): source_mtime is not None): if hash_based: if source_hash is None: - source_hash = _imp.source_hash(source_bytes) + source_hash = _imp.source_hash(_RAW_MAGIC_NUMBER, + source_bytes) data = _code_to_hash_pyc(code_object, source_hash, check_source) else: data = _code_to_timestamp_pyc(code_object, source_mtime, @@ -1328,7 +1397,7 @@ def __len__(self): return len(self._recalculate()) def __repr__(self): - return '_NamespacePath({!r})'.format(self._path) + return f'_NamespacePath({self._path!r})' def __contains__(self, item): return item in self._recalculate() @@ -1339,22 +1408,11 @@ def append(self, item): # This class is actually exposed publicly in a namespace package's __loader__ # attribute, so it should be available through a non-private name. -# https://bugs.python.org/issue35673 +# https://github.com/python/cpython/issues/92054 class NamespaceLoader: def __init__(self, name, path, path_finder): self._path = _NamespacePath(name, path, path_finder) - @staticmethod - def module_repr(module): - """Return repr for the module. - - The method is deprecated. The import machinery does the job itself. - - """ - _warnings.warn("NamespaceLoader.module_repr() is deprecated and " - "slated for removal in Python 3.12", DeprecationWarning) - return ''.format(module.__name__) - def is_package(self, fullname): return True @@ -1574,10 +1632,8 @@ def __init__(self, path, *loader_details): # Base (directory) path if not path or path == '.': self.path = _os.getcwd() - elif not _path_isabs(path): - self.path = _path_join(_os.getcwd(), path) else: - self.path = path + self.path = _path_abspath(path) self._path_mtime = -1 self._path_cache = set() self._relaxed_path_cache = set() @@ -1682,7 +1738,7 @@ def _fill_cache(self): for item in contents: name, dot, suffix = item.partition('.') if dot: - new_name = '{}.{}'.format(name, suffix.lower()) + new_name = f'{name}.{suffix.lower()}' else: new_name = name lower_suffix_contents.add(new_name) @@ -1709,7 +1765,7 @@ def path_hook_for_FileFinder(path): return path_hook_for_FileFinder def __repr__(self): - return 'FileFinder({!r})'.format(self.path) + return f'FileFinder({self.path!r})' # Import setup ############################################################### @@ -1727,6 +1783,8 @@ def _fix_up_module(ns, name, pathname, cpathname=None): loader = SourceFileLoader(name, pathname) if not spec: spec = spec_from_file_location(name, pathname, loader=loader) + if cpathname: + spec.cached = _path_abspath(cpathname) try: ns['__spec__'] = spec ns['__loader__'] = loader From 165286d404177552c408d51028d1f786a529fbf2 Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Tue, 28 Feb 2023 05:47:10 +0100 Subject: [PATCH 059/100] reimplement winreg_QueryValue_impl and winreg_SetValue_impl --- PC/clinic/winreg.c.h | 10 +-- PC/winreg.c | 148 ++++++++++++++++++++++++++++--------------- 2 files changed, 103 insertions(+), 55 deletions(-) diff --git a/PC/clinic/winreg.c.h b/PC/clinic/winreg.c.h index 1938fcff19c853..d55b8e17ee136e 100644 --- a/PC/clinic/winreg.c.h +++ b/PC/clinic/winreg.c.h @@ -1204,7 +1204,7 @@ winreg_QueryInfoKey(PyObject *module, PyObject *arg) #endif /* (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) */ -#if (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) && !defined(MS_WINDOWS_GAMES) +#if (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) PyDoc_STRVAR(winreg_QueryValue__doc__, "QueryValue($module, key, sub_key, /)\n" @@ -1267,7 +1267,7 @@ winreg_QueryValue(PyObject *module, PyObject *const *args, Py_ssize_t nargs) return return_value; } -#endif /* (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) && !defined(MS_WINDOWS_GAMES) */ +#endif /* (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) */ #if (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) @@ -1391,7 +1391,7 @@ winreg_SaveKey(PyObject *module, PyObject *const *args, Py_ssize_t nargs) #endif /* (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) && !defined(MS_WINDOWS_GAMES) */ -#if (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) && !defined(MS_WINDOWS_GAMES) +#if (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) PyDoc_STRVAR(winreg_SetValue__doc__, "SetValue($module, key, sub_key, type, value, /)\n" @@ -1474,7 +1474,7 @@ winreg_SetValue(PyObject *module, PyObject *const *args, Py_ssize_t nargs) return return_value; } -#endif /* (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) && !defined(MS_WINDOWS_GAMES) */ +#endif /* (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) */ #if (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) @@ -1795,4 +1795,4 @@ winreg_QueryReflectionKey(PyObject *module, PyObject *arg) #ifndef WINREG_QUERYREFLECTIONKEY_METHODDEF #define WINREG_QUERYREFLECTIONKEY_METHODDEF #endif /* !defined(WINREG_QUERYREFLECTIONKEY_METHODDEF) */ -/*[clinic end generated code: output=be95e7a8d3498fc6 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=4d3befb1f9c9d05c input=a9049054013a1b77]*/ diff --git a/PC/winreg.c b/PC/winreg.c index f46222ad211d00..873551c3686e95 100644 --- a/PC/winreg.c +++ b/PC/winreg.c @@ -1476,7 +1476,6 @@ winreg_QueryInfoKey_impl(PyObject *module, HKEY key) return ret; } -#ifndef MS_WINDOWS_GAMES /*[clinic input] winreg.QueryValue @@ -1503,56 +1502,77 @@ static PyObject * winreg_QueryValue_impl(PyObject *module, HKEY key, const Py_UNICODE *sub_key) /*[clinic end generated code: output=c655810ae50c63a9 input=41cafbbf423b21d6]*/ { - long rc; - PyObject *retStr; - wchar_t *retBuf; - DWORD bufSize = 0; - DWORD retSize = 0; - wchar_t *tmp; + LONG rc; + HKEY childKey = key; + WCHAR buf[256], *pbuf = buf; + DWORD size = sizeof(buf); + DWORD type; + Py_ssize_t length; + PyObject *result = NULL; if (PySys_Audit("winreg.QueryValue", "nuu", (Py_ssize_t)key, sub_key, NULL) < 0) { return NULL; } - rc = RegQueryValueW(key, sub_key, NULL, &retSize); - if (rc == ERROR_MORE_DATA) - retSize = 256; - else if (rc != ERROR_SUCCESS) - return PyErr_SetFromWindowsErrWithFunction(rc, + + if (key == HKEY_PERFORMANCE_DATA) { + return PyErr_SetFromWindowsErrWithFunction(ERROR_INVALID_HANDLE, "RegQueryValue"); + } - bufSize = retSize; - retBuf = (wchar_t *) PyMem_Malloc(bufSize); - if (retBuf == NULL) - return PyErr_NoMemory(); + if (sub_key && sub_key[0]) { + Py_BEGIN_ALLOW_THREADS + rc = RegOpenKeyExW(key, sub_key, 0, KEY_QUERY_VALUE, &childKey); + Py_END_ALLOW_THREADS + if (rc != ERROR_SUCCESS) { + return PyErr_SetFromWindowsErrWithFunction(rc, "RegOpenKeyEx"); + } + } while (1) { - retSize = bufSize; - rc = RegQueryValueW(key, sub_key, retBuf, &retSize); - if (rc != ERROR_MORE_DATA) + Py_BEGIN_ALLOW_THREADS + rc = RegQueryValueExW(childKey, NULL, NULL, &type, (LPBYTE)pbuf, + &size); + Py_END_ALLOW_THREADS + if (rc != ERROR_MORE_DATA) { break; - - bufSize *= 2; - tmp = (wchar_t *) PyMem_Realloc(retBuf, bufSize); + } + void *tmp = PyMem_Realloc(pbuf != buf ? pbuf : NULL, size); if (tmp == NULL) { - PyMem_Free(retBuf); - return PyErr_NoMemory(); + PyErr_NoMemory(); + goto exit; } - retBuf = tmp; + pbuf = tmp; } - if (rc != ERROR_SUCCESS) { - PyMem_Free(retBuf); - return PyErr_SetFromWindowsErrWithFunction(rc, - "RegQueryValue"); + if (rc == ERROR_SUCCESS) { + if (type != REG_SZ) { + PyErr_SetFromWindowsErrWithFunction(ERROR_INVALID_DATA, + "RegQueryValue"); + goto exit; + } + length = wcsnlen(pbuf, size / sizeof(WCHAR)); + } + else if (rc == ERROR_FILE_NOT_FOUND) { + // Return an empty string if there's no default value. + length = 0; + } + else { + PyErr_SetFromWindowsErrWithFunction(rc, "RegQueryValueEx"); + goto exit; } - retStr = PyUnicode_FromWideChar(retBuf, wcslen(retBuf)); - PyMem_Free(retBuf); - return retStr; -} + result = PyUnicode_FromWideChar(pbuf, length); -#endif /* MS_WINDOWS_GAMES */ +exit: + if (pbuf != buf) { + PyMem_Free(pbuf); + } + if (childKey != key) { + RegCloseKey(childKey); + } + return result; +} /*[clinic input] @@ -1676,8 +1696,6 @@ winreg_SaveKey_impl(PyObject *module, HKEY key, const Py_UNICODE *file_name) #endif /* MS_WINDOWS_GAMES */ -#ifndef MS_WINDOWS_GAMES - /*[clinic input] winreg.SetValue @@ -1710,41 +1728,71 @@ winreg_SetValue_impl(PyObject *module, HKEY key, const Py_UNICODE *sub_key, DWORD type, PyObject *value_obj) /*[clinic end generated code: output=d4773dc9c372311a input=bf088494ae2d24fd]*/ { - Py_ssize_t value_length; - long rc; + LONG rc; + HKEY childKey = key; + LPWSTR value; + Py_ssize_t size; + Py_ssize_t length; + PyObject *result = NULL; if (type != REG_SZ) { PyErr_SetString(PyExc_TypeError, "type must be winreg.REG_SZ"); return NULL; } - wchar_t *value = PyUnicode_AsWideCharString(value_obj, &value_length); + value = PyUnicode_AsWideCharString(value_obj, &length); if (value == NULL) { return NULL; } - if ((Py_ssize_t)(DWORD)value_length != value_length) { + + size = (length + 1) * sizeof(WCHAR); + if ((Py_ssize_t)(DWORD)size != size) { PyErr_SetString(PyExc_OverflowError, "value is too long"); - PyMem_Free(value); - return NULL; + goto exit; } if (PySys_Audit("winreg.SetValue", "nunu#", (Py_ssize_t)key, sub_key, (Py_ssize_t)type, - value, value_length) < 0) { - PyMem_Free(value); - return NULL; + value, length) < 0) + { + goto exit; + } + + if (key == HKEY_PERFORMANCE_DATA) { + PyErr_SetFromWindowsErrWithFunction(ERROR_INVALID_HANDLE, + "RegSetValue"); + goto exit; + } + + if (sub_key && sub_key[0]) { + Py_BEGIN_ALLOW_THREADS + rc = RegCreateKeyExW(key, sub_key, 0, NULL, 0, KEY_SET_VALUE, NULL, + &childKey, NULL); + Py_END_ALLOW_THREADS + if (rc != ERROR_SUCCESS) { + PyErr_SetFromWindowsErrWithFunction(rc, "RegCreateKeyEx"); + goto exit; + } } Py_BEGIN_ALLOW_THREADS - rc = RegSetValueW(key, sub_key, REG_SZ, value, (DWORD)(value_length + 1)); + rc = RegSetValueExW(childKey, NULL, 0, REG_SZ, (LPBYTE)value, (DWORD)size); Py_END_ALLOW_THREADS + if (rc == ERROR_SUCCESS) { + result = Py_NewRef(Py_None); + } + else { + PyErr_SetFromWindowsErrWithFunction(rc, "RegSetValueEx"); + } + +exit: PyMem_Free(value); - if (rc != ERROR_SUCCESS) - return PyErr_SetFromWindowsErrWithFunction(rc, "RegSetValue"); - Py_RETURN_NONE; + if (childKey != key) { + RegCloseKey(childKey); + } + return result; } -#endif /* MS_WINDOWS_GAMES */ /*[clinic input] winreg.SetValueEx From 141384976a9aa5be3f239970593d68479200ece2 Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Tue, 28 Feb 2023 05:48:18 +0100 Subject: [PATCH 060/100] Update Python/fileutils.c Co-authored-by: Eryk Sun --- Python/fileutils.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Python/fileutils.c b/Python/fileutils.c index 4d1768a00bbe7e..70ff355f4857d4 100644 --- a/Python/fileutils.c +++ b/Python/fileutils.c @@ -1273,6 +1273,8 @@ _Py_stat(PyObject *path, struct stat *statbuf) } #ifdef MS_WINDOWS +// For some Windows API partitions, SetHandleInformation() is declared +// but none of the handle flags are defined. #ifndef HANDLE_FLAG_INHERIT #define HANDLE_FLAG_INHERIT 0x00000001 #endif From 6465d73d61660175f2c604541cab1c14cbf5fb8e Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Tue, 28 Feb 2023 07:20:11 +0100 Subject: [PATCH 061/100] move skip root to own function --- Modules/posixmodule.c | 56 +++++++++++++++++++++++++++---------------- 1 file changed, 36 insertions(+), 20 deletions(-) diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 6f4427e0435d49..42a3d0d92c3945 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -4419,6 +4419,40 @@ os__getvolumepathname_impl(PyObject *module, path_t *path) return result; } +#if MS_WINDOWS_GAMES +// The Windows Games API partition does not provide PathCchSkipRoot +// so we need our own implementation +static wchar_t* +win32_games_skip_root(wchar_t* path) +{ + if (path[0] == L'\\') { + /* relative path with root e.g. \Windows */ + if (path[1] != L'\\') { + return path + 1; + } + + /* UNC drives e.g. \\server\share or \\?\UNC\server\share */ + wchar_t *end = path + 2; + if (!wcsnicmp(end, L"?\\UNC\\", 6)) { + end += 6; + } + + end = wcschr(end, '\\'); + if (!end) { + return path + wcslen(path); + } + end = wcschr(end + 1, '\\'); + return (!end) ? wcslen(path) : end + 1; + } + /* absolute / relative path with drive, e.g. C: or C:\ */ + else if (isalpha(path[0]) && path[1] == L':') { + return (path[2] == L'\\') ? path + 3 : path + 2; + } + + /* relative path */ + return NULL; +} +#endif /*[clinic input] os._path_splitroot @@ -4447,26 +4481,8 @@ os__path_splitroot_impl(PyObject *module, path_t *path) } #if MS_WINDOWS_GAMES - /* network share */ - if (buffer[0] == L'\\' && buffer[1] == L'\\') { - end = buffer + 2; - for (int i = 0; i < 2; ++i) { - end = wcschr(end, '\\'); - if (end == NULL) { - break; - } - end++; - } - ret = (end != NULL) ? S_OK : E_INVALIDARG; - } - /* Check for absolute drive path */ - else if (buffer[0] && buffer[1] == L':' && buffer[2] == L'\\') { - end = buffer + 3; - ret = S_OK; - } - else { - ret = E_INVALIDARG; - } + end = win32_games_skip_root(buffer); + ret = (end != NULL) ? S_OK : E_INVALIDARG; #else Py_BEGIN_ALLOW_THREADS ret = PathCchSkipRoot(buffer, &end); From 3f0c6f08e90cd98f6a051d58a9f9b20fc4ace9be Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Tue, 28 Feb 2023 07:46:15 +0100 Subject: [PATCH 062/100] cleanup --- Modules/posixmodule.c | 4 ++-- Python/fileutils.c | 8 +------- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 42a3d0d92c3945..cd9570da3ddc40 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -4419,7 +4419,7 @@ os__getvolumepathname_impl(PyObject *module, path_t *path) return result; } -#if MS_WINDOWS_GAMES +#ifdef MS_WINDOWS_GAMES // The Windows Games API partition does not provide PathCchSkipRoot // so we need our own implementation static wchar_t* @@ -4480,7 +4480,7 @@ os__path_splitroot_impl(PyObject *module, path_t *path) *p = L'\\'; } -#if MS_WINDOWS_GAMES +#ifdef MS_WINDOWS_GAMES end = win32_games_skip_root(buffer); ret = (end != NULL) ? S_OK : E_INVALIDARG; #else diff --git a/Python/fileutils.c b/Python/fileutils.c index 70ff355f4857d4..f2cb224ada9909 100644 --- a/Python/fileutils.c +++ b/Python/fileutils.c @@ -1371,17 +1371,11 @@ set_inheritable(int fd, int inheritable, int raise, int *atomic_flag_works) else flags = 0; - /* This check can be removed once support for Windows 7 ends. */ -#define CONSOLE_PSEUDOHANDLE(handle) (((ULONG_PTR)(handle) & 0x3) == 0x3 && \ - GetFileType(handle) == FILE_TYPE_CHAR) - - if (!CONSOLE_PSEUDOHANDLE(handle) && - !SetHandleInformation(handle, HANDLE_FLAG_INHERIT, flags)) { + if (!SetHandleInformation(handle, HANDLE_FLAG_INHERIT, flags)) { if (raise) PyErr_SetFromWindowsErr(0); return -1; } -#undef CONSOLE_PSEUDOHANDLE return 0; #else From 8f3a2629722166bb329428b9f6f5cb3f0a5ae614 Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Tue, 28 Feb 2023 11:41:38 +0100 Subject: [PATCH 063/100] better handle joinfile on xbox --- Modules/posixmodule.c | 2 +- Python/fileutils.c | 92 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 92 insertions(+), 2 deletions(-) diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index cd9570da3ddc40..19f7a4a11de8af 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -4442,7 +4442,7 @@ win32_games_skip_root(wchar_t* path) return path + wcslen(path); } end = wcschr(end + 1, '\\'); - return (!end) ? wcslen(path) : end + 1; + return (!end) ? path + wcslen(path) : end + 1; } /* absolute / relative path with drive, e.g. C: or C:\ */ else if (isalpha(path[0]) && path[1] == L':') { diff --git a/Python/fileutils.c b/Python/fileutils.c index f2cb224ada9909..3aa81513266f3d 100644 --- a/Python/fileutils.c +++ b/Python/fileutils.c @@ -2117,6 +2117,91 @@ _Py_abspath(const wchar_t *path, wchar_t **abspath_p) #endif } +#ifdef MS_WINDOWS_GAMES +static wchar_t* +win32_games_skip_root(wchar_t* path) +{ + if (path[0] == '\\') { + /* relative path with root e.g. \Windows */ + if (path[1] != '\\') { + return path + 1; + } + + /* UNC drives e.g. \\server\share or \\?\UNC\server\share */ + wchar_t *end = path + 2; + if (!wcsnicmp(end, L"?\\UNC\\", 6)) { + end += 6; + } + + end = wcschr(end, '\\'); + if (!end) { + return path + wcslen(path); + } + end = wcschr(end + 1, '\\'); + return (!end) ? path + wcslen(path) : end + 1; + } + /* absolute / relative path with drive, e.g. C: or C:\ */ + else if (isalpha(path[0]) && path[1] == ':') { + return (path[2] == '\\') ? path + 3 : path + 2; + } + + /* relative path */ + return NULL; +} + +// The Windows Games API partition does not provide PathCchCombineEx +// so we need our own implementation +static int +win32_games_join_relfile(wchar_t *buffer, size_t bufsize, + const wchar_t *dirname, const wchar_t *relfile) +{ + if ((isalpha(relfile[0]) && relfile[1] == ':') || + (relfile[0] == '\\' && relfile[1] == '\\')) + { + dirname = relfile; + relfile = NULL; + } + + size_t dir_len = wcslen(dirname); + size_t file_len = relfile ? wcslen(relfile) : 0; + /* path is at max dirname + filename + backslash + \0 */ + size_t new_len = dir_len + file_len + 2; + if (bufsize >= MAXPATHLEN || new_len > bufsize) { + return -1; + } + + size_t combined_length = dir_len; + wcscpy(buffer, dirname); + if (!relfile || !relfile[0]) { + if(wcsncmp(buffer, L"\\\\?\\", 4)) { + buffer += 4; + } + if (isalpha(buffer[0]) && buffer[1] == ':') { + if (!buffer[2]) { + buffer[2] = '\\'; + buffer[3] = '\0'; + } + } + } + else { + if (relfile[0] == '\\' && relfile[1] != '\\') + { + wchar_t* root_end = win32_games_skip_root(buffer); + if (root_end) { + *root_end = '\0'; + } + combined_length = root_end - buffer; + relfile++; + } + if (combined_length && buffer[combined_length - 1] != '\\') { + buffer[combined_length++] = '\\'; + buffer[combined_length] = '\0'; + } + wcscat(buffer, relfile); + } + return 0; +} +#endif /* MS_WINDOWS_GAMES */ // The caller must ensure "buffer" is big enough. static int @@ -2124,10 +2209,15 @@ join_relfile(wchar_t *buffer, size_t bufsize, const wchar_t *dirname, const wchar_t *relfile) { #if defined(MS_WINDOWS) && !defined(MS_WINDOWS_GAMES) +#ifdef MS_WINDOWS_GAMES + return win32_games_join_relfile(buffer, bufsize, dirname, relfile) +#else if (FAILED(PathCchCombineEx(buffer, bufsize, dirname, relfile, PATHCCH_ALLOW_LONG_PATHS))) { return -1; } + return 0; +#endif #else assert(!_Py_isabs(relfile)); size_t dirlen = wcslen(dirname); @@ -2151,8 +2241,8 @@ join_relfile(wchar_t *buffer, size_t bufsize, } wcscpy(&buffer[relstart], relfile); } -#endif return 0; +#endif } /* Join the two paths together, like os.path.join(). Return NULL From 6b8074ef24819f0cf449fbdd212f32a83460a821 Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Tue, 28 Feb 2023 19:51:24 +0100 Subject: [PATCH 064/100] cleanup --- Modules/_io/_iomodule.c | 6 +++--- Modules/_io/_iomodule.h | 4 ++-- Modules/_io/winconsoleio.c | 2 +- Modules/_randommodule.c | 4 ++-- Modules/_ssl.c | 2 +- Modules/posixmodule.c | 2 +- PC/pyconfig.h | 5 +++++ Parser/myreadline.c | 6 +++--- Python/pylifecycle.c | 2 +- 9 files changed, 19 insertions(+), 14 deletions(-) diff --git a/Modules/_io/_iomodule.c b/Modules/_io/_iomodule.c index 461f42556c4305..1506755427fc0d 100644 --- a/Modules/_io/_iomodule.c +++ b/Modules/_io/_iomodule.c @@ -317,7 +317,7 @@ _io_open_impl(PyObject *module, PyObject *file, const char *mode, _PyIO_State *state = get_io_state(module); { PyObject *RawIO_class = (PyObject *)state->PyFileIO_Type; -#if defined(MS_WINDOWS) && !defined(MS_WINDOWS_GAMES) +#ifdef HAVE_WINDOWS_CONSOLE_IO const PyConfig *config = _Py_GetConfig(); if (!config->legacy_windows_stdio && _PyIO_get_console_type(path_or_fd) != '\0') { RawIO_class = (PyObject *)&PyWindowsConsoleIO_Type; @@ -660,7 +660,7 @@ static PyTypeObject* static_types[] = { // PyRawIOBase_Type(PyIOBase_Type) subclasses &_PyBytesIOBuffer_Type, -#if defined(MS_WINDOWS) && !defined(MS_WINDOWS_GAMES) +#ifdef HAVE_WINDOWS_CONSOLE_IO &PyWindowsConsoleIO_Type, #endif }; @@ -718,7 +718,7 @@ PyInit__io(void) } // Set type base classes -#if defined(MS_WINDOWS) && !defined(MS_WINDOWS_GAMES) +#ifdef HAVE_WINDOWS_CONSOLE_IO PyWindowsConsoleIO_Type.tp_base = &PyRawIOBase_Type; #endif diff --git a/Modules/_io/_iomodule.h b/Modules/_io/_iomodule.h index 8bb627de157d87..8299b3a6a19a0a 100644 --- a/Modules/_io/_iomodule.h +++ b/Modules/_io/_iomodule.h @@ -26,7 +26,7 @@ extern PyType_Spec fileio_spec; extern PyType_Spec stringio_spec; extern PyType_Spec textiowrapper_spec; -#if defined(MS_WINDOWS) && !defined(MS_WINDOWS_GAMES) +#ifdef HAVE_WINDOWS_CONSOLE_IO extern PyTypeObject PyWindowsConsoleIO_Type; #endif /* MS_WINDOWS && !MS_WINDOWS_GAMES */ @@ -178,7 +178,7 @@ find_io_state_by_def(PyTypeObject *type) extern _PyIO_State *_PyIO_get_module_state(void); -#if defined(MS_WINDOWS) && !defined(MS_WINDOWS_GAMES) +#ifdef HAVE_WINDOWS_CONSOLE_IO extern char _PyIO_get_console_type(PyObject *); #endif diff --git a/Modules/_io/winconsoleio.c b/Modules/_io/winconsoleio.c index c0ebaf75c8bd5c..de49318cbb0d1a 100644 --- a/Modules/_io/winconsoleio.c +++ b/Modules/_io/winconsoleio.c @@ -11,7 +11,7 @@ #include "pycore_fileutils.h" // _Py_BEGIN_SUPPRESS_IPH #include "pycore_object.h" // _PyObject_GC_UNTRACK() -#if defined(MS_WINDOWS) && !defined(MS_WINDOWS_GAMES) +#ifdef HAVE_WINDOWS_CONSOLE_IO #include "structmember.h" // PyMemberDef #ifdef HAVE_SYS_TYPES_H diff --git a/Modules/_randommodule.c b/Modules/_randommodule.c index 09e445a4b0f8d5..ddba7e6d5e0179 100644 --- a/Modules/_randommodule.c +++ b/Modules/_randommodule.c @@ -77,8 +77,8 @@ # include // getpid() #endif -#ifdef MS_WINDOWS_NON_DESKTOP -# include +#ifdef MS_WINDOWS +# include #endif /* Period parameters -- These are all magic. Don't change. */ diff --git a/Modules/_ssl.c b/Modules/_ssl.c index 0c504700f48e6a..28112317bc289e 100644 --- a/Modules/_ssl.c +++ b/Modules/_ssl.c @@ -28,7 +28,7 @@ /* Include symbols from _socket module */ #include "socketmodule.h" -#ifdef MS_WINDOWS_GAMES +#ifdef MS_WINDOWS # include #endif diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 19f7a4a11de8af..e967fead2705c2 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -313,7 +313,7 @@ corresponding Unix manual entries for more information on calls."); # include #endif -#if defined(MS_WINDOWS) && !defined(MS_WINDOWS_GAMES) +#ifdef HAVE_WINDOWS_CONSOLE_IO # define TERMSIZE_USE_CONIO #elif defined(HAVE_SYS_IOCTL_H) # include diff --git a/PC/pyconfig.h b/PC/pyconfig.h index 2d651172d53e63..71992a4f364b13 100644 --- a/PC/pyconfig.h +++ b/PC/pyconfig.h @@ -392,6 +392,11 @@ Py_NO_ENABLE_SHARED to find out. Also support MS_NO_COREDLL for b/w compat */ /* Define to 1 if you have the header file. */ #define HAVE_CONIO_H 1 +/* Define to 1 if you support windows console io */ +#if defined(Py_BUILD_CORE) && !defined(MS_WINDOWS_GAMES) +#define HAVE_WINDOWS_CONSOLE_IO 1 +#endif + /* Define to 1 if you have the header file. */ #define HAVE_DIRECT_H 1 diff --git a/Parser/myreadline.c b/Parser/myreadline.c index 7800574ac04dfa..3f0e29f051a438 100644 --- a/Parser/myreadline.c +++ b/Parser/myreadline.c @@ -110,7 +110,7 @@ my_fgets(PyThreadState* tstate, char *buf, int len, FILE *fp) /* NOTREACHED */ } -#if defined(MS_WINDOWS) && !defined(MS_WINDOWS_GAMES) +#ifdef HAVE_WINDOWS_CONSOLE_IO /* Readline implementation using ReadConsoleW */ extern char _get_console_type(HANDLE handle); @@ -235,7 +235,7 @@ _PyOS_WindowsConsoleReadline(PyThreadState *tstate, HANDLE hStdIn) return buf; } -#endif +#endif /* HAVE_WINDOWS_CONSOLE_IO */ /* Readline implementation using fgets() */ @@ -248,7 +248,7 @@ PyOS_StdioReadline(FILE *sys_stdin, FILE *sys_stdout, const char *prompt) PyThreadState *tstate = _PyOS_ReadlineTState; assert(tstate != NULL); -#if defined(MS_WINDOWS) && !defined(MS_WINDOWS_GAMES) +#ifdef HAVE_WINDOWS_CONSOLE_IO const PyConfig *config = _PyInterpreterState_GetConfig(tstate->interp); if (!config->legacy_windows_stdio && sys_stdin == stdin) { HANDLE hStdIn, hStdErr; diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index fb7177b0d74dc1..82e94090a6027a 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -2289,7 +2289,7 @@ create_stdio(const PyConfig *config, PyObject* io, raw = Py_NewRef(buf); } -#if defined(MS_WINDOWS) && !defined(MS_WINDOWS_GAMES) +#ifdef HAVE_WINDOWS_CONSOLE_IO /* Windows console IO is always UTF-8 encoded */ PyTypeObject *winconsoleio_type = (PyTypeObject *)_PyImport_GetModuleAttr( &_Py_ID(_io), &_Py_ID(_WindowsConsoleIO)); From 99b6a1db57dae63105ff66ea7d1145c36242ae3d Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Tue, 28 Feb 2023 19:58:36 +0100 Subject: [PATCH 065/100] Update Modules/socketmodule.c Co-authored-by: Steve Dower --- Modules/socketmodule.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c index f3b0a39758f41a..958ea92b7a417c 100644 --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -383,6 +383,8 @@ remove_unusable_flags(PyObject *m) VER_MAJORVERSION|VER_MINORVERSION|VER_BUILDNUMBER, dwlConditionMask); #else + /* note in this case 'info' is the actual OS version, whereas above + it is the version to compare against. */ BOOL isSupported = info.dwMajorVersion > 10 || (info.dwMajorVersion == 10 && info.dwMinorVersion > 0) || (info.dwMajorVersion == 10 && info.dwMinorVersion == 0 && From d0e548ddd911744147bb8c35b85751f5d7462cbf Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Tue, 28 Feb 2023 20:25:20 +0100 Subject: [PATCH 066/100] define missing flags on non desktop builds --- Modules/_randommodule.c | 2 +- Modules/_winapi.c | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Modules/_randommodule.c b/Modules/_randommodule.c index ddba7e6d5e0179..43f6323762d5a7 100644 --- a/Modules/_randommodule.c +++ b/Modules/_randommodule.c @@ -78,7 +78,7 @@ #endif #ifdef MS_WINDOWS -# include +# include #endif /* Period parameters -- These are all magic. Don't change. */ diff --git a/Modules/_winapi.c b/Modules/_winapi.c index 4882c8cd674a02..747cc693d84cec 100644 --- a/Modules/_winapi.c +++ b/Modules/_winapi.c @@ -66,6 +66,14 @@ #define T_HANDLE T_POINTER +// winbase.h limits the STARTF_* flags to the desktop API as of 10.0.19041. +#ifndef STARTF_USESHOWWINDOW +#define STARTF_USESHOWWINDOW 0x00000001 +#endif +#ifndef STARTF_USESTDHANDLES +#define STARTF_USESTDHANDLES 0x00000100 +#endif + typedef struct { PyTypeObject *overlapped_type; } WinApiState; @@ -2176,10 +2184,8 @@ static int winapi_exec(PyObject *m) WINAPI_CONSTANT(F_DWORD, SEC_NOCACHE); WINAPI_CONSTANT(F_DWORD, SEC_RESERVE); WINAPI_CONSTANT(F_DWORD, SEC_WRITECOMBINE); -#ifndef MS_WINDOWS_NON_DESKTOP WINAPI_CONSTANT(F_DWORD, STARTF_USESHOWWINDOW); WINAPI_CONSTANT(F_DWORD, STARTF_USESTDHANDLES); -#endif WINAPI_CONSTANT(F_DWORD, STD_INPUT_HANDLE); WINAPI_CONSTANT(F_DWORD, STD_OUTPUT_HANDLE); WINAPI_CONSTANT(F_DWORD, STD_ERROR_HANDLE); From c569a18053d0b473ba1ee00e5c8d6e5f0c0bd533 Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Tue, 28 Feb 2023 20:33:46 +0100 Subject: [PATCH 067/100] set inherit in WASSocketW --- Modules/_io/clinic/winconsoleio.c.h | 42 ++++++++++++++--------------- Modules/socketmodule.c | 26 +++++++----------- 2 files changed, 30 insertions(+), 38 deletions(-) diff --git a/Modules/_io/clinic/winconsoleio.c.h b/Modules/_io/clinic/winconsoleio.c.h index da2d639e00ed32..4c5cd0892c4a6d 100644 --- a/Modules/_io/clinic/winconsoleio.c.h +++ b/Modules/_io/clinic/winconsoleio.c.h @@ -8,7 +8,7 @@ preserve #endif -#if (defined(MS_WINDOWS) && !defined(MS_WINDOWS_GAMES)) +#if defined(HAVE_WINDOWS_CONSOLE_IO) PyDoc_STRVAR(_io__WindowsConsoleIO_close__doc__, "close($self, /)\n" @@ -31,9 +31,9 @@ _io__WindowsConsoleIO_close(winconsoleio *self, PyObject *Py_UNUSED(ignored)) return _io__WindowsConsoleIO_close_impl(self); } -#endif /* (defined(MS_WINDOWS) && !defined(MS_WINDOWS_GAMES)) */ +#endif /* defined(HAVE_WINDOWS_CONSOLE_IO) */ -#if (defined(MS_WINDOWS) && !defined(MS_WINDOWS_GAMES)) +#if defined(HAVE_WINDOWS_CONSOLE_IO) PyDoc_STRVAR(_io__WindowsConsoleIO___init____doc__, "_WindowsConsoleIO(file, mode=\'r\', closefd=True, opener=None)\n" @@ -131,9 +131,9 @@ _io__WindowsConsoleIO___init__(PyObject *self, PyObject *args, PyObject *kwargs) return return_value; } -#endif /* (defined(MS_WINDOWS) && !defined(MS_WINDOWS_GAMES)) */ +#endif /* defined(HAVE_WINDOWS_CONSOLE_IO) */ -#if (defined(MS_WINDOWS) && !defined(MS_WINDOWS_GAMES)) +#if defined(HAVE_WINDOWS_CONSOLE_IO) PyDoc_STRVAR(_io__WindowsConsoleIO_fileno__doc__, "fileno($self, /)\n" @@ -153,9 +153,9 @@ _io__WindowsConsoleIO_fileno(winconsoleio *self, PyObject *Py_UNUSED(ignored)) return _io__WindowsConsoleIO_fileno_impl(self); } -#endif /* (defined(MS_WINDOWS) && !defined(MS_WINDOWS_GAMES)) */ +#endif /* defined(HAVE_WINDOWS_CONSOLE_IO) */ -#if (defined(MS_WINDOWS) && !defined(MS_WINDOWS_GAMES)) +#if defined(HAVE_WINDOWS_CONSOLE_IO) PyDoc_STRVAR(_io__WindowsConsoleIO_readable__doc__, "readable($self, /)\n" @@ -175,9 +175,9 @@ _io__WindowsConsoleIO_readable(winconsoleio *self, PyObject *Py_UNUSED(ignored)) return _io__WindowsConsoleIO_readable_impl(self); } -#endif /* (defined(MS_WINDOWS) && !defined(MS_WINDOWS_GAMES)) */ +#endif /* defined(HAVE_WINDOWS_CONSOLE_IO) */ -#if (defined(MS_WINDOWS) && !defined(MS_WINDOWS_GAMES)) +#if defined(HAVE_WINDOWS_CONSOLE_IO) PyDoc_STRVAR(_io__WindowsConsoleIO_writable__doc__, "writable($self, /)\n" @@ -197,9 +197,9 @@ _io__WindowsConsoleIO_writable(winconsoleio *self, PyObject *Py_UNUSED(ignored)) return _io__WindowsConsoleIO_writable_impl(self); } -#endif /* (defined(MS_WINDOWS) && !defined(MS_WINDOWS_GAMES)) */ +#endif /* defined(HAVE_WINDOWS_CONSOLE_IO) */ -#if (defined(MS_WINDOWS) && !defined(MS_WINDOWS_GAMES)) +#if defined(HAVE_WINDOWS_CONSOLE_IO) PyDoc_STRVAR(_io__WindowsConsoleIO_readinto__doc__, "readinto($self, buffer, /)\n" @@ -239,9 +239,9 @@ _io__WindowsConsoleIO_readinto(winconsoleio *self, PyObject *arg) return return_value; } -#endif /* (defined(MS_WINDOWS) && !defined(MS_WINDOWS_GAMES)) */ +#endif /* defined(HAVE_WINDOWS_CONSOLE_IO) */ -#if (defined(MS_WINDOWS) && !defined(MS_WINDOWS_GAMES)) +#if defined(HAVE_WINDOWS_CONSOLE_IO) PyDoc_STRVAR(_io__WindowsConsoleIO_readall__doc__, "readall($self, /)\n" @@ -263,9 +263,9 @@ _io__WindowsConsoleIO_readall(winconsoleio *self, PyObject *Py_UNUSED(ignored)) return _io__WindowsConsoleIO_readall_impl(self); } -#endif /* (defined(MS_WINDOWS) && !defined(MS_WINDOWS_GAMES)) */ +#endif /* defined(HAVE_WINDOWS_CONSOLE_IO) */ -#if (defined(MS_WINDOWS) && !defined(MS_WINDOWS_GAMES)) +#if defined(HAVE_WINDOWS_CONSOLE_IO) PyDoc_STRVAR(_io__WindowsConsoleIO_read__doc__, "read($self, size=-1, /)\n" @@ -305,9 +305,9 @@ _io__WindowsConsoleIO_read(winconsoleio *self, PyObject *const *args, Py_ssize_t return return_value; } -#endif /* (defined(MS_WINDOWS) && !defined(MS_WINDOWS_GAMES)) */ +#endif /* defined(HAVE_WINDOWS_CONSOLE_IO) */ -#if (defined(MS_WINDOWS) && !defined(MS_WINDOWS_GAMES)) +#if defined(HAVE_WINDOWS_CONSOLE_IO) PyDoc_STRVAR(_io__WindowsConsoleIO_write__doc__, "write($self, b, /)\n" @@ -348,9 +348,9 @@ _io__WindowsConsoleIO_write(winconsoleio *self, PyObject *arg) return return_value; } -#endif /* (defined(MS_WINDOWS) && !defined(MS_WINDOWS_GAMES)) */ +#endif /* defined(HAVE_WINDOWS_CONSOLE_IO) */ -#if (defined(MS_WINDOWS) && !defined(MS_WINDOWS_GAMES)) +#if defined(HAVE_WINDOWS_CONSOLE_IO) PyDoc_STRVAR(_io__WindowsConsoleIO_isatty__doc__, "isatty($self, /)\n" @@ -370,7 +370,7 @@ _io__WindowsConsoleIO_isatty(winconsoleio *self, PyObject *Py_UNUSED(ignored)) return _io__WindowsConsoleIO_isatty_impl(self); } -#endif /* (defined(MS_WINDOWS) && !defined(MS_WINDOWS_GAMES)) */ +#endif /* defined(HAVE_WINDOWS_CONSOLE_IO) */ #ifndef _IO__WINDOWSCONSOLEIO_CLOSE_METHODDEF #define _IO__WINDOWSCONSOLEIO_CLOSE_METHODDEF @@ -407,4 +407,4 @@ _io__WindowsConsoleIO_isatty(winconsoleio *self, PyObject *Py_UNUSED(ignored)) #ifndef _IO__WINDOWSCONSOLEIO_ISATTY_METHODDEF #define _IO__WINDOWSCONSOLEIO_ISATTY_METHODDEF #endif /* !defined(_IO__WINDOWSCONSOLEIO_ISATTY_METHODDEF) */ -/*[clinic end generated code: output=380ec40c9ff821ed input=a9049054013a1b77]*/ +/*[clinic end generated code: output=163e934aa9b0ef16 input=a9049054013a1b77]*/ diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c index 958ea92b7a417c..54581e752b64cd 100644 --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -5445,11 +5445,6 @@ sock_initobj_impl(PySocketSockObject *self, int family, int type, int proto, proto = 0; } #ifdef MS_WINDOWS - /* Windows implementation */ -#ifndef WSA_FLAG_NO_HANDLE_INHERIT -#define WSA_FLAG_NO_HANDLE_INHERIT 0x80 -#endif - Py_BEGIN_ALLOW_THREADS fd = WSASocketW(family, type, proto, NULL, 0, @@ -6161,8 +6156,9 @@ socket_dup(PyObject *self, PyObject *fdobj) #endif fd = PyLong_AsSocket_t(fdobj); - if (fd == (SOCKET_T)(-1) && PyErr_Occurred()) + if (fd == (SOCKET_T)(-1) && PyErr_Occurred()) { return NULL; + } #ifdef MS_WINDOWS if (WSADuplicateSocketW(fd, GetCurrentProcessId(), &info)) @@ -6170,27 +6166,23 @@ socket_dup(PyObject *self, PyObject *fdobj) newfd = WSASocketW(FROM_PROTOCOL_INFO, FROM_PROTOCOL_INFO, FROM_PROTOCOL_INFO, - &info, 0, WSA_FLAG_OVERLAPPED); - if (newfd == INVALID_SOCKET) + &info, 0, + WSA_FLAG_OVERLAPPED | WSA_FLAG_NO_HANDLE_INHERIT); + if (newfd == INVALID_SOCKET) { return set_error(); - -#ifndef MS_WINDOWS_NON_DESKTOP - if (!SetHandleInformation((HANDLE)newfd, HANDLE_FLAG_INHERIT, 0)) { - closesocket(newfd); - PyErr_SetFromWindowsErr(0); - return NULL; } -#endif #else /* On UNIX, dup can be used to duplicate the file descriptor of a socket */ newfd = _Py_dup(fd); - if (newfd == INVALID_SOCKET) + if (newfd == INVALID_SOCKET) { return NULL; + } #endif newfdobj = PyLong_FromSocket_t(newfd); - if (newfdobj == NULL) + if (newfdobj == NULL) { SOCKETCLOSE(newfd); + } return newfdobj; } From 3e86c9ed0d2e9105b2a4401083f6b114572c4063 Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Tue, 28 Feb 2023 20:49:24 +0100 Subject: [PATCH 068/100] add back dynamic loading --- PC/pyconfig.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/PC/pyconfig.h b/PC/pyconfig.h index 71992a4f364b13..14624c61c1c9bb 100644 --- a/PC/pyconfig.h +++ b/PC/pyconfig.h @@ -507,9 +507,7 @@ Py_NO_ENABLE_SHARED to find out. Also support MS_NO_COREDLL for b/w compat */ /* #define HAVE_CLOCK */ /* Define when any dynamic module loading is enabled */ -#ifndef MS_WINDOWS_GAMES -# define HAVE_DYNAMIC_LOADING -#endif +#define HAVE_DYNAMIC_LOADING /* Define if you have ftime. */ #define HAVE_FTIME From d5cb524b9ec2ad9e81b572919fecae7b3d0aa15e Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Tue, 28 Feb 2023 21:03:14 +0100 Subject: [PATCH 069/100] more cleanup --- Modules/_io/_iomodule.h | 2 +- Modules/_io/winconsoleio.c | 2 +- Modules/posixmodule.c | 25 +++---------------------- 3 files changed, 5 insertions(+), 24 deletions(-) diff --git a/Modules/_io/_iomodule.h b/Modules/_io/_iomodule.h index 8299b3a6a19a0a..d7224e56f9a722 100644 --- a/Modules/_io/_iomodule.h +++ b/Modules/_io/_iomodule.h @@ -28,7 +28,7 @@ extern PyType_Spec textiowrapper_spec; #ifdef HAVE_WINDOWS_CONSOLE_IO extern PyTypeObject PyWindowsConsoleIO_Type; -#endif /* MS_WINDOWS && !MS_WINDOWS_GAMES */ +#endif /* HAVE_WINDOWS_CONSOLE_IO */ /* These functions are used as METH_NOARGS methods, are normally called * with args=NULL, and return a new reference. diff --git a/Modules/_io/winconsoleio.c b/Modules/_io/winconsoleio.c index de49318cbb0d1a..f836e230243020 100644 --- a/Modules/_io/winconsoleio.c +++ b/Modules/_io/winconsoleio.c @@ -1179,4 +1179,4 @@ PyTypeObject PyWindowsConsoleIO_Type = { 0, /* tp_finalize */ }; -#endif /* MS_WINDOWS && !MS_WINDOWS_GAMES */ +#endif /* HAVE_WINDOWS_CONSOLE_IO */ diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index e967fead2705c2..c6921262b5f8a5 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -323,7 +323,7 @@ corresponding Unix manual entries for more information on calls."); # if defined(TIOCGWINSZ) # define TERMSIZE_USE_IOCTL # endif -#endif /* MS_WINDOWS && !MS_WINDOWS_GAMES */ +#endif /* HAVE_WINDOWS_CONSOLE_IO */ /* Various compilers have only certain posix functions */ /* XXX Gosh I wish these were all moved into pyconfig.h */ @@ -15080,9 +15080,6 @@ os_getrandom_impl(PyObject *module, Py_ssize_t size, int flags) * on win32 */ -typedef DLL_DIRECTORY_COOKIE (WINAPI *PAddDllDirectory)(PCWSTR newDirectory); -typedef BOOL (WINAPI *PRemoveDllDirectory)(DLL_DIRECTORY_COOKIE cookie); - /*[clinic input] os._add_dll_directory @@ -15102,8 +15099,6 @@ static PyObject * os__add_dll_directory_impl(PyObject *module, path_t *path) /*[clinic end generated code: output=80b025daebb5d683 input=1de3e6c13a5808c8]*/ { - HMODULE hKernel32; - PAddDllDirectory AddDllDirectory; DLL_DIRECTORY_COOKIE cookie = 0; DWORD err = 0; @@ -15111,14 +15106,8 @@ os__add_dll_directory_impl(PyObject *module, path_t *path) return NULL; } - /* For Windows 7, we have to load this. As this will be a fairly - infrequent operation, just do it each time. Kernel32 is always - loaded. */ Py_BEGIN_ALLOW_THREADS - if (!(hKernel32 = GetModuleHandleW(L"kernel32")) || - !(AddDllDirectory = (PAddDllDirectory)GetProcAddress( - hKernel32, "AddDllDirectory")) || - !(cookie = (*AddDllDirectory)(path->wide))) { + if (!(cookie = AddDllDirectory(path->wide))) { err = GetLastError(); } Py_END_ALLOW_THREADS @@ -15147,8 +15136,6 @@ static PyObject * os__remove_dll_directory_impl(PyObject *module, PyObject *cookie) /*[clinic end generated code: output=594350433ae535bc input=c1d16a7e7d9dc5dc]*/ { - HMODULE hKernel32; - PRemoveDllDirectory RemoveDllDirectory; DLL_DIRECTORY_COOKIE cookieValue; DWORD err = 0; @@ -15161,14 +15148,8 @@ os__remove_dll_directory_impl(PyObject *module, PyObject *cookie) cookieValue = (DLL_DIRECTORY_COOKIE)PyCapsule_GetPointer( cookie, "DLL directory cookie"); - /* For Windows 7, we have to load this. As this will be a fairly - infrequent operation, just do it each time. Kernel32 is always - loaded. */ Py_BEGIN_ALLOW_THREADS - if (!(hKernel32 = GetModuleHandleW(L"kernel32")) || - !(RemoveDllDirectory = (PRemoveDllDirectory)GetProcAddress( - hKernel32, "RemoveDllDirectory")) || - !(*RemoveDllDirectory)(cookieValue)) { + if (!RemoveDllDirectory(cookieValue)) { err = GetLastError(); } Py_END_ALLOW_THREADS From 63267d801bdeb28dfaae3036376be736bf43514a Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Tue, 28 Feb 2023 21:23:44 +0100 Subject: [PATCH 070/100] rename platform defines --- Modules/_randommodule.c | 2 +- Modules/mmapmodule.c | 4 +- Modules/posixmodule.c | 10 ++-- Modules/socketmodule.c | 14 ++--- Modules/timemodule.c | 4 +- PC/clinic/msvcrtmodule.c.h | 18 +++--- PC/clinic/winreg.c.h | 110 ++++++++++++++++++------------------- PC/config.c | 4 +- PC/config_minimal.c | 4 +- PC/msvcrtmodule.c | 16 +++--- PC/pyconfig.h | 18 ++++-- PC/winreg.c | 4 +- Python/sysmodule.c | 4 +- 13 files changed, 108 insertions(+), 104 deletions(-) diff --git a/Modules/_randommodule.c b/Modules/_randommodule.c index 43f6323762d5a7..6c68fc1fbfd8d3 100644 --- a/Modules/_randommodule.c +++ b/Modules/_randommodule.c @@ -263,7 +263,7 @@ random_seed_time_pid(RandomObject *self) key[0] = (uint32_t)(now & 0xffffffffU); key[1] = (uint32_t)(now >> 32); -#ifdef MS_WINDOWS_NON_DESKTOP +#if defined(MS_WINDOWS) && !defined(MS_WINDOWS_DESKTOP_APP) key[2] = (uint32_t)GetCurrentProcessId(); #elif defined(HAVE_GETPID) key[2] = (uint32_t)getpid(); diff --git a/Modules/mmapmodule.c b/Modules/mmapmodule.c index f2ec118922743d..74be3d7845a855 100644 --- a/Modules/mmapmodule.c +++ b/Modules/mmapmodule.c @@ -29,7 +29,7 @@ #include "structmember.h" // PyMemberDef #include // offsetof() -#if !defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES) +#if !defined(MS_WINDOWS) || defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES) #ifndef MS_WINDOWS #define UNIX @@ -1727,4 +1727,4 @@ PyInit_mmap(void) return PyModuleDef_Init(&mmapmodule); } -#endif /* !MS_WINDOWS_NON_DESKTOP || MS_WINDOWS_GAMES */ +#endif /* !MS_WINDOWS || MS_WINDOWS_DESKTOP_APP || MS_WINDOWS_GAMES */ diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index c6921262b5f8a5..c772e6bfba9b9d 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -30,7 +30,7 @@ # include # include // UNLEN # include "osdefs.h" // SEP -# ifndef MS_WINDOWS_NON_DESKTOP +# ifdef MS_WINDOWS_DESKTOP_APP # define HAVE_SYMLINK # endif #endif @@ -333,7 +333,7 @@ corresponding Unix manual entries for more information on calls."); # include #elif defined( _MSC_VER) /* Microsoft compiler */ -# ifndef MS_WINDOWS_NON_DESKTOP +# ifdef MS_WINDOWS_DESKTOP_APP # define HAVE_GETPPID 1 # define HAVE_GETLOGIN 1 # define HAVE_SPAWNV 1 @@ -342,7 +342,7 @@ corresponding Unix manual entries for more information on calls."); # define HAVE_WEXECV 1 # define HAVE_SYSTEM 1 # define HAVE_CWAIT 1 -# endif /* !MS_WINDOWS_NON_DESKTOP */ +# endif /* MS_WINDOWS_DESKTOP_APP */ # define HAVE_PIPE 1 # define HAVE_FSYNC 1 # define fsync _commit @@ -7971,7 +7971,7 @@ static PyObject * os_getpid_impl(PyObject *module) /*[clinic end generated code: output=9ea6fdac01ed2b3c input=5a9a00f0ab68aa00]*/ { -#ifdef MS_WINDOWS_NON_DESKTOP +#if defined(MS_WINDOWS) && !defined(MS_WINDOWS_DESKTOP_APP) return PyLong_FromUnsignedLong(GetCurrentProcessId()); #else return PyLong_FromPid(getpid()); @@ -13822,7 +13822,7 @@ os_cpu_count_impl(PyObject *module) { int ncpu = 0; #ifdef MS_WINDOWS -#ifndef MS_WINDOWS_NON_DESKTOP +#ifdef MS_WINDOWS_DESKTOP_APP ncpu = GetActiveProcessorCount(ALL_PROCESSOR_GROUPS); #endif #elif defined(__hpux) diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c index 54581e752b64cd..2b3a9c01973d53 100644 --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -270,7 +270,7 @@ shutdown(how) -- shut down traffic in one or both directions\n\ # include -#else +#else /* MS_WINDOWS */ /* MS_WINDOWS includes */ # ifdef HAVE_FCNTL_H @@ -281,7 +281,6 @@ shutdown(how) -- shut down traffic in one or both directions\n\ # include /* Macros based on the IPPROTO enum, see: https://bugs.python.org/issue29515 */ -#ifdef MS_WINDOWS #define IPPROTO_ICMP IPPROTO_ICMP #define IPPROTO_IGMP IPPROTO_IGMP #define IPPROTO_GGP IPPROTO_GGP @@ -312,7 +311,6 @@ shutdown(how) -- shut down traffic in one or both directions\n\ #define IPPROTO_PGM IPPROTO_PGM // WinSock2 only #define IPPROTO_L2TP IPPROTO_L2TP // WinSock2 only #define IPPROTO_SCTP IPPROTO_SCTP // WinSock2 only -#endif /* MS_WINDOWS */ /* Provides the IsWindows7SP1OrGreater() function */ #include @@ -353,7 +351,7 @@ remove_unusable_flags(PyObject *m) if (dict == NULL) { return -1; } -#ifdef MS_WINDOWS_NON_DESKTOP +#ifndef MS_WINDOWS_DESKTOP_APP info.dwOSVersionInfoSize = sizeof(info); if (!GetVersionExW((OSVERSIONINFOW*) &info)) { PyErr_SetFromWindowsErr(0); @@ -374,7 +372,7 @@ remove_unusable_flags(PyObject *m) #endif for (int i=0; imemb) -#endif +#endif /* MS_WINDOWS_DESKTOP_APP */ /* Convert "sock_addr_t *" to "struct sockaddr *". */ #define SAS2SA(x) (&((x)->sa)) @@ -2885,7 +2883,7 @@ sock_accept(PySocketSockObject *s, PyObject *Py_UNUSED(ignored)) newfd = ctx.result; #ifdef MS_WINDOWS -#ifndef MS_WINDOWS_NON_DESKTOP +#ifdef MS_WINDOWS_DESKTOP_APP if (!SetHandleInformation((HANDLE)newfd, HANDLE_FLAG_INHERIT, 0)) { PyErr_SetFromWindowsErr(0); SOCKETCLOSE(newfd); diff --git a/Modules/timemodule.c b/Modules/timemodule.c index c1473583b795bc..ed1d76608527c1 100644 --- a/Modules/timemodule.c +++ b/Modules/timemodule.c @@ -1137,7 +1137,7 @@ time_tzset(PyObject *self, PyObject *unused) return NULL; } -#ifndef MS_WINDOWS_NON_DESKTOP +#ifdef MS_WINDOWS_DESKTOP_APP tzset(); #endif @@ -1757,7 +1757,7 @@ init_timezone(PyObject *m) */ #ifdef HAVE_DECL_TZNAME PyObject *otz0, *otz1; -#ifndef MS_WINDOWS_NON_DESKTOP +#ifdef MS_WINDOWS_DESKTOP_APP tzset(); #endif PyModule_AddIntConstant(m, "timezone", _Py_timezone); diff --git a/PC/clinic/msvcrtmodule.c.h b/PC/clinic/msvcrtmodule.c.h index 0c044ddc40da52..f751acd3a7df4f 100644 --- a/PC/clinic/msvcrtmodule.c.h +++ b/PC/clinic/msvcrtmodule.c.h @@ -261,7 +261,7 @@ msvcrt_getch(PyObject *module, PyObject *Py_UNUSED(ignored)) return return_value; } -#if !defined(MS_WINDOWS_NON_DESKTOP) +#if defined(MS_WINDOWS_DESKTOP_APP) PyDoc_STRVAR(msvcrt_getwch__doc__, "getwch($module, /)\n" @@ -287,7 +287,7 @@ msvcrt_getwch(PyObject *module, PyObject *Py_UNUSED(ignored)) return return_value; } -#endif /* !defined(MS_WINDOWS_NON_DESKTOP) */ +#endif /* defined(MS_WINDOWS_DESKTOP_APP) */ PyDoc_STRVAR(msvcrt_getche__doc__, "getche($module, /)\n" @@ -313,7 +313,7 @@ msvcrt_getche(PyObject *module, PyObject *Py_UNUSED(ignored)) return return_value; } -#if !defined(MS_WINDOWS_NON_DESKTOP) +#if defined(MS_WINDOWS_DESKTOP_APP) PyDoc_STRVAR(msvcrt_getwche__doc__, "getwche($module, /)\n" @@ -339,7 +339,7 @@ msvcrt_getwche(PyObject *module, PyObject *Py_UNUSED(ignored)) return return_value; } -#endif /* !defined(MS_WINDOWS_NON_DESKTOP) */ +#endif /* defined(MS_WINDOWS_DESKTOP_APP) */ PyDoc_STRVAR(msvcrt_putch__doc__, "putch($module, char, /)\n" @@ -375,7 +375,7 @@ msvcrt_putch(PyObject *module, PyObject *arg) return return_value; } -#if !defined(MS_WINDOWS_NON_DESKTOP) +#if defined(MS_WINDOWS_DESKTOP_APP) PyDoc_STRVAR(msvcrt_putwch__doc__, "putwch($module, unicode_char, /)\n" @@ -413,7 +413,7 @@ msvcrt_putwch(PyObject *module, PyObject *arg) return return_value; } -#endif /* !defined(MS_WINDOWS_NON_DESKTOP) */ +#endif /* defined(MS_WINDOWS_DESKTOP_APP) */ PyDoc_STRVAR(msvcrt_ungetch__doc__, "ungetch($module, char, /)\n" @@ -453,7 +453,7 @@ msvcrt_ungetch(PyObject *module, PyObject *arg) return return_value; } -#if !defined(MS_WINDOWS_NON_DESKTOP) +#if defined(MS_WINDOWS_DESKTOP_APP) PyDoc_STRVAR(msvcrt_ungetwch__doc__, "ungetwch($module, unicode_char, /)\n" @@ -491,7 +491,7 @@ msvcrt_ungetwch(PyObject *module, PyObject *arg) return return_value; } -#endif /* !defined(MS_WINDOWS_NON_DESKTOP) */ +#endif /* defined(MS_WINDOWS_DESKTOP_APP) */ #if defined(_DEBUG) @@ -707,4 +707,4 @@ msvcrt_SetErrorMode(PyObject *module, PyObject *arg) #ifndef MSVCRT_GETERRORMODE_METHODDEF #define MSVCRT_GETERRORMODE_METHODDEF #endif /* !defined(MSVCRT_GETERRORMODE_METHODDEF) */ -/*[clinic end generated code: output=50255b8b9a685dcf input=a9049054013a1b77]*/ +/*[clinic end generated code: output=7eeaa49a1fa0a0b8 input=a9049054013a1b77]*/ diff --git a/PC/clinic/winreg.c.h b/PC/clinic/winreg.c.h index d55b8e17ee136e..ef4c82fe5bd9fa 100644 --- a/PC/clinic/winreg.c.h +++ b/PC/clinic/winreg.c.h @@ -8,7 +8,7 @@ preserve #endif -#if (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) +#if (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) PyDoc_STRVAR(winreg_HKEYType_Close__doc__, "Close($self, /)\n" @@ -30,9 +30,9 @@ winreg_HKEYType_Close(PyHKEYObject *self, PyObject *Py_UNUSED(ignored)) return winreg_HKEYType_Close_impl(self); } -#endif /* (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) */ +#endif /* (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) */ -#if (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) +#if (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) PyDoc_STRVAR(winreg_HKEYType_Detach__doc__, "Detach($self, /)\n" @@ -60,9 +60,9 @@ winreg_HKEYType_Detach(PyHKEYObject *self, PyObject *Py_UNUSED(ignored)) return winreg_HKEYType_Detach_impl(self); } -#endif /* (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) */ +#endif /* (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) */ -#if (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) +#if (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) PyDoc_STRVAR(winreg_HKEYType___enter____doc__, "__enter__($self, /)\n" @@ -87,9 +87,9 @@ winreg_HKEYType___enter__(PyHKEYObject *self, PyObject *Py_UNUSED(ignored)) return return_value; } -#endif /* (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) */ +#endif /* (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) */ -#if (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) +#if (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) PyDoc_STRVAR(winreg_HKEYType___exit____doc__, "__exit__($self, /, exc_type, exc_value, traceback)\n" @@ -150,9 +150,9 @@ winreg_HKEYType___exit__(PyHKEYObject *self, PyObject *const *args, Py_ssize_t n return return_value; } -#endif /* (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) */ +#endif /* (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) */ -#if (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) +#if (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) PyDoc_STRVAR(winreg_CloseKey__doc__, "CloseKey($module, hkey, /)\n" @@ -169,9 +169,9 @@ PyDoc_STRVAR(winreg_CloseKey__doc__, #define WINREG_CLOSEKEY_METHODDEF \ {"CloseKey", (PyCFunction)winreg_CloseKey, METH_O, winreg_CloseKey__doc__}, -#endif /* (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) */ +#endif /* (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) */ -#if (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) && !defined(MS_WINDOWS_GAMES) +#if (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) && !defined(MS_WINDOWS_GAMES) PyDoc_STRVAR(winreg_ConnectRegistry__doc__, "ConnectRegistry($module, computer_name, key, /)\n" @@ -235,9 +235,9 @@ winreg_ConnectRegistry(PyObject *module, PyObject *const *args, Py_ssize_t nargs return return_value; } -#endif /* (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) && !defined(MS_WINDOWS_GAMES) */ +#endif /* (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) && !defined(MS_WINDOWS_GAMES) */ -#if (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) +#if (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) PyDoc_STRVAR(winreg_CreateKey__doc__, "CreateKey($module, key, sub_key, /)\n" @@ -304,9 +304,9 @@ winreg_CreateKey(PyObject *module, PyObject *const *args, Py_ssize_t nargs) return return_value; } -#endif /* (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) */ +#endif /* (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) */ -#if (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) +#if (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) PyDoc_STRVAR(winreg_CreateKeyEx__doc__, "CreateKeyEx($module, /, key, sub_key, reserved=0,\n" @@ -428,9 +428,9 @@ winreg_CreateKeyEx(PyObject *module, PyObject *const *args, Py_ssize_t nargs, Py return return_value; } -#endif /* (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) */ +#endif /* (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) */ -#if (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) +#if (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) PyDoc_STRVAR(winreg_DeleteKey__doc__, "DeleteKey($module, key, sub_key, /)\n" @@ -486,9 +486,9 @@ winreg_DeleteKey(PyObject *module, PyObject *const *args, Py_ssize_t nargs) return return_value; } -#endif /* (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) */ +#endif /* (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) */ -#if (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) +#if (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) PyDoc_STRVAR(winreg_DeleteKeyEx__doc__, "DeleteKeyEx($module, /, key, sub_key, access=winreg.KEY_WOW64_64KEY,\n" @@ -603,9 +603,9 @@ winreg_DeleteKeyEx(PyObject *module, PyObject *const *args, Py_ssize_t nargs, Py return return_value; } -#endif /* (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) */ +#endif /* (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) */ -#if (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) +#if (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) PyDoc_STRVAR(winreg_DeleteValue__doc__, "DeleteValue($module, key, value, /)\n" @@ -659,9 +659,9 @@ winreg_DeleteValue(PyObject *module, PyObject *const *args, Py_ssize_t nargs) return return_value; } -#endif /* (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) */ +#endif /* (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) */ -#if (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) +#if (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) PyDoc_STRVAR(winreg_EnumKey__doc__, "EnumKey($module, key, index, /)\n" @@ -707,9 +707,9 @@ winreg_EnumKey(PyObject *module, PyObject *const *args, Py_ssize_t nargs) return return_value; } -#endif /* (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) */ +#endif /* (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) */ -#if (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) +#if (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) PyDoc_STRVAR(winreg_EnumValue__doc__, "EnumValue($module, key, index, /)\n" @@ -764,9 +764,9 @@ winreg_EnumValue(PyObject *module, PyObject *const *args, Py_ssize_t nargs) return return_value; } -#endif /* (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) */ +#endif /* (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) */ -#if (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) +#if (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) PyDoc_STRVAR(winreg_ExpandEnvironmentStrings__doc__, "ExpandEnvironmentStrings($module, string, /)\n" @@ -804,9 +804,9 @@ winreg_ExpandEnvironmentStrings(PyObject *module, PyObject *arg) return return_value; } -#endif /* (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) */ +#endif /* (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) */ -#if (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) && !defined(MS_WINDOWS_GAMES) +#if (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) && !defined(MS_WINDOWS_GAMES) PyDoc_STRVAR(winreg_FlushKey__doc__, "FlushKey($module, key, /)\n" @@ -848,9 +848,9 @@ winreg_FlushKey(PyObject *module, PyObject *arg) return return_value; } -#endif /* (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) && !defined(MS_WINDOWS_GAMES) */ +#endif /* (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) && !defined(MS_WINDOWS_GAMES) */ -#if (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) && !defined(MS_WINDOWS_GAMES) +#if (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) && !defined(MS_WINDOWS_GAMES) PyDoc_STRVAR(winreg_LoadKey__doc__, "LoadKey($module, key, sub_key, file_name, /)\n" @@ -928,9 +928,9 @@ winreg_LoadKey(PyObject *module, PyObject *const *args, Py_ssize_t nargs) return return_value; } -#endif /* (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) && !defined(MS_WINDOWS_GAMES) */ +#endif /* (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) && !defined(MS_WINDOWS_GAMES) */ -#if (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) +#if (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) PyDoc_STRVAR(winreg_OpenKey__doc__, "OpenKey($module, /, key, sub_key, reserved=0, access=winreg.KEY_READ)\n" @@ -1045,9 +1045,9 @@ winreg_OpenKey(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObje return return_value; } -#endif /* (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) */ +#endif /* (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) */ -#if (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) +#if (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) PyDoc_STRVAR(winreg_OpenKeyEx__doc__, "OpenKeyEx($module, /, key, sub_key, reserved=0, access=winreg.KEY_READ)\n" @@ -1162,9 +1162,9 @@ winreg_OpenKeyEx(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyOb return return_value; } -#endif /* (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) */ +#endif /* (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) */ -#if (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) +#if (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) PyDoc_STRVAR(winreg_QueryInfoKey__doc__, "QueryInfoKey($module, key, /)\n" @@ -1202,9 +1202,9 @@ winreg_QueryInfoKey(PyObject *module, PyObject *arg) return return_value; } -#endif /* (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) */ +#endif /* (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) */ -#if (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) +#if (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) PyDoc_STRVAR(winreg_QueryValue__doc__, "QueryValue($module, key, sub_key, /)\n" @@ -1267,9 +1267,9 @@ winreg_QueryValue(PyObject *module, PyObject *const *args, Py_ssize_t nargs) return return_value; } -#endif /* (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) */ +#endif /* (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) */ -#if (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) +#if (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) PyDoc_STRVAR(winreg_QueryValueEx__doc__, "QueryValueEx($module, key, name, /)\n" @@ -1328,9 +1328,9 @@ winreg_QueryValueEx(PyObject *module, PyObject *const *args, Py_ssize_t nargs) return return_value; } -#endif /* (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) */ +#endif /* (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) */ -#if (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) && !defined(MS_WINDOWS_GAMES) +#if (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) && !defined(MS_WINDOWS_GAMES) PyDoc_STRVAR(winreg_SaveKey__doc__, "SaveKey($module, key, file_name, /)\n" @@ -1389,9 +1389,9 @@ winreg_SaveKey(PyObject *module, PyObject *const *args, Py_ssize_t nargs) return return_value; } -#endif /* (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) && !defined(MS_WINDOWS_GAMES) */ +#endif /* (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) && !defined(MS_WINDOWS_GAMES) */ -#if (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) +#if (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) PyDoc_STRVAR(winreg_SetValue__doc__, "SetValue($module, key, sub_key, type, value, /)\n" @@ -1474,9 +1474,9 @@ winreg_SetValue(PyObject *module, PyObject *const *args, Py_ssize_t nargs) return return_value; } -#endif /* (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) */ +#endif /* (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) */ -#if (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) +#if (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) PyDoc_STRVAR(winreg_SetValueEx__doc__, "SetValueEx($module, key, value_name, reserved, type, value, /)\n" @@ -1572,9 +1572,9 @@ winreg_SetValueEx(PyObject *module, PyObject *const *args, Py_ssize_t nargs) return return_value; } -#endif /* (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) */ +#endif /* (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) */ -#if (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) && !defined(MS_WINDOWS_GAMES) +#if (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) && !defined(MS_WINDOWS_GAMES) PyDoc_STRVAR(winreg_DisableReflectionKey__doc__, "DisableReflectionKey($module, key, /)\n" @@ -1612,9 +1612,9 @@ winreg_DisableReflectionKey(PyObject *module, PyObject *arg) return return_value; } -#endif /* (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) && !defined(MS_WINDOWS_GAMES) */ +#endif /* (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) && !defined(MS_WINDOWS_GAMES) */ -#if (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) && !defined(MS_WINDOWS_GAMES) +#if (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) && !defined(MS_WINDOWS_GAMES) PyDoc_STRVAR(winreg_EnableReflectionKey__doc__, "EnableReflectionKey($module, key, /)\n" @@ -1650,9 +1650,9 @@ winreg_EnableReflectionKey(PyObject *module, PyObject *arg) return return_value; } -#endif /* (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) && !defined(MS_WINDOWS_GAMES) */ +#endif /* (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) && !defined(MS_WINDOWS_GAMES) */ -#if (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) && !defined(MS_WINDOWS_GAMES) +#if (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) && !defined(MS_WINDOWS_GAMES) PyDoc_STRVAR(winreg_QueryReflectionKey__doc__, "QueryReflectionKey($module, key, /)\n" @@ -1686,7 +1686,7 @@ winreg_QueryReflectionKey(PyObject *module, PyObject *arg) return return_value; } -#endif /* (!defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES)) && !defined(MS_WINDOWS_GAMES) */ +#endif /* (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) && !defined(MS_WINDOWS_GAMES) */ #ifndef WINREG_HKEYTYPE_CLOSE_METHODDEF #define WINREG_HKEYTYPE_CLOSE_METHODDEF @@ -1795,4 +1795,4 @@ winreg_QueryReflectionKey(PyObject *module, PyObject *arg) #ifndef WINREG_QUERYREFLECTIONKEY_METHODDEF #define WINREG_QUERYREFLECTIONKEY_METHODDEF #endif /* !defined(WINREG_QUERYREFLECTIONKEY_METHODDEF) */ -/*[clinic end generated code: output=4d3befb1f9c9d05c input=a9049054013a1b77]*/ +/*[clinic end generated code: output=d6de23fc941e7b62 input=a9049054013a1b77]*/ diff --git a/PC/config.c b/PC/config.c index 5e0b694d8e2508..6a1588f42d3fc7 100644 --- a/PC/config.c +++ b/PC/config.c @@ -43,7 +43,7 @@ extern PyObject* PyInit__collections(void); extern PyObject* PyInit__heapq(void); extern PyObject* PyInit__bisect(void); extern PyObject* PyInit__symtable(void); -#if !defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES) +#if defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES) extern PyObject* PyInit_mmap(void); extern PyObject* PyInit_winreg(void); #endif @@ -124,7 +124,7 @@ struct _inittab _PyImport_Inittab[] = { {"itertools", PyInit_itertools}, {"_collections", PyInit__collections}, {"_symtable", PyInit__symtable}, -#if !defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES) +#if defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES) {"mmap", PyInit_mmap}, {"winreg", PyInit_winreg}, #endif diff --git a/PC/config_minimal.c b/PC/config_minimal.c index b83a6ff105b798..a061658254b90f 100644 --- a/PC/config_minimal.c +++ b/PC/config_minimal.c @@ -14,7 +14,7 @@ extern PyObject* PyInit__tracemalloc(void); extern PyObject* PyInit_gc(void); extern PyObject* PyInit_nt(void); extern PyObject* PyInit__signal(void); -#if !defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES) +#if defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES) extern PyObject* PyInit_winreg(void); #endif @@ -37,7 +37,7 @@ struct _inittab _PyImport_Inittab[] = { {"_tokenize", PyInit__tokenize}, {"_tracemalloc", PyInit__tracemalloc}, -#if !defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES) +#if defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES) {"winreg", PyInit_winreg}, #endif diff --git a/PC/msvcrtmodule.c b/PC/msvcrtmodule.c index 3a6eeabb3e2cb6..dfd3a17187c41d 100644 --- a/PC/msvcrtmodule.c +++ b/PC/msvcrtmodule.c @@ -253,7 +253,7 @@ msvcrt_getch_impl(PyObject *module) return ch; } -#ifndef MS_WINDOWS_NON_DESKTOP +#ifdef MS_WINDOWS_DESKTOP_APP /*[clinic input] msvcrt.getwch -> wchar_t @@ -273,7 +273,7 @@ msvcrt_getwch_impl(PyObject *module) return ch; } -#endif /* MS_WINDOWS_NON_DESKTOP */ +#endif /* MS_WINDOWS_DESKTOP_APP */ /*[clinic input] msvcrt.getche -> byte_char @@ -293,7 +293,7 @@ msvcrt_getche_impl(PyObject *module) return ch; } -#ifndef MS_WINDOWS_NON_DESKTOP +#ifdef MS_WINDOWS_DESKTOP_APP /*[clinic input] msvcrt.getwche -> wchar_t @@ -313,7 +313,7 @@ msvcrt_getwche_impl(PyObject *module) return ch; } -#endif /* MS_WINDOWS_NON_DESKTOP */ +#endif /* MS_WINDOWS_DESKTOP_APP */ /*[clinic input] msvcrt.putch @@ -334,7 +334,7 @@ msvcrt_putch_impl(PyObject *module, char char_value) Py_RETURN_NONE; } -#ifndef MS_WINDOWS_NON_DESKTOP +#ifdef MS_WINDOWS_DESKTOP_APP /*[clinic input] msvcrt.putwch @@ -356,7 +356,7 @@ msvcrt_putwch_impl(PyObject *module, int unicode_char) } -#endif /* MS_WINDOWS_NON_DESKTOP */ +#endif /* MS_WINDOWS_DESKTOP_APP */ /*[clinic input] msvcrt.ungetch @@ -386,7 +386,7 @@ msvcrt_ungetch_impl(PyObject *module, char char_value) Py_RETURN_NONE; } -#ifndef MS_WINDOWS_NON_DESKTOP +#ifdef MS_WINDOWS_DESKTOP_APP /*[clinic input] msvcrt.ungetwch @@ -412,7 +412,7 @@ msvcrt_ungetwch_impl(PyObject *module, int unicode_char) Py_RETURN_NONE; } -#endif /* MS_WINDOWS_NON_DESKTOP */ +#endif /* MS_WINDOWS_DESKTOP_APP */ #ifdef _DEBUG /*[clinic input] diff --git a/PC/pyconfig.h b/PC/pyconfig.h index 14624c61c1c9bb..41032f81a14c9c 100644 --- a/PC/pyconfig.h +++ b/PC/pyconfig.h @@ -72,12 +72,18 @@ WIN32 is still required for the locale module. #define USE_SOCKET #endif -#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY != WINAPI_FAMILY_DESKTOP_APP) -#define MS_WINDOWS_NON_DESKTOP -#endif - -#if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_GAMES) -#define MS_WINDOWS_GAMES +#if !defined(WINAPI_FAMILY) || (WINAPI_FAMILY == WINAPI_FAMILY_DESKTOP_APP) +# define MS_WINDOWS_DESKTOP_APP +#elif defined(WINAPI_FAMILY_PC_APP) +# define MS_WINDOWS_PC_APP +#elif defined(WINAPI_FAMILY_PHONE_APP) +# define MS_WINDOWS_PHONE_APP +#elif defined(WINAPI_FAMILY_SYSTEM) +# define MS_WINDOWS_SYSTEM +#elif defined(WINAPI_FAMILY_SERVER ) +# define MS_WINDOWS_SERVER +#elif defined(WINAPI_FAMILY_GAMES) +# define MS_WINDOWS_GAMES #endif /* Compiler specific defines */ diff --git a/PC/winreg.c b/PC/winreg.c index 873551c3686e95..efe5d3e9bd29ff 100644 --- a/PC/winreg.c +++ b/PC/winreg.c @@ -18,7 +18,7 @@ #include "structmember.h" // PyMemberDef #include -#if !defined(MS_WINDOWS_NON_DESKTOP) || defined(MS_WINDOWS_GAMES) +#if defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES) static BOOL PyHKEY_AsHKEY(PyObject *ob, HKEY *pRes, BOOL bNoneOK); static BOOL clinic_HKEY_converter(PyObject *ob, void *p); @@ -2165,4 +2165,4 @@ PyMODINIT_FUNC PyInit_winreg(void) return m; } -#endif /* !MS_WINDOWS_NON_DESKTOP || MS_WINDOWS_GAMES */ +#endif /* MS_WINDOWS_DESKTOP_APP || MS_WINDOWS_GAMES */ diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 074f8d8ab85dd9..c3b42dd6b27ab4 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -1493,7 +1493,7 @@ static PyStructSequence_Desc windows_version_desc = { static PyObject * _sys_getwindowsversion_from_kernel32() { -#ifdef MS_WINDOWS_NON_DESKTOP +#ifndef MS_WINDOWS_DESKTOP_APP return NULL; #else HANDLE hKernel32; @@ -1529,7 +1529,7 @@ _sys_getwindowsversion_from_kernel32() realBuild = HIWORD(ffi->dwProductVersionLS); PyMem_RawFree(verblock); return Py_BuildValue("(kkk)", realMajor, realMinor, realBuild); -#endif /* MS_WINDOWS_NON_DESKTOP */ +#endif /* MS_WINDOWS_DESKTOP_APP */ } /* Disable deprecation warnings about GetVersionEx as the result is From 79f2bfe36b218b52f1d80a2dc11f2d8dd519cfe6 Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Tue, 28 Feb 2023 21:45:19 +0100 Subject: [PATCH 071/100] add missing inherit flag --- Modules/socketmodule.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c index 2b3a9c01973d53..64bcdc45e38956 100644 --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -5347,7 +5347,8 @@ sock_initobj_impl(PySocketSockObject *self, int family, int type, int proto, Py_BEGIN_ALLOW_THREADS fd = WSASocketW(FROM_PROTOCOL_INFO, FROM_PROTOCOL_INFO, - FROM_PROTOCOL_INFO, &info, 0, WSA_FLAG_OVERLAPPED); + FROM_PROTOCOL_INFO, &info, 0, + WSA_FLAG_OVERLAPPED | WSA_FLAG_NO_HANDLE_INHERIT); Py_END_ALLOW_THREADS if (fd == INVALID_SOCKET) { set_error(); From fc6b942f98104f23d2f3f7bba37c9c6199627757 Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Tue, 28 Feb 2023 21:54:24 +0100 Subject: [PATCH 072/100] fix guard --- Modules/timemodule.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Modules/timemodule.c b/Modules/timemodule.c index ed1d76608527c1..8aef41456bc2da 100644 --- a/Modules/timemodule.c +++ b/Modules/timemodule.c @@ -1137,7 +1137,7 @@ time_tzset(PyObject *self, PyObject *unused) return NULL; } -#ifdef MS_WINDOWS_DESKTOP_APP +#if !defined(MS_WINDOWS) || defined(MS_WINDOWS_DESKTOP_APP) tzset(); #endif @@ -1757,7 +1757,7 @@ init_timezone(PyObject *m) */ #ifdef HAVE_DECL_TZNAME PyObject *otz0, *otz1; -#ifdef MS_WINDOWS_DESKTOP_APP +#if !defined(MS_WINDOWS) || defined(MS_WINDOWS_DESKTOP_APP) tzset(); #endif PyModule_AddIntConstant(m, "timezone", _Py_timezone); From 05e98597e0f5da7d17a281b68bd334d9279852a5 Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Wed, 1 Mar 2023 00:50:38 +0100 Subject: [PATCH 073/100] use api partititions --- Modules/_randommodule.c | 2 +- Modules/clinic/posixmodule.c.h | 10 +-- Modules/faulthandler.c | 2 +- Modules/mmapmodule.c | 6 +- Modules/posixmodule.c | 31 +++++----- Modules/socketmodule.c | 10 +-- Modules/timemodule.c | 4 +- PC/clinic/msvcrtmodule.c.h | 22 +++---- PC/clinic/winreg.c.h | 110 ++++++++++++++++----------------- PC/config.c | 12 ++-- PC/config_minimal.c | 4 +- PC/msvcrtmodule.c | 22 +++---- PC/pyconfig.h | 25 ++++---- PC/winreg.c | 24 +++---- Python/fileutils.c | 50 ++++++++------- Python/initconfig.c | 8 --- Python/sysmodule.c | 4 +- 17 files changed, 173 insertions(+), 173 deletions(-) diff --git a/Modules/_randommodule.c b/Modules/_randommodule.c index 6c68fc1fbfd8d3..3f9bdce6e3572f 100644 --- a/Modules/_randommodule.c +++ b/Modules/_randommodule.c @@ -263,7 +263,7 @@ random_seed_time_pid(RandomObject *self) key[0] = (uint32_t)(now & 0xffffffffU); key[1] = (uint32_t)(now >> 32); -#if defined(MS_WINDOWS) && !defined(MS_WINDOWS_DESKTOP_APP) +#if defined(MS_WINDOWS) && !defined(MS_WINDOWS_DESKTOP) key[2] = (uint32_t)GetCurrentProcessId(); #elif defined(HAVE_GETPID) key[2] = (uint32_t)getpid(); diff --git a/Modules/clinic/posixmodule.c.h b/Modules/clinic/posixmodule.c.h index 102e0228eea252..a03df9efb77380 100644 --- a/Modules/clinic/posixmodule.c.h +++ b/Modules/clinic/posixmodule.c.h @@ -10988,7 +10988,7 @@ os_getrandom(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject #endif /* defined(HAVE_GETRANDOM_SYSCALL) */ -#if (defined(MS_WINDOWS) && !defined(MS_WINDOWS_GAMES)) +#if (defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM)) PyDoc_STRVAR(os__add_dll_directory__doc__, "_add_dll_directory($module, /, path)\n" @@ -11057,9 +11057,9 @@ os__add_dll_directory(PyObject *module, PyObject *const *args, Py_ssize_t nargs, return return_value; } -#endif /* (defined(MS_WINDOWS) && !defined(MS_WINDOWS_GAMES)) */ +#endif /* (defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM)) */ -#if (defined(MS_WINDOWS) && !defined(MS_WINDOWS_GAMES)) +#if (defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM)) PyDoc_STRVAR(os__remove_dll_directory__doc__, "_remove_dll_directory($module, /, cookie)\n" @@ -11120,7 +11120,7 @@ os__remove_dll_directory(PyObject *module, PyObject *const *args, Py_ssize_t nar return return_value; } -#endif /* (defined(MS_WINDOWS) && !defined(MS_WINDOWS_GAMES)) */ +#endif /* (defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM)) */ #if (defined(WIFEXITED) || defined(MS_WINDOWS)) @@ -11796,4 +11796,4 @@ os_waitstatus_to_exitcode(PyObject *module, PyObject *const *args, Py_ssize_t na #ifndef OS_WAITSTATUS_TO_EXITCODE_METHODDEF #define OS_WAITSTATUS_TO_EXITCODE_METHODDEF #endif /* !defined(OS_WAITSTATUS_TO_EXITCODE_METHODDEF) */ -/*[clinic end generated code: output=c65f0b8b54f5ef41 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=804f6e46ed7a369b input=a9049054013a1b77]*/ diff --git a/Modules/faulthandler.c b/Modules/faulthandler.c index ba03e979b5f403..bfe35fed7a450a 100644 --- a/Modules/faulthandler.c +++ b/Modules/faulthandler.c @@ -953,7 +953,7 @@ faulthandler_unregister_py(PyObject *self, PyObject *args) static void faulthandler_suppress_crash_report(void) { -#if defined(MS_WINDOWS) && !defined(MS_WINDOWS_GAMES) +#ifdef MS_WINDOWS_DESKTOP UINT mode; /* Configure Windows to not display the Windows Error Reporting dialog */ diff --git a/Modules/mmapmodule.c b/Modules/mmapmodule.c index 74be3d7845a855..240971e2bfb097 100644 --- a/Modules/mmapmodule.c +++ b/Modules/mmapmodule.c @@ -29,7 +29,7 @@ #include "structmember.h" // PyMemberDef #include // offsetof() -#if !defined(MS_WINDOWS) || defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES) +#if !defined(MS_WINDOWS) || defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES) #ifndef MS_WINDOWS #define UNIX @@ -649,7 +649,7 @@ mmap_flush_method(mmap_object *self, PyObject *args) if (self->access == ACCESS_READ || self->access == ACCESS_COPY) Py_RETURN_NONE; -#if defined(MS_WINDOWS) && !defined(MS_WINDOWS_GAMES) +#if defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM) if (!FlushViewOfFile(self->data+offset, size)) { PyErr_SetFromWindowsErr(GetLastError()); return NULL; @@ -1727,4 +1727,4 @@ PyInit_mmap(void) return PyModuleDef_Init(&mmapmodule); } -#endif /* !MS_WINDOWS || MS_WINDOWS_DESKTOP_APP || MS_WINDOWS_GAMES */ +#endif /* !MS_WINDOWS || MS_WINDOWS_DESKTOP || MS_WINDOWS_SYSTEM || MS_WINDOWS_GAMES */ diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index c772e6bfba9b9d..7a610acbca8e72 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -30,7 +30,7 @@ # include # include // UNLEN # include "osdefs.h" // SEP -# ifdef MS_WINDOWS_DESKTOP_APP +# ifdef MS_WINDOWS_DESKTOP # define HAVE_SYMLINK # endif #endif @@ -333,7 +333,7 @@ corresponding Unix manual entries for more information on calls."); # include #elif defined( _MSC_VER) /* Microsoft compiler */ -# ifdef MS_WINDOWS_DESKTOP_APP +# ifdef MS_WINDOWS_DESKTOP # define HAVE_GETPPID 1 # define HAVE_GETLOGIN 1 # define HAVE_SPAWNV 1 @@ -342,7 +342,7 @@ corresponding Unix manual entries for more information on calls."); # define HAVE_WEXECV 1 # define HAVE_SYSTEM 1 # define HAVE_CWAIT 1 -# endif /* MS_WINDOWS_DESKTOP_APP */ +# endif /* MS_WINDOWS_DESKTOP */ # define HAVE_PIPE 1 # define HAVE_FSYNC 1 # define fsync _commit @@ -4419,7 +4419,7 @@ os__getvolumepathname_impl(PyObject *module, path_t *path) return result; } -#ifdef MS_WINDOWS_GAMES +#if !defined(MS_WINDOWS_APP) && !defined(MS_WINDOWS_SYSTEM) // The Windows Games API partition does not provide PathCchSkipRoot // so we need our own implementation static wchar_t* @@ -4452,7 +4452,7 @@ win32_games_skip_root(wchar_t* path) /* relative path */ return NULL; } -#endif +#endif /* MS_WINDOWS_GAMES && !MS_WINDOWS_DESKTOP */ /*[clinic input] os._path_splitroot @@ -4480,13 +4480,13 @@ os__path_splitroot_impl(PyObject *module, path_t *path) *p = L'\\'; } -#ifdef MS_WINDOWS_GAMES - end = win32_games_skip_root(buffer); - ret = (end != NULL) ? S_OK : E_INVALIDARG; -#else +#if defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM) Py_BEGIN_ALLOW_THREADS ret = PathCchSkipRoot(buffer, &end); Py_END_ALLOW_THREADS +#else + end = win32_games_skip_root(buffer); + ret = (end != NULL) ? S_OK : E_INVALIDARG; #endif if (FAILED(ret)) { result = Py_BuildValue("sO", "", path->object); @@ -7971,7 +7971,7 @@ static PyObject * os_getpid_impl(PyObject *module) /*[clinic end generated code: output=9ea6fdac01ed2b3c input=5a9a00f0ab68aa00]*/ { -#if defined(MS_WINDOWS) && !defined(MS_WINDOWS_DESKTOP_APP) +#if defined(MS_WINDOWS) && !defined(MS_WINDOWS_DESKTOP) return PyLong_FromUnsignedLong(GetCurrentProcessId()); #else return PyLong_FromPid(getpid()); @@ -8430,7 +8430,7 @@ os_kill_impl(PyObject *module, pid_t pid, Py_ssize_t signal) DWORD err; HANDLE handle; -#if !defined(MS_WINDOWS_GAMES) +#if defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM) /* Console processes which share a common console can be sent CTRL+C or CTRL+BREAK events, provided they handle said events. */ if (sig == CTRL_C_EVENT || sig == CTRL_BREAK_EVENT) { @@ -8442,7 +8442,7 @@ os_kill_impl(PyObject *module, pid_t pid, Py_ssize_t signal) Py_RETURN_NONE; } } -#endif +#endif /* MS_WINDOWS_APP || MS_WINDOWS_SYSTEM */ /* If the signal is outside of what GenerateConsoleCtrlEvent can use, attempt to open and terminate the process. */ @@ -13822,7 +13822,7 @@ os_cpu_count_impl(PyObject *module) { int ncpu = 0; #ifdef MS_WINDOWS -#ifdef MS_WINDOWS_DESKTOP_APP +#ifdef MS_WINDOWS_DESKTOP ncpu = GetActiveProcessorCount(ALL_PROCESSOR_GROUPS); #endif #elif defined(__hpux) @@ -15075,7 +15075,8 @@ os_getrandom_impl(PyObject *module, Py_ssize_t size, int flags) } #endif /* HAVE_GETRANDOM_SYSCALL */ -#if defined(MS_WINDOWS) && !defined(MS_WINDOWS_GAMES) +#if defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM) + /* bpo-36085: Helper functions for managing DLL search directories * on win32 */ @@ -15166,7 +15167,7 @@ os__remove_dll_directory_impl(PyObject *module, PyObject *cookie) Py_RETURN_NONE; } -#endif /* MS_WINDOWS && !MS_WINDOWS_GAMES */ +#endif /* MS_WINDOWS_APP || MS_WINDOWS_SYSTEM */ /* Only check if WIFEXITED is available: expect that it comes diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c index 64bcdc45e38956..582ad944e2aa8b 100644 --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -351,7 +351,7 @@ remove_unusable_flags(PyObject *m) if (dict == NULL) { return -1; } -#ifndef MS_WINDOWS_DESKTOP_APP +#ifndef MS_WINDOWS_DESKTOP info.dwOSVersionInfoSize = sizeof(info); if (!GetVersionExW((OSVERSIONINFOW*) &info)) { PyErr_SetFromWindowsErr(0); @@ -372,7 +372,7 @@ remove_unusable_flags(PyObject *m) #endif for (int i=0; imemb) -#endif /* MS_WINDOWS_DESKTOP_APP */ +#endif /* MS_WINDOWS_DESKTOP */ /* Convert "sock_addr_t *" to "struct sockaddr *". */ #define SAS2SA(x) (&((x)->sa)) @@ -2883,7 +2883,7 @@ sock_accept(PySocketSockObject *s, PyObject *Py_UNUSED(ignored)) newfd = ctx.result; #ifdef MS_WINDOWS -#ifdef MS_WINDOWS_DESKTOP_APP +#ifdef MS_WINDOWS_DESKTOP if (!SetHandleInformation((HANDLE)newfd, HANDLE_FLAG_INHERIT, 0)) { PyErr_SetFromWindowsErr(0); SOCKETCLOSE(newfd); diff --git a/Modules/timemodule.c b/Modules/timemodule.c index 8aef41456bc2da..c612eaeca157a2 100644 --- a/Modules/timemodule.c +++ b/Modules/timemodule.c @@ -1137,7 +1137,7 @@ time_tzset(PyObject *self, PyObject *unused) return NULL; } -#if !defined(MS_WINDOWS) || defined(MS_WINDOWS_DESKTOP_APP) +#if !defined(MS_WINDOWS) || defined(MS_WINDOWS_DESKTOP) tzset(); #endif @@ -1757,7 +1757,7 @@ init_timezone(PyObject *m) */ #ifdef HAVE_DECL_TZNAME PyObject *otz0, *otz1; -#if !defined(MS_WINDOWS) || defined(MS_WINDOWS_DESKTOP_APP) +#if !defined(MS_WINDOWS) || defined(MS_WINDOWS_DESKTOP) tzset(); #endif PyModule_AddIntConstant(m, "timezone", _Py_timezone); diff --git a/PC/clinic/msvcrtmodule.c.h b/PC/clinic/msvcrtmodule.c.h index f751acd3a7df4f..70f355cc6d6faf 100644 --- a/PC/clinic/msvcrtmodule.c.h +++ b/PC/clinic/msvcrtmodule.c.h @@ -261,7 +261,7 @@ msvcrt_getch(PyObject *module, PyObject *Py_UNUSED(ignored)) return return_value; } -#if defined(MS_WINDOWS_DESKTOP_APP) +#if defined(MS_WINDOWS_DESKTOP) PyDoc_STRVAR(msvcrt_getwch__doc__, "getwch($module, /)\n" @@ -287,7 +287,7 @@ msvcrt_getwch(PyObject *module, PyObject *Py_UNUSED(ignored)) return return_value; } -#endif /* defined(MS_WINDOWS_DESKTOP_APP) */ +#endif /* defined(MS_WINDOWS_DESKTOP) */ PyDoc_STRVAR(msvcrt_getche__doc__, "getche($module, /)\n" @@ -313,7 +313,7 @@ msvcrt_getche(PyObject *module, PyObject *Py_UNUSED(ignored)) return return_value; } -#if defined(MS_WINDOWS_DESKTOP_APP) +#if defined(MS_WINDOWS_DESKTOP) PyDoc_STRVAR(msvcrt_getwche__doc__, "getwche($module, /)\n" @@ -339,7 +339,7 @@ msvcrt_getwche(PyObject *module, PyObject *Py_UNUSED(ignored)) return return_value; } -#endif /* defined(MS_WINDOWS_DESKTOP_APP) */ +#endif /* defined(MS_WINDOWS_DESKTOP) */ PyDoc_STRVAR(msvcrt_putch__doc__, "putch($module, char, /)\n" @@ -375,7 +375,7 @@ msvcrt_putch(PyObject *module, PyObject *arg) return return_value; } -#if defined(MS_WINDOWS_DESKTOP_APP) +#if defined(MS_WINDOWS_DESKTOP) PyDoc_STRVAR(msvcrt_putwch__doc__, "putwch($module, unicode_char, /)\n" @@ -413,7 +413,7 @@ msvcrt_putwch(PyObject *module, PyObject *arg) return return_value; } -#endif /* defined(MS_WINDOWS_DESKTOP_APP) */ +#endif /* defined(MS_WINDOWS_DESKTOP) */ PyDoc_STRVAR(msvcrt_ungetch__doc__, "ungetch($module, char, /)\n" @@ -453,7 +453,7 @@ msvcrt_ungetch(PyObject *module, PyObject *arg) return return_value; } -#if defined(MS_WINDOWS_DESKTOP_APP) +#if defined(MS_WINDOWS_DESKTOP) PyDoc_STRVAR(msvcrt_ungetwch__doc__, "ungetwch($module, unicode_char, /)\n" @@ -491,7 +491,7 @@ msvcrt_ungetwch(PyObject *module, PyObject *arg) return return_value; } -#endif /* defined(MS_WINDOWS_DESKTOP_APP) */ +#endif /* defined(MS_WINDOWS_DESKTOP) */ #if defined(_DEBUG) @@ -626,7 +626,7 @@ msvcrt_set_error_mode(PyObject *module, PyObject *arg) #endif /* defined(_DEBUG) */ -#if !defined(MS_WINDOWS_GAMES) +#if (defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM)) PyDoc_STRVAR(msvcrt_GetErrorMode__doc__, "GetErrorMode($module, /)\n" @@ -646,7 +646,7 @@ msvcrt_GetErrorMode(PyObject *module, PyObject *Py_UNUSED(ignored)) return msvcrt_GetErrorMode_impl(module); } -#endif /* !defined(MS_WINDOWS_GAMES) */ +#endif /* (defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM)) */ PyDoc_STRVAR(msvcrt_SetErrorMode__doc__, "SetErrorMode($module, mode, /)\n" @@ -707,4 +707,4 @@ msvcrt_SetErrorMode(PyObject *module, PyObject *arg) #ifndef MSVCRT_GETERRORMODE_METHODDEF #define MSVCRT_GETERRORMODE_METHODDEF #endif /* !defined(MSVCRT_GETERRORMODE_METHODDEF) */ -/*[clinic end generated code: output=7eeaa49a1fa0a0b8 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=66607ffeda8a5f8b input=a9049054013a1b77]*/ diff --git a/PC/clinic/winreg.c.h b/PC/clinic/winreg.c.h index ef4c82fe5bd9fa..7a9474301da8a1 100644 --- a/PC/clinic/winreg.c.h +++ b/PC/clinic/winreg.c.h @@ -8,7 +8,7 @@ preserve #endif -#if (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) +#if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES)) PyDoc_STRVAR(winreg_HKEYType_Close__doc__, "Close($self, /)\n" @@ -30,9 +30,9 @@ winreg_HKEYType_Close(PyHKEYObject *self, PyObject *Py_UNUSED(ignored)) return winreg_HKEYType_Close_impl(self); } -#endif /* (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) */ +#endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES)) */ -#if (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) +#if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES)) PyDoc_STRVAR(winreg_HKEYType_Detach__doc__, "Detach($self, /)\n" @@ -60,9 +60,9 @@ winreg_HKEYType_Detach(PyHKEYObject *self, PyObject *Py_UNUSED(ignored)) return winreg_HKEYType_Detach_impl(self); } -#endif /* (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) */ +#endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES)) */ -#if (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) +#if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES)) PyDoc_STRVAR(winreg_HKEYType___enter____doc__, "__enter__($self, /)\n" @@ -87,9 +87,9 @@ winreg_HKEYType___enter__(PyHKEYObject *self, PyObject *Py_UNUSED(ignored)) return return_value; } -#endif /* (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) */ +#endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES)) */ -#if (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) +#if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES)) PyDoc_STRVAR(winreg_HKEYType___exit____doc__, "__exit__($self, /, exc_type, exc_value, traceback)\n" @@ -150,9 +150,9 @@ winreg_HKEYType___exit__(PyHKEYObject *self, PyObject *const *args, Py_ssize_t n return return_value; } -#endif /* (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) */ +#endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES)) */ -#if (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) +#if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES)) PyDoc_STRVAR(winreg_CloseKey__doc__, "CloseKey($module, hkey, /)\n" @@ -169,9 +169,9 @@ PyDoc_STRVAR(winreg_CloseKey__doc__, #define WINREG_CLOSEKEY_METHODDEF \ {"CloseKey", (PyCFunction)winreg_CloseKey, METH_O, winreg_CloseKey__doc__}, -#endif /* (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) */ +#endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES)) */ -#if (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) && !defined(MS_WINDOWS_GAMES) +#if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES)) && (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM)) PyDoc_STRVAR(winreg_ConnectRegistry__doc__, "ConnectRegistry($module, computer_name, key, /)\n" @@ -235,9 +235,9 @@ winreg_ConnectRegistry(PyObject *module, PyObject *const *args, Py_ssize_t nargs return return_value; } -#endif /* (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) && !defined(MS_WINDOWS_GAMES) */ +#endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES)) && (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM)) */ -#if (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) +#if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES)) PyDoc_STRVAR(winreg_CreateKey__doc__, "CreateKey($module, key, sub_key, /)\n" @@ -304,9 +304,9 @@ winreg_CreateKey(PyObject *module, PyObject *const *args, Py_ssize_t nargs) return return_value; } -#endif /* (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) */ +#endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES)) */ -#if (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) +#if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES)) PyDoc_STRVAR(winreg_CreateKeyEx__doc__, "CreateKeyEx($module, /, key, sub_key, reserved=0,\n" @@ -428,9 +428,9 @@ winreg_CreateKeyEx(PyObject *module, PyObject *const *args, Py_ssize_t nargs, Py return return_value; } -#endif /* (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) */ +#endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES)) */ -#if (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) +#if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES)) PyDoc_STRVAR(winreg_DeleteKey__doc__, "DeleteKey($module, key, sub_key, /)\n" @@ -486,9 +486,9 @@ winreg_DeleteKey(PyObject *module, PyObject *const *args, Py_ssize_t nargs) return return_value; } -#endif /* (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) */ +#endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES)) */ -#if (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) +#if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES)) PyDoc_STRVAR(winreg_DeleteKeyEx__doc__, "DeleteKeyEx($module, /, key, sub_key, access=winreg.KEY_WOW64_64KEY,\n" @@ -603,9 +603,9 @@ winreg_DeleteKeyEx(PyObject *module, PyObject *const *args, Py_ssize_t nargs, Py return return_value; } -#endif /* (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) */ +#endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES)) */ -#if (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) +#if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES)) PyDoc_STRVAR(winreg_DeleteValue__doc__, "DeleteValue($module, key, value, /)\n" @@ -659,9 +659,9 @@ winreg_DeleteValue(PyObject *module, PyObject *const *args, Py_ssize_t nargs) return return_value; } -#endif /* (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) */ +#endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES)) */ -#if (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) +#if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES)) PyDoc_STRVAR(winreg_EnumKey__doc__, "EnumKey($module, key, index, /)\n" @@ -707,9 +707,9 @@ winreg_EnumKey(PyObject *module, PyObject *const *args, Py_ssize_t nargs) return return_value; } -#endif /* (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) */ +#endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES)) */ -#if (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) +#if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES)) PyDoc_STRVAR(winreg_EnumValue__doc__, "EnumValue($module, key, index, /)\n" @@ -764,9 +764,9 @@ winreg_EnumValue(PyObject *module, PyObject *const *args, Py_ssize_t nargs) return return_value; } -#endif /* (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) */ +#endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES)) */ -#if (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) +#if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES)) PyDoc_STRVAR(winreg_ExpandEnvironmentStrings__doc__, "ExpandEnvironmentStrings($module, string, /)\n" @@ -804,9 +804,9 @@ winreg_ExpandEnvironmentStrings(PyObject *module, PyObject *arg) return return_value; } -#endif /* (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) */ +#endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES)) */ -#if (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) && !defined(MS_WINDOWS_GAMES) +#if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES)) && (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM)) PyDoc_STRVAR(winreg_FlushKey__doc__, "FlushKey($module, key, /)\n" @@ -848,9 +848,9 @@ winreg_FlushKey(PyObject *module, PyObject *arg) return return_value; } -#endif /* (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) && !defined(MS_WINDOWS_GAMES) */ +#endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES)) && (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM)) */ -#if (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) && !defined(MS_WINDOWS_GAMES) +#if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES)) && (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM)) PyDoc_STRVAR(winreg_LoadKey__doc__, "LoadKey($module, key, sub_key, file_name, /)\n" @@ -928,9 +928,9 @@ winreg_LoadKey(PyObject *module, PyObject *const *args, Py_ssize_t nargs) return return_value; } -#endif /* (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) && !defined(MS_WINDOWS_GAMES) */ +#endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES)) && (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM)) */ -#if (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) +#if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES)) PyDoc_STRVAR(winreg_OpenKey__doc__, "OpenKey($module, /, key, sub_key, reserved=0, access=winreg.KEY_READ)\n" @@ -1045,9 +1045,9 @@ winreg_OpenKey(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObje return return_value; } -#endif /* (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) */ +#endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES)) */ -#if (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) +#if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES)) PyDoc_STRVAR(winreg_OpenKeyEx__doc__, "OpenKeyEx($module, /, key, sub_key, reserved=0, access=winreg.KEY_READ)\n" @@ -1162,9 +1162,9 @@ winreg_OpenKeyEx(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyOb return return_value; } -#endif /* (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) */ +#endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES)) */ -#if (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) +#if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES)) PyDoc_STRVAR(winreg_QueryInfoKey__doc__, "QueryInfoKey($module, key, /)\n" @@ -1202,9 +1202,9 @@ winreg_QueryInfoKey(PyObject *module, PyObject *arg) return return_value; } -#endif /* (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) */ +#endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES)) */ -#if (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) +#if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES)) PyDoc_STRVAR(winreg_QueryValue__doc__, "QueryValue($module, key, sub_key, /)\n" @@ -1267,9 +1267,9 @@ winreg_QueryValue(PyObject *module, PyObject *const *args, Py_ssize_t nargs) return return_value; } -#endif /* (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) */ +#endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES)) */ -#if (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) +#if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES)) PyDoc_STRVAR(winreg_QueryValueEx__doc__, "QueryValueEx($module, key, name, /)\n" @@ -1328,9 +1328,9 @@ winreg_QueryValueEx(PyObject *module, PyObject *const *args, Py_ssize_t nargs) return return_value; } -#endif /* (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) */ +#endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES)) */ -#if (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) && !defined(MS_WINDOWS_GAMES) +#if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES)) && (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM)) PyDoc_STRVAR(winreg_SaveKey__doc__, "SaveKey($module, key, file_name, /)\n" @@ -1389,9 +1389,9 @@ winreg_SaveKey(PyObject *module, PyObject *const *args, Py_ssize_t nargs) return return_value; } -#endif /* (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) && !defined(MS_WINDOWS_GAMES) */ +#endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES)) && (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM)) */ -#if (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) +#if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES)) PyDoc_STRVAR(winreg_SetValue__doc__, "SetValue($module, key, sub_key, type, value, /)\n" @@ -1474,9 +1474,9 @@ winreg_SetValue(PyObject *module, PyObject *const *args, Py_ssize_t nargs) return return_value; } -#endif /* (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) */ +#endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES)) */ -#if (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) +#if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES)) PyDoc_STRVAR(winreg_SetValueEx__doc__, "SetValueEx($module, key, value_name, reserved, type, value, /)\n" @@ -1572,9 +1572,9 @@ winreg_SetValueEx(PyObject *module, PyObject *const *args, Py_ssize_t nargs) return return_value; } -#endif /* (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) */ +#endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES)) */ -#if (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) && !defined(MS_WINDOWS_GAMES) +#if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES)) && (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM)) PyDoc_STRVAR(winreg_DisableReflectionKey__doc__, "DisableReflectionKey($module, key, /)\n" @@ -1612,9 +1612,9 @@ winreg_DisableReflectionKey(PyObject *module, PyObject *arg) return return_value; } -#endif /* (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) && !defined(MS_WINDOWS_GAMES) */ +#endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES)) && (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM)) */ -#if (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) && !defined(MS_WINDOWS_GAMES) +#if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES)) && (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM)) PyDoc_STRVAR(winreg_EnableReflectionKey__doc__, "EnableReflectionKey($module, key, /)\n" @@ -1650,9 +1650,9 @@ winreg_EnableReflectionKey(PyObject *module, PyObject *arg) return return_value; } -#endif /* (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) && !defined(MS_WINDOWS_GAMES) */ +#endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES)) && (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM)) */ -#if (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) && !defined(MS_WINDOWS_GAMES) +#if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES)) && (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM)) PyDoc_STRVAR(winreg_QueryReflectionKey__doc__, "QueryReflectionKey($module, key, /)\n" @@ -1686,7 +1686,7 @@ winreg_QueryReflectionKey(PyObject *module, PyObject *arg) return return_value; } -#endif /* (defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES)) && !defined(MS_WINDOWS_GAMES) */ +#endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES)) && (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM)) */ #ifndef WINREG_HKEYTYPE_CLOSE_METHODDEF #define WINREG_HKEYTYPE_CLOSE_METHODDEF @@ -1795,4 +1795,4 @@ winreg_QueryReflectionKey(PyObject *module, PyObject *arg) #ifndef WINREG_QUERYREFLECTIONKEY_METHODDEF #define WINREG_QUERYREFLECTIONKEY_METHODDEF #endif /* !defined(WINREG_QUERYREFLECTIONKEY_METHODDEF) */ -/*[clinic end generated code: output=d6de23fc941e7b62 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=715db416dc1321ee input=a9049054013a1b77]*/ diff --git a/PC/config.c b/PC/config.c index 6a1588f42d3fc7..d5ef71d6f0faef 100644 --- a/PC/config.c +++ b/PC/config.c @@ -43,12 +43,14 @@ extern PyObject* PyInit__collections(void); extern PyObject* PyInit__heapq(void); extern PyObject* PyInit__bisect(void); extern PyObject* PyInit__symtable(void); -#if defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES) +#if !defined(MS_WINDOWS) || defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES) extern PyObject* PyInit_mmap(void); -extern PyObject* PyInit_winreg(void); #endif extern PyObject* PyInit__csv(void); extern PyObject* PyInit__sre(void); +#if defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES) +extern PyObject* PyInit_winreg(void); +#endif extern PyObject* PyInit__struct(void); extern PyObject* PyInit__datetime(void); extern PyObject* PyInit__functools(void); @@ -124,12 +126,14 @@ struct _inittab _PyImport_Inittab[] = { {"itertools", PyInit_itertools}, {"_collections", PyInit__collections}, {"_symtable", PyInit__symtable}, -#if defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES) +#if !defined(MS_WINDOWS) || defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES) {"mmap", PyInit_mmap}, - {"winreg", PyInit_winreg}, #endif {"_csv", PyInit__csv}, {"_sre", PyInit__sre}, +#if defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES) + {"winreg", PyInit_winreg}, +#endif {"_struct", PyInit__struct}, {"_datetime", PyInit__datetime}, {"_functools", PyInit__functools}, diff --git a/PC/config_minimal.c b/PC/config_minimal.c index a061658254b90f..20b3a6e74b125f 100644 --- a/PC/config_minimal.c +++ b/PC/config_minimal.c @@ -14,7 +14,7 @@ extern PyObject* PyInit__tracemalloc(void); extern PyObject* PyInit_gc(void); extern PyObject* PyInit_nt(void); extern PyObject* PyInit__signal(void); -#if defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES) +#if defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES) extern PyObject* PyInit_winreg(void); #endif @@ -37,7 +37,7 @@ struct _inittab _PyImport_Inittab[] = { {"_tokenize", PyInit__tokenize}, {"_tracemalloc", PyInit__tracemalloc}, -#if defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES) +#if defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES) {"winreg", PyInit_winreg}, #endif diff --git a/PC/msvcrtmodule.c b/PC/msvcrtmodule.c index dfd3a17187c41d..b4d026c120913d 100644 --- a/PC/msvcrtmodule.c +++ b/PC/msvcrtmodule.c @@ -253,7 +253,7 @@ msvcrt_getch_impl(PyObject *module) return ch; } -#ifdef MS_WINDOWS_DESKTOP_APP +#ifdef MS_WINDOWS_DESKTOP /*[clinic input] msvcrt.getwch -> wchar_t @@ -273,7 +273,7 @@ msvcrt_getwch_impl(PyObject *module) return ch; } -#endif /* MS_WINDOWS_DESKTOP_APP */ +#endif /* MS_WINDOWS_DESKTOP */ /*[clinic input] msvcrt.getche -> byte_char @@ -293,7 +293,7 @@ msvcrt_getche_impl(PyObject *module) return ch; } -#ifdef MS_WINDOWS_DESKTOP_APP +#ifdef MS_WINDOWS_DESKTOP /*[clinic input] msvcrt.getwche -> wchar_t @@ -313,7 +313,7 @@ msvcrt_getwche_impl(PyObject *module) return ch; } -#endif /* MS_WINDOWS_DESKTOP_APP */ +#endif /* MS_WINDOWS_DESKTOP */ /*[clinic input] msvcrt.putch @@ -334,7 +334,7 @@ msvcrt_putch_impl(PyObject *module, char char_value) Py_RETURN_NONE; } -#ifdef MS_WINDOWS_DESKTOP_APP +#ifdef MS_WINDOWS_DESKTOP /*[clinic input] msvcrt.putwch @@ -356,7 +356,7 @@ msvcrt_putwch_impl(PyObject *module, int unicode_char) } -#endif /* MS_WINDOWS_DESKTOP_APP */ +#endif /* MS_WINDOWS_DESKTOP */ /*[clinic input] msvcrt.ungetch @@ -386,7 +386,7 @@ msvcrt_ungetch_impl(PyObject *module, char char_value) Py_RETURN_NONE; } -#ifdef MS_WINDOWS_DESKTOP_APP +#ifdef MS_WINDOWS_DESKTOP /*[clinic input] msvcrt.ungetwch @@ -412,7 +412,7 @@ msvcrt_ungetwch_impl(PyObject *module, int unicode_char) Py_RETURN_NONE; } -#endif /* MS_WINDOWS_DESKTOP_APP */ +#endif /* MS_WINDOWS_DESKTOP */ #ifdef _DEBUG /*[clinic input] @@ -491,7 +491,7 @@ msvcrt_set_error_mode_impl(PyObject *module, int mode) } #endif /* _DEBUG */ -#ifndef MS_WINDOWS_GAMES +#if defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM) /*[clinic input] msvcrt.GetErrorMode @@ -512,7 +512,7 @@ msvcrt_GetErrorMode_impl(PyObject *module) return PyLong_FromUnsignedLong(res); } -#endif /* MS_WINDOWS_GAMES */ +#endif /* MS_WINDOWS_APP || MS_WINDOWS_SYSTEM */ /*[clinic input] msvcrt.SetErrorMode @@ -621,7 +621,7 @@ PyInit_msvcrt(void) insertint(d, "LK_NBRLCK", _LK_NBRLCK); insertint(d, "LK_RLCK", _LK_RLCK); insertint(d, "LK_UNLCK", _LK_UNLCK); -#ifndef MS_WINDOWS_GAMES +#ifdef MS_WINDOWS_DESKTOP insertint(d, "SEM_FAILCRITICALERRORS", SEM_FAILCRITICALERRORS); insertint(d, "SEM_NOALIGNMENTFAULTEXCEPT", SEM_NOALIGNMENTFAULTEXCEPT); insertint(d, "SEM_NOGPFAULTERRORBOX", SEM_NOGPFAULTERRORBOX); diff --git a/PC/pyconfig.h b/PC/pyconfig.h index 41032f81a14c9c..473c9cb5d3db66 100644 --- a/PC/pyconfig.h +++ b/PC/pyconfig.h @@ -72,18 +72,17 @@ WIN32 is still required for the locale module. #define USE_SOCKET #endif -#if !defined(WINAPI_FAMILY) || (WINAPI_FAMILY == WINAPI_FAMILY_DESKTOP_APP) -# define MS_WINDOWS_DESKTOP_APP -#elif defined(WINAPI_FAMILY_PC_APP) -# define MS_WINDOWS_PC_APP -#elif defined(WINAPI_FAMILY_PHONE_APP) -# define MS_WINDOWS_PHONE_APP -#elif defined(WINAPI_FAMILY_SYSTEM) -# define MS_WINDOWS_SYSTEM -#elif defined(WINAPI_FAMILY_SERVER ) -# define MS_WINDOWS_SERVER -#elif defined(WINAPI_FAMILY_GAMES) -# define MS_WINDOWS_GAMES +#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) +#define MS_WINDOWS_DESKTOP +#endif +#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) +#define MS_WINDOWS_APP +#endif +#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_SYSTEM) +#define MS_WINDOWS_SYSTEM +#endif +#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_GAMES) +#define MS_WINDOWS_GAMES #endif /* Compiler specific defines */ @@ -399,7 +398,7 @@ Py_NO_ENABLE_SHARED to find out. Also support MS_NO_COREDLL for b/w compat */ #define HAVE_CONIO_H 1 /* Define to 1 if you support windows console io */ -#if defined(Py_BUILD_CORE) && !defined(MS_WINDOWS_GAMES) +#if defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM) #define HAVE_WINDOWS_CONSOLE_IO 1 #endif diff --git a/PC/winreg.c b/PC/winreg.c index efe5d3e9bd29ff..d7f2ab4b0a8996 100644 --- a/PC/winreg.c +++ b/PC/winreg.c @@ -18,7 +18,7 @@ #include "structmember.h" // PyMemberDef #include -#if defined(MS_WINDOWS_DESKTOP_APP) || defined(MS_WINDOWS_GAMES) +#if defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES) static BOOL PyHKEY_AsHKEY(PyObject *ob, HKEY *pRes, BOOL bNoneOK); static BOOL clinic_HKEY_converter(PyObject *ob, void *p); @@ -831,7 +831,7 @@ winreg_CloseKey(PyObject *module, PyObject *hkey) Py_RETURN_NONE; } -#ifndef MS_WINDOWS_GAMES +#if defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) /*[clinic input] winreg.ConnectRegistry -> HKEY @@ -870,7 +870,7 @@ winreg_ConnectRegistry_impl(PyObject *module, return retKey; } -#endif /* MS_WINDOWS_GAMES */ +#endif /* MS_WINDOWS_DESKTOP || MS_WINDOWS_SYSTEM */ /*[clinic input] winreg.CreateKey -> HKEY @@ -1278,7 +1278,7 @@ winreg_ExpandEnvironmentStrings_impl(PyObject *module, return o; } -#ifndef MS_WINDOWS_GAMES +#if defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) /*[clinic input] winreg.FlushKey @@ -1313,9 +1313,9 @@ winreg_FlushKey_impl(PyObject *module, HKEY key) Py_RETURN_NONE; } -#endif /* MS_WINDOWS_GAMES */ +#endif /* MS_WINDOWS_DESKTOP || MS_WINDOWS_SYSTEM */ -#ifndef MS_WINDOWS_GAMES +#if defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) /*[clinic input] winreg.LoadKey @@ -1365,7 +1365,7 @@ winreg_LoadKey_impl(PyObject *module, HKEY key, const Py_UNICODE *sub_key, Py_RETURN_NONE; } -#endif /* MS_WINDOWS_GAMES */ +#endif /* MS_WINDOWS_DESKTOP || MS_WINDOWS_SYSTEM */ /*[clinic input] winreg.OpenKey -> HKEY @@ -1647,7 +1647,7 @@ winreg_QueryValueEx_impl(PyObject *module, HKEY key, const Py_UNICODE *name) return result; } -#ifndef MS_WINDOWS_GAMES +#if defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) /*[clinic input] winreg.SaveKey @@ -1694,7 +1694,7 @@ winreg_SaveKey_impl(PyObject *module, HKEY key, const Py_UNICODE *file_name) Py_RETURN_NONE; } -#endif /* MS_WINDOWS_GAMES */ +#endif /* MS_WINDOWS_DESKTOP || MS_WINDOWS_SYSTEM */ /*[clinic input] winreg.SetValue @@ -1872,7 +1872,7 @@ winreg_SetValueEx_impl(PyObject *module, HKEY key, Py_RETURN_NONE; } -#ifndef MS_WINDOWS_GAMES +#if defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) /*[clinic input] winreg.DisableReflectionKey @@ -2022,7 +2022,7 @@ winreg_QueryReflectionKey_impl(PyObject *module, HKEY key) return PyBool_FromLong(result); } -#endif /* MS_WINDOWS_GAMES */ +#endif /* MS_WINDOWS_DESKTOP || MS_WINDOWS_SYSTEM */ static struct PyMethodDef winreg_methods[] = { WINREG_CLOSEKEY_METHODDEF @@ -2165,4 +2165,4 @@ PyMODINIT_FUNC PyInit_winreg(void) return m; } -#endif /* MS_WINDOWS_DESKTOP_APP || MS_WINDOWS_GAMES */ +#endif /* MS_WINDOWS_DESKTOP || MS_WINDOWS_SYSTEM || MS_WINDOWS_GAMES */ diff --git a/Python/fileutils.c b/Python/fileutils.c index 3aa81513266f3d..0545a1987cef91 100644 --- a/Python/fileutils.c +++ b/Python/fileutils.c @@ -77,9 +77,8 @@ _Py_device_encoding(int fd) if (!valid) Py_RETURN_NONE; -#ifdef MS_WINDOWS_GAMES - Py_RETURN_NONE; -#elif defined(MS_WINDOWS) +#ifdef MS_WINDOWS +#ifdef HAVE_WINDOWS_CONSOLE_IO UINT cp; if (fd == 0) cp = GetConsoleCP(); @@ -94,6 +93,9 @@ _Py_device_encoding(int fd) } return PyUnicode_FromFormat("cp%u", (unsigned int)cp); +#else + Py_RETURN_NONE; +#endif /* HAVE_WINDOWS_CONSOLE_IO */ #else if (_PyRuntime.preconfig.utf8_mode) { _Py_DECLARE_STR(utf_8, "utf-8"); @@ -2022,19 +2024,8 @@ _Py_wrealpath(const wchar_t *path, int _Py_isabs(const wchar_t *path) { -#ifdef MS_WINDOWS_GAMES - /* this does not handle persistent local storage */ - if (path[0] == SEP || path[0] == ALTSEP) { - // Check for an absolute UNC path. - return path[1] == SEP || path[1] == ALTSEP; - } - else { - // Check for an absolute drive path. - return ((path[0]) && - (path[1] == L':') && - (path[2] == SEP || path[2] == ALTSEP)); - } -#elif defined(MS_WINDOWS) +#ifdef MS_WINDOWS +#if defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM) const wchar_t *tail; HRESULT hr = PathCchSkipRoot(path, &tail); if (FAILED(hr) || path == tail) { @@ -2049,6 +2040,19 @@ _Py_isabs(const wchar_t *path) return 0; } return 1; +#else + /* this does not handle persistent local storage */ + if (path[0] == SEP || path[0] == ALTSEP) { + // Check for an absolute UNC path. + return path[1] == SEP || path[1] == ALTSEP; + } + else { + // Check for an absolute drive path. + return ((path[0]) && + (path[1] == L':') && + (path[2] == SEP || path[2] == ALTSEP)); + } +#endif /* MS_WINDOWS_APP || MS_WINDOWS_SYSTEM */ #else return (path[0] == SEP); #endif @@ -2117,7 +2121,7 @@ _Py_abspath(const wchar_t *path, wchar_t **abspath_p) #endif } -#ifdef MS_WINDOWS_GAMES +#if !defined(MS_WINDOWS_APP) && !defined(MS_WINDOWS_SYSTEM) static wchar_t* win32_games_skip_root(wchar_t* path) { @@ -2201,23 +2205,23 @@ win32_games_join_relfile(wchar_t *buffer, size_t bufsize, } return 0; } -#endif /* MS_WINDOWS_GAMES */ +#endif /* !MS_WINDOWS_APP && !MS_WINDOWS_SYSTEM */ // The caller must ensure "buffer" is big enough. static int join_relfile(wchar_t *buffer, size_t bufsize, const wchar_t *dirname, const wchar_t *relfile) { -#if defined(MS_WINDOWS) && !defined(MS_WINDOWS_GAMES) -#ifdef MS_WINDOWS_GAMES - return win32_games_join_relfile(buffer, bufsize, dirname, relfile) -#else +#if defined(MS_WINDOWS) +#if defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM) if (FAILED(PathCchCombineEx(buffer, bufsize, dirname, relfile, PATHCCH_ALLOW_LONG_PATHS))) { return -1; } return 0; -#endif +#else + return win32_games_join_relfile(buffer, bufsize, dirname, relfile) +#endif /* MS_WINDOWS_APP && MS_WINDOWS_SYSTEM */ #else assert(!_Py_isabs(relfile)); size_t dirlen = wcslen(dirname); diff --git a/Python/initconfig.c b/Python/initconfig.c index 6da289d0ec315a..deec805a6b1ca4 100644 --- a/Python/initconfig.c +++ b/Python/initconfig.c @@ -822,12 +822,8 @@ config_init_defaults(PyConfig *config) config->buffered_stdio = 1; config->pathconfig_warnings = 1; #ifdef MS_WINDOWS -#ifdef MS_WINDOWS_GAMES - config->legacy_windows_stdio = 1; -#else config->legacy_windows_stdio = 0; #endif -#endif } @@ -861,12 +857,8 @@ PyConfig_InitIsolatedConfig(PyConfig *config) config->safe_path = 1; config->pathconfig_warnings = 0; #ifdef MS_WINDOWS -#ifdef MS_WINDOWS_GAMES - config->legacy_windows_stdio = 1; -#else config->legacy_windows_stdio = 0; #endif -#endif } diff --git a/Python/sysmodule.c b/Python/sysmodule.c index c3b42dd6b27ab4..3c5a82f66de617 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -1493,7 +1493,7 @@ static PyStructSequence_Desc windows_version_desc = { static PyObject * _sys_getwindowsversion_from_kernel32() { -#ifndef MS_WINDOWS_DESKTOP_APP +#ifndef MS_WINDOWS_DESKTOP return NULL; #else HANDLE hKernel32; @@ -1529,7 +1529,7 @@ _sys_getwindowsversion_from_kernel32() realBuild = HIWORD(ffi->dwProductVersionLS); PyMem_RawFree(verblock); return Py_BuildValue("(kkk)", realMajor, realMinor, realBuild); -#endif /* MS_WINDOWS_DESKTOP_APP */ +#endif /* !MS_WINDOWS_DESKTOP */ } /* Disable deprecation warnings about GetVersionEx as the result is From 9769662f94a4e7e22bdc7f76be49920c393cf98d Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Wed, 1 Mar 2023 00:58:31 +0100 Subject: [PATCH 074/100] fix guards --- Modules/posixmodule.c | 4 ++-- Python/fileutils.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 7a610acbca8e72..3b5e4f4110c4f6 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -4419,7 +4419,7 @@ os__getvolumepathname_impl(PyObject *module, path_t *path) return result; } -#if !defined(MS_WINDOWS_APP) && !defined(MS_WINDOWS_SYSTEM) +#if defined(MS_WINDOWS) && !defined(MS_WINDOWS_APP) && !defined(MS_WINDOWS_SYSTEM) // The Windows Games API partition does not provide PathCchSkipRoot // so we need our own implementation static wchar_t* @@ -4452,7 +4452,7 @@ win32_games_skip_root(wchar_t* path) /* relative path */ return NULL; } -#endif /* MS_WINDOWS_GAMES && !MS_WINDOWS_DESKTOP */ +#endif /* MS_WINDOWS && !MS_WINDOWS_APP && !MS_WINDOWS_SYSTEM */ /*[clinic input] os._path_splitroot diff --git a/Python/fileutils.c b/Python/fileutils.c index 0545a1987cef91..8aa3bc5dbaa70a 100644 --- a/Python/fileutils.c +++ b/Python/fileutils.c @@ -2121,7 +2121,7 @@ _Py_abspath(const wchar_t *path, wchar_t **abspath_p) #endif } -#if !defined(MS_WINDOWS_APP) && !defined(MS_WINDOWS_SYSTEM) +#if defined(MS_WINDOWS) && !defined(MS_WINDOWS_APP) && !defined(MS_WINDOWS_SYSTEM) static wchar_t* win32_games_skip_root(wchar_t* path) { @@ -2205,7 +2205,7 @@ win32_games_join_relfile(wchar_t *buffer, size_t bufsize, } return 0; } -#endif /* !MS_WINDOWS_APP && !MS_WINDOWS_SYSTEM */ +#endif /* MS_WINDOWS && !MS_WINDOWS_APP && !MS_WINDOWS_SYSTEM */ // The caller must ensure "buffer" is big enough. static int From 8f12bf812ff159668fc5b220a003f13338afc9bc Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Wed, 1 Mar 2023 01:11:57 +0100 Subject: [PATCH 075/100] add missing include --- Modules/socketmodule.c | 11 ++++++++--- PC/pyconfig.h | 2 ++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c index 582ad944e2aa8b..fff948f6aa29eb 100644 --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -5348,7 +5348,7 @@ sock_initobj_impl(PySocketSockObject *self, int family, int type, int proto, Py_BEGIN_ALLOW_THREADS fd = WSASocketW(FROM_PROTOCOL_INFO, FROM_PROTOCOL_INFO, FROM_PROTOCOL_INFO, &info, 0, - WSA_FLAG_OVERLAPPED | WSA_FLAG_NO_HANDLE_INHERIT); + WSA_FLAG_OVERLAPPED ); Py_END_ALLOW_THREADS if (fd == INVALID_SOCKET) { set_error(); @@ -6165,11 +6165,16 @@ socket_dup(PyObject *self, PyObject *fdobj) newfd = WSASocketW(FROM_PROTOCOL_INFO, FROM_PROTOCOL_INFO, FROM_PROTOCOL_INFO, - &info, 0, - WSA_FLAG_OVERLAPPED | WSA_FLAG_NO_HANDLE_INHERIT); + &info, 0, WSA_FLAG_OVERLAPPED); if (newfd == INVALID_SOCKET) { return set_error(); } + + if (!SetHandleInformation((HANDLE)newfd, HANDLE_FLAG_INHERIT, 0)) { + closesocket(newfd); + PyErr_SetFromWindowsErr(0); + return NULL; + } #else /* On UNIX, dup can be used to duplicate the file descriptor of a socket */ newfd = _Py_dup(fd); diff --git a/PC/pyconfig.h b/PC/pyconfig.h index 473c9cb5d3db66..5267fd9942c0ce 100644 --- a/PC/pyconfig.h +++ b/PC/pyconfig.h @@ -72,6 +72,8 @@ WIN32 is still required for the locale module. #define USE_SOCKET #endif +#include + #if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) #define MS_WINDOWS_DESKTOP #endif From f20fea85bfeeb392783be2879e49b43c5c1b9f40 Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Wed, 1 Mar 2023 10:27:24 +0100 Subject: [PATCH 076/100] apply code review --- Modules/mmapmodule.c | 2 +- Modules/posixmodule.c | 8 ++++---- PC/config.c | 4 ++-- Python/fileutils.c | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Modules/mmapmodule.c b/Modules/mmapmodule.c index 240971e2bfb097..a286db486dc89a 100644 --- a/Modules/mmapmodule.c +++ b/Modules/mmapmodule.c @@ -29,7 +29,7 @@ #include "structmember.h" // PyMemberDef #include // offsetof() -#if !defined(MS_WINDOWS) || defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES) +#if !defined(MS_WINDOWS) || defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_GAMES) #ifndef MS_WINDOWS #define UNIX diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 3b5e4f4110c4f6..b84ae717f18575 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -4420,7 +4420,7 @@ os__getvolumepathname_impl(PyObject *module, path_t *path) } #if defined(MS_WINDOWS) && !defined(MS_WINDOWS_APP) && !defined(MS_WINDOWS_SYSTEM) -// The Windows Games API partition does not provide PathCchSkipRoot +// The Windows Games API family does not provide PathCchSkipRoot // so we need our own implementation static wchar_t* win32_games_skip_root(wchar_t* path) @@ -7971,10 +7971,10 @@ static PyObject * os_getpid_impl(PyObject *module) /*[clinic end generated code: output=9ea6fdac01ed2b3c input=5a9a00f0ab68aa00]*/ { -#if defined(MS_WINDOWS) && !defined(MS_WINDOWS_DESKTOP) - return PyLong_FromUnsignedLong(GetCurrentProcessId()); -#else +#if !defined(MS_WINDOWS) || defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) return PyLong_FromPid(getpid()); +#else + return PyLong_FromUnsignedLong(GetCurrentProcessId()); #endif } #endif /* defined(HAVE_GETPID) */ diff --git a/PC/config.c b/PC/config.c index d5ef71d6f0faef..9a7c7f9a2c181e 100644 --- a/PC/config.c +++ b/PC/config.c @@ -43,7 +43,7 @@ extern PyObject* PyInit__collections(void); extern PyObject* PyInit__heapq(void); extern PyObject* PyInit__bisect(void); extern PyObject* PyInit__symtable(void); -#if !defined(MS_WINDOWS) || defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES) +#if !defined(MS_WINDOWS) || defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_GAMES) extern PyObject* PyInit_mmap(void); #endif extern PyObject* PyInit__csv(void); @@ -126,7 +126,7 @@ struct _inittab _PyImport_Inittab[] = { {"itertools", PyInit_itertools}, {"_collections", PyInit__collections}, {"_symtable", PyInit__symtable}, -#if !defined(MS_WINDOWS) || defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) || defined(MS_WINDOWS_GAMES) +#if !defined(MS_WINDOWS) || defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_GAMES) {"mmap", PyInit_mmap}, #endif {"_csv", PyInit__csv}, diff --git a/Python/fileutils.c b/Python/fileutils.c index 8aa3bc5dbaa70a..9eba857b6c77fd 100644 --- a/Python/fileutils.c +++ b/Python/fileutils.c @@ -2153,7 +2153,7 @@ win32_games_skip_root(wchar_t* path) return NULL; } -// The Windows Games API partition does not provide PathCchCombineEx +// The Windows Games API family does not provide PathCchCombineEx // so we need our own implementation static int win32_games_join_relfile(wchar_t *buffer, size_t bufsize, From e33a42fd795cd622bb2ead3cf14683bed2eb4b7e Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Wed, 1 Mar 2023 11:32:20 +0100 Subject: [PATCH 077/100] move replacement functions into fileutils --- Include/internal/pycore_fileutils.h | 8 +++ Modules/posixmodule.c | 39 ------------- Python/fileutils.c | 86 ++++++++++++++++------------- 3 files changed, 56 insertions(+), 77 deletions(-) diff --git a/Include/internal/pycore_fileutils.h b/Include/internal/pycore_fileutils.h index f8e2bf22590888..1a5c51e60a1c96 100644 --- a/Include/internal/pycore_fileutils.h +++ b/Include/internal/pycore_fileutils.h @@ -251,6 +251,14 @@ extern int _Py_add_relfile(wchar_t *dirname, extern size_t _Py_find_basename(const wchar_t *filename); PyAPI_FUNC(wchar_t *) _Py_normpath(wchar_t *path, Py_ssize_t size); +// The Windows Games API family does not provide these functions +// so provide our own implementations. Remove them in case they get added +// to the Games API family +#if defined(MS_WINDOWS) && !defined(MS_WINDOWS_APP) && !defined(MS_WINDOWS_SYSTEM) +#include + +extern HRESULT PathCchSkipRoot(const wchar_t *pszPath, const wchar_t **ppszRootEnd); +#endif /* defined(MS_WINDOWS) && !defined(MS_WINDOWS_APP) && !defined(MS_WINDOWS_SYSTEM) */ // Macros to protect CRT calls against instant termination when passed an // invalid parameter (bpo-23524). IPH stands for Invalid Parameter Handler. diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index b84ae717f18575..3a90e42c29d5e4 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -4419,40 +4419,6 @@ os__getvolumepathname_impl(PyObject *module, path_t *path) return result; } -#if defined(MS_WINDOWS) && !defined(MS_WINDOWS_APP) && !defined(MS_WINDOWS_SYSTEM) -// The Windows Games API family does not provide PathCchSkipRoot -// so we need our own implementation -static wchar_t* -win32_games_skip_root(wchar_t* path) -{ - if (path[0] == L'\\') { - /* relative path with root e.g. \Windows */ - if (path[1] != L'\\') { - return path + 1; - } - - /* UNC drives e.g. \\server\share or \\?\UNC\server\share */ - wchar_t *end = path + 2; - if (!wcsnicmp(end, L"?\\UNC\\", 6)) { - end += 6; - } - - end = wcschr(end, '\\'); - if (!end) { - return path + wcslen(path); - } - end = wcschr(end + 1, '\\'); - return (!end) ? path + wcslen(path) : end + 1; - } - /* absolute / relative path with drive, e.g. C: or C:\ */ - else if (isalpha(path[0]) && path[1] == L':') { - return (path[2] == L'\\') ? path + 3 : path + 2; - } - - /* relative path */ - return NULL; -} -#endif /* MS_WINDOWS && !MS_WINDOWS_APP && !MS_WINDOWS_SYSTEM */ /*[clinic input] os._path_splitroot @@ -4480,14 +4446,9 @@ os__path_splitroot_impl(PyObject *module, path_t *path) *p = L'\\'; } -#if defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM) Py_BEGIN_ALLOW_THREADS ret = PathCchSkipRoot(buffer, &end); Py_END_ALLOW_THREADS -#else - end = win32_games_skip_root(buffer); - ret = (end != NULL) ? S_OK : E_INVALIDARG; -#endif if (FAILED(ret)) { result = Py_BuildValue("sO", "", path->object); } else if (end != buffer) { diff --git a/Python/fileutils.c b/Python/fileutils.c index 9eba857b6c77fd..a0741bedc40cd7 100644 --- a/Python/fileutils.c +++ b/Python/fileutils.c @@ -2025,7 +2025,6 @@ int _Py_isabs(const wchar_t *path) { #ifdef MS_WINDOWS -#if defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM) const wchar_t *tail; HRESULT hr = PathCchSkipRoot(path, &tail); if (FAILED(hr) || path == tail) { @@ -2040,19 +2039,6 @@ _Py_isabs(const wchar_t *path) return 0; } return 1; -#else - /* this does not handle persistent local storage */ - if (path[0] == SEP || path[0] == ALTSEP) { - // Check for an absolute UNC path. - return path[1] == SEP || path[1] == ALTSEP; - } - else { - // Check for an absolute drive path. - return ((path[0]) && - (path[1] == L':') && - (path[2] == SEP || path[2] == ALTSEP)); - } -#endif /* MS_WINDOWS_APP || MS_WINDOWS_SYSTEM */ #else return (path[0] == SEP); #endif @@ -2121,40 +2107,74 @@ _Py_abspath(const wchar_t *path, wchar_t **abspath_p) #endif } +// The Windows Games API family does not provide these functions +// so provide our own implementations. Remove them in case they get added +// to the Games API family #if defined(MS_WINDOWS) && !defined(MS_WINDOWS_APP) && !defined(MS_WINDOWS_SYSTEM) -static wchar_t* -win32_games_skip_root(wchar_t* path) +HRESULT +PathCchSkipRoot(const wchar_t *path, const wchar_t **rootEnd) { if (path[0] == '\\') { /* relative path with root e.g. \Windows */ if (path[1] != '\\') { - return path + 1; + *rootEnd = path + 1; + return S_OK; } /* UNC drives e.g. \\server\share or \\?\UNC\server\share */ - wchar_t *end = path + 2; + const wchar_t *end = path + 2; if (!wcsnicmp(end, L"?\\UNC\\", 6)) { end += 6; } end = wcschr(end, '\\'); if (!end) { - return path + wcslen(path); + *rootEnd = path + wcslen(path); + return S_OK; } end = wcschr(end + 1, '\\'); - return (!end) ? path + wcslen(path) : end + 1; + *rootEnd = (!end) ? path + wcslen(path) : end + 1; + return S_OK; } /* absolute / relative path with drive, e.g. C: or C:\ */ else if (isalpha(path[0]) && path[1] == ':') { - return (path[2] == '\\') ? path + 3 : path + 2; + *rootEnd = (path[2] == '\\') ? path + 3 : path + 2; + return S_OK; } /* relative path */ - return NULL; + return E_INVALIDARG; +} + +static HRESULT +PathCchStripToRoot(wchar_t *path, size_t size) +{ + wchar_t *end; + if (PathCchSkipRoot(path, &end) == S_OK) { + if (*end == '\0') { + return S_FALSE; + } + *end = '\0'; + } + + return E_INVALIDARG; +} + +static wchar_t* +PathAddBackslashW(wchar_t *path) +{ + size_t len; + if (!path) { + return NULL; + } + len = wcslen(path); + if (len && path[len - 1] != '\\') { + path[len++] = '\\'; + path[len] = '\0'; + } + return path + len; } -// The Windows Games API family does not provide PathCchCombineEx -// so we need our own implementation static int win32_games_join_relfile(wchar_t *buffer, size_t bufsize, const wchar_t *dirname, const wchar_t *relfile) @@ -2180,27 +2200,17 @@ win32_games_join_relfile(wchar_t *buffer, size_t bufsize, if(wcsncmp(buffer, L"\\\\?\\", 4)) { buffer += 4; } - if (isalpha(buffer[0]) && buffer[1] == ':') { - if (!buffer[2]) { - buffer[2] = '\\'; - buffer[3] = '\0'; - } + if (isalpha(buffer[0]) && buffer[1] == ':' && !buffer[2]) { + PathAddBackslashW(buffer); } } else { if (relfile[0] == '\\' && relfile[1] != '\\') { - wchar_t* root_end = win32_games_skip_root(buffer); - if (root_end) { - *root_end = '\0'; - } - combined_length = root_end - buffer; + PathCchStripToRoot(buffer, combined_length); relfile++; } - if (combined_length && buffer[combined_length - 1] != '\\') { - buffer[combined_length++] = '\\'; - buffer[combined_length] = '\0'; - } + PathAddBackslashW(buffer); wcscat(buffer, relfile); } return 0; From 556a8e1f60695a4e203a2d2f235cd4ff6fee184c Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Wed, 1 Mar 2023 15:27:55 +0100 Subject: [PATCH 078/100] disable dynamic load of pythoncore for static lib --- Modules/_winapi.c | 2 ++ PC/config_minimal.c | 2 ++ Python/dynload_win.c | 8 ++++++++ Python/sysmodule.c | 8 ++++---- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/Modules/_winapi.c b/Modules/_winapi.c index 747cc693d84cec..83cde7501176b6 100644 --- a/Modules/_winapi.c +++ b/Modules/_winapi.c @@ -1212,8 +1212,10 @@ _winapi_ExitProcess_impl(PyObject *module, UINT ExitCode) /*[clinic end generated code: output=a387deb651175301 input=4f05466a9406c558]*/ { #if defined(Py_DEBUG) +#ifdef MS_WINDOWS_DESKTOP SetErrorMode(SEM_FAILCRITICALERRORS|SEM_NOALIGNMENTFAULTEXCEPT| SEM_NOGPFAULTERRORBOX|SEM_NOOPENFILEERRORBOX); +#endif _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_DEBUG); #endif diff --git a/PC/config_minimal.c b/PC/config_minimal.c index 20b3a6e74b125f..9a66ea1d1cd348 100644 --- a/PC/config_minimal.c +++ b/PC/config_minimal.c @@ -5,8 +5,10 @@ #include "Python.h" +#ifdef Py_ENABLE_SHARED /* Define extern variables omitted from minimal builds */ void *PyWin_DLLhModule = NULL; +#endif extern PyObject* PyInit_faulthandler(void); diff --git a/Python/dynload_win.c b/Python/dynload_win.c index 7bd04d573df4ad..acab05e2c6def3 100644 --- a/Python/dynload_win.c +++ b/Python/dynload_win.c @@ -163,6 +163,7 @@ static char *GetPythonImport (HINSTANCE hModule) return NULL; } +#ifdef Py_ENABLE_SHARED /* Load python3.dll before loading any extension module that might refer to it. That way, we can be sure that always the python3.dll corresponding to this python DLL is loaded, not a python3.dll that might be on the path @@ -216,6 +217,7 @@ _Py_CheckPython3(void) return hPython3 != NULL; #undef MAXPATHLEN } +#endif /* Py_ENABLE_SHARED */ dl_funcptr _PyImport_FindSharedFuncptrWindows(const char *prefix, const char *shortname, @@ -224,7 +226,9 @@ dl_funcptr _PyImport_FindSharedFuncptrWindows(const char *prefix, dl_funcptr p; char funcname[258], *import_python; +#ifdef Py_ENABLE_SHARED _Py_CheckPython3(); +#endif /* Py_ENABLE_SHARED */ wchar_t *wpathname = PyUnicode_AsWideCharString(pathname, NULL); if (wpathname == NULL) @@ -234,10 +238,12 @@ dl_funcptr _PyImport_FindSharedFuncptrWindows(const char *prefix, { HINSTANCE hDLL = NULL; +#ifdef MS_WINDOWS_DESKTOP unsigned int old_mode; /* Don't display a message box when Python can't load a DLL */ old_mode = SetErrorMode(SEM_FAILCRITICALERRORS); +#endif /* bpo-36085: We use LoadLibraryEx with restricted search paths to avoid DLL preloading attacks and enable use of the @@ -250,8 +256,10 @@ dl_funcptr _PyImport_FindSharedFuncptrWindows(const char *prefix, Py_END_ALLOW_THREADS PyMem_Free(wpathname); +#ifdef MS_WINDOWS_DESKTOP /* restore old error mode settings */ SetErrorMode(old_mode); +#endif if (hDLL==NULL){ PyObject *message; diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 764fb70bae6c38..fcff12411a45ea 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -42,11 +42,11 @@ Data members: #include #endif /* MS_WINDOWS */ -#ifdef MS_COREDLL +#ifdef Py_ENABLE_SHARED extern void *PyWin_DLLhModule; /* A string loaded from the DLL at startup: */ extern const char *PyWin_DLLVersionString; -#endif +#endif /* Py_ENABLE_SHARED */ #ifdef __EMSCRIPTEN__ #include @@ -3162,10 +3162,10 @@ _PySys_InitCore(PyThreadState *tstate, PyObject *sysdict) SET_SYS_FROM_STRING("byteorder", "little"); #endif -#ifdef MS_COREDLL +#ifdef Py_ENABLE_SHARED SET_SYS("dllhandle", PyLong_FromVoidPtr(PyWin_DLLhModule)); SET_SYS_FROM_STRING("winver", PyWin_DLLVersionString); -#endif +#endif /* Py_ENABLE_SHARED */ #ifdef ABIFLAGS SET_SYS_FROM_STRING("abiflags", ABIFLAGS); #endif From 74258ca2d67485368a8518d4a9d990dff1a97ba3 Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Wed, 1 Mar 2023 16:00:27 +0100 Subject: [PATCH 079/100] use core dll for windows specific --- Python/sysmodule.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Python/sysmodule.c b/Python/sysmodule.c index fcff12411a45ea..764fb70bae6c38 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -42,11 +42,11 @@ Data members: #include #endif /* MS_WINDOWS */ -#ifdef Py_ENABLE_SHARED +#ifdef MS_COREDLL extern void *PyWin_DLLhModule; /* A string loaded from the DLL at startup: */ extern const char *PyWin_DLLVersionString; -#endif /* Py_ENABLE_SHARED */ +#endif #ifdef __EMSCRIPTEN__ #include @@ -3162,10 +3162,10 @@ _PySys_InitCore(PyThreadState *tstate, PyObject *sysdict) SET_SYS_FROM_STRING("byteorder", "little"); #endif -#ifdef Py_ENABLE_SHARED +#ifdef MS_COREDLL SET_SYS("dllhandle", PyLong_FromVoidPtr(PyWin_DLLhModule)); SET_SYS_FROM_STRING("winver", PyWin_DLLVersionString); -#endif /* Py_ENABLE_SHARED */ +#endif #ifdef ABIFLAGS SET_SYS_FROM_STRING("abiflags", ABIFLAGS); #endif From 686da5948fd62e7408a866d00575ffc0ab1da833 Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Wed, 1 Mar 2023 16:15:50 +0100 Subject: [PATCH 080/100] Update Python/fileutils.c Co-authored-by: Steve Dower --- Python/fileutils.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Python/fileutils.c b/Python/fileutils.c index a0741bedc40cd7..5bd50750e869cd 100644 --- a/Python/fileutils.c +++ b/Python/fileutils.c @@ -2110,6 +2110,9 @@ _Py_abspath(const wchar_t *path, wchar_t **abspath_p) // The Windows Games API family does not provide these functions // so provide our own implementations. Remove them in case they get added // to the Games API family +// Note that this implementation does not handle all the same cases as the real +// function, but we expect games are very unlikely to encounter the more obscure +// cases. #if defined(MS_WINDOWS) && !defined(MS_WINDOWS_APP) && !defined(MS_WINDOWS_SYSTEM) HRESULT PathCchSkipRoot(const wchar_t *path, const wchar_t **rootEnd) From b151f7f3294383a41b28e60646c1192c231e55e6 Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Wed, 1 Mar 2023 16:28:53 +0100 Subject: [PATCH 081/100] apply code review --- Modules/mmapmodule.c | 2 ++ Modules/socketmodule.c | 3 +-- PC/config.c | 4 ++-- PC/pyconfig.h | 12 +++++++----- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/Modules/mmapmodule.c b/Modules/mmapmodule.c index a286db486dc89a..80cf50e5f69706 100644 --- a/Modules/mmapmodule.c +++ b/Modules/mmapmodule.c @@ -29,6 +29,8 @@ #include "structmember.h" // PyMemberDef #include // offsetof() +// to support MS_WINDOWS_SYSTEM OpenFileMappingA / CreateFileMappingA +// need to be replaced with OpenFileMappingW / CreateFileMappingW #if !defined(MS_WINDOWS) || defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_GAMES) #ifndef MS_WINDOWS diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c index b9fb0abaeb2c1d..44d6f5fc8ccead 100644 --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -5347,8 +5347,7 @@ sock_initobj_impl(PySocketSockObject *self, int family, int type, int proto, Py_BEGIN_ALLOW_THREADS fd = WSASocketW(FROM_PROTOCOL_INFO, FROM_PROTOCOL_INFO, - FROM_PROTOCOL_INFO, &info, 0, - WSA_FLAG_OVERLAPPED ); + FROM_PROTOCOL_INFO, &info, 0, WSA_FLAG_OVERLAPPED); Py_END_ALLOW_THREADS if (fd == INVALID_SOCKET) { set_error(); diff --git a/PC/config.c b/PC/config.c index 9a7c7f9a2c181e..9d0fe6f87df69a 100644 --- a/PC/config.c +++ b/PC/config.c @@ -43,7 +43,7 @@ extern PyObject* PyInit__collections(void); extern PyObject* PyInit__heapq(void); extern PyObject* PyInit__bisect(void); extern PyObject* PyInit__symtable(void); -#if !defined(MS_WINDOWS) || defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_GAMES) +#if defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_GAMES) extern PyObject* PyInit_mmap(void); #endif extern PyObject* PyInit__csv(void); @@ -126,7 +126,7 @@ struct _inittab _PyImport_Inittab[] = { {"itertools", PyInit_itertools}, {"_collections", PyInit__collections}, {"_symtable", PyInit__symtable}, -#if !defined(MS_WINDOWS) || defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_GAMES) +#if defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_GAMES) {"mmap", PyInit_mmap}, #endif {"_csv", PyInit__csv}, diff --git a/PC/pyconfig.h b/PC/pyconfig.h index 5267fd9942c0ce..019451c744c6ec 100644 --- a/PC/pyconfig.h +++ b/PC/pyconfig.h @@ -72,6 +72,7 @@ WIN32 is still required for the locale module. #define USE_SOCKET #endif +#ifdef Py_BUILD_CORE #include #if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) @@ -87,6 +88,12 @@ WIN32 is still required for the locale module. #define MS_WINDOWS_GAMES #endif +/* Define to 1 if you support windows console io */ +#if defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM) +#define HAVE_WINDOWS_CONSOLE_IO 1 +#endif +#endif /* Py_BUILD_CORE */ + /* Compiler specific defines */ /* ------------------------------------------------------------------------*/ @@ -399,11 +406,6 @@ Py_NO_ENABLE_SHARED to find out. Also support MS_NO_COREDLL for b/w compat */ /* Define to 1 if you have the header file. */ #define HAVE_CONIO_H 1 -/* Define to 1 if you support windows console io */ -#if defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM) -#define HAVE_WINDOWS_CONSOLE_IO 1 -#endif - /* Define to 1 if you have the header file. */ #define HAVE_DIRECT_H 1 From 39d2d130166cf10c0b9d12b41d5bc1edbe32b573 Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Wed, 1 Mar 2023 16:42:36 +0100 Subject: [PATCH 082/100] rename to PathCchCombineEx --- Python/fileutils.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/Python/fileutils.c b/Python/fileutils.c index 5bd50750e869cd..e97a42e8d2e758 100644 --- a/Python/fileutils.c +++ b/Python/fileutils.c @@ -2178,10 +2178,16 @@ PathAddBackslashW(wchar_t *path) return path + len; } -static int -win32_games_join_relfile(wchar_t *buffer, size_t bufsize, - const wchar_t *dirname, const wchar_t *relfile) +#ifndef PATHCCH_ALLOW_LONG_PATHS +#define PATHCCH_ALLOW_LONG_PATHS 0x01 +#endif + +static HRESULT +PathCchCombineEx(wchar_t *buffer, size_t bufsize, const wchar_t *dirname, + const wchar_t *relfile, unsigned long flags) { + (void)flags; + if ((isalpha(relfile[0]) && relfile[1] == ':') || (relfile[0] == '\\' && relfile[1] == '\\')) { @@ -2194,7 +2200,7 @@ win32_games_join_relfile(wchar_t *buffer, size_t bufsize, /* path is at max dirname + filename + backslash + \0 */ size_t new_len = dir_len + file_len + 2; if (bufsize >= MAXPATHLEN || new_len > bufsize) { - return -1; + return E_INVALIDARG; } size_t combined_length = dir_len; @@ -2216,7 +2222,7 @@ win32_games_join_relfile(wchar_t *buffer, size_t bufsize, PathAddBackslashW(buffer); wcscat(buffer, relfile); } - return 0; + return S_OK; } #endif /* MS_WINDOWS && !MS_WINDOWS_APP && !MS_WINDOWS_SYSTEM */ @@ -2225,16 +2231,11 @@ static int join_relfile(wchar_t *buffer, size_t bufsize, const wchar_t *dirname, const wchar_t *relfile) { -#if defined(MS_WINDOWS) -#if defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM) +#ifdef MS_WINDOWS if (FAILED(PathCchCombineEx(buffer, bufsize, dirname, relfile, PATHCCH_ALLOW_LONG_PATHS))) { return -1; } - return 0; -#else - return win32_games_join_relfile(buffer, bufsize, dirname, relfile) -#endif /* MS_WINDOWS_APP && MS_WINDOWS_SYSTEM */ #else assert(!_Py_isabs(relfile)); size_t dirlen = wcslen(dirname); @@ -2258,8 +2259,8 @@ join_relfile(wchar_t *buffer, size_t bufsize, } wcscpy(&buffer[relstart], relfile); } - return 0; #endif + return 0; } /* Join the two paths together, like os.path.join(). Return NULL From 2895563e47d892035695f098ff22b1480dc0d54f Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Wed, 1 Mar 2023 17:14:02 +0100 Subject: [PATCH 083/100] define for all BUILD_CORE --- PC/pyconfig.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/PC/pyconfig.h b/PC/pyconfig.h index 019451c744c6ec..b40085dd06fbe6 100644 --- a/PC/pyconfig.h +++ b/PC/pyconfig.h @@ -72,7 +72,7 @@ WIN32 is still required for the locale module. #define USE_SOCKET #endif -#ifdef Py_BUILD_CORE +#if defined(Py_BUILD_CORE) || defined(Py_BUILD_CORE_BUILTIN) || defined(Py_BUILD_CORE_MODULE) #include #if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) @@ -92,7 +92,7 @@ WIN32 is still required for the locale module. #if defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM) #define HAVE_WINDOWS_CONSOLE_IO 1 #endif -#endif /* Py_BUILD_CORE */ +#endif /* Py_BUILD_CORE || Py_BUILD_CORE_BUILTIN || Py_BUILD_CORE_MODULE */ /* Compiler specific defines */ From 8e3d3c5c99c3be0c8c8754589e1ce5267959c78b Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Wed, 1 Mar 2023 18:24:36 +0100 Subject: [PATCH 084/100] cleanup --- Modules/clinic/posixmodule.c.h | 10 +++++----- Modules/mmapmodule.c | 2 +- Modules/posixmodule.c | 4 ++-- PC/clinic/msvcrtmodule.c.h | 6 +++--- PC/msvcrtmodule.c | 2 +- PC/pyconfig.h | 2 +- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Modules/clinic/posixmodule.c.h b/Modules/clinic/posixmodule.c.h index a03df9efb77380..6565f8df935cb8 100644 --- a/Modules/clinic/posixmodule.c.h +++ b/Modules/clinic/posixmodule.c.h @@ -10988,7 +10988,7 @@ os_getrandom(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject #endif /* defined(HAVE_GETRANDOM_SYSCALL) */ -#if (defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM)) +#if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM)) PyDoc_STRVAR(os__add_dll_directory__doc__, "_add_dll_directory($module, /, path)\n" @@ -11057,9 +11057,9 @@ os__add_dll_directory(PyObject *module, PyObject *const *args, Py_ssize_t nargs, return return_value; } -#endif /* (defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM)) */ +#endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM)) */ -#if (defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM)) +#if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM)) PyDoc_STRVAR(os__remove_dll_directory__doc__, "_remove_dll_directory($module, /, cookie)\n" @@ -11120,7 +11120,7 @@ os__remove_dll_directory(PyObject *module, PyObject *const *args, Py_ssize_t nar return return_value; } -#endif /* (defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM)) */ +#endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM)) */ #if (defined(WIFEXITED) || defined(MS_WINDOWS)) @@ -11796,4 +11796,4 @@ os_waitstatus_to_exitcode(PyObject *module, PyObject *const *args, Py_ssize_t na #ifndef OS_WAITSTATUS_TO_EXITCODE_METHODDEF #define OS_WAITSTATUS_TO_EXITCODE_METHODDEF #endif /* !defined(OS_WAITSTATUS_TO_EXITCODE_METHODDEF) */ -/*[clinic end generated code: output=804f6e46ed7a369b input=a9049054013a1b77]*/ +/*[clinic end generated code: output=9495478e51701b8a input=a9049054013a1b77]*/ diff --git a/Modules/mmapmodule.c b/Modules/mmapmodule.c index 80cf50e5f69706..352af7bc030df7 100644 --- a/Modules/mmapmodule.c +++ b/Modules/mmapmodule.c @@ -651,7 +651,7 @@ mmap_flush_method(mmap_object *self, PyObject *args) if (self->access == ACCESS_READ || self->access == ACCESS_COPY) Py_RETURN_NONE; -#if defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM) +#if defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM) if (!FlushViewOfFile(self->data+offset, size)) { PyErr_SetFromWindowsErr(GetLastError()); return NULL; diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 3a90e42c29d5e4..d8eb9ef84323d7 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -8391,7 +8391,7 @@ os_kill_impl(PyObject *module, pid_t pid, Py_ssize_t signal) DWORD err; HANDLE handle; -#if defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM) +#if defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM) /* Console processes which share a common console can be sent CTRL+C or CTRL+BREAK events, provided they handle said events. */ if (sig == CTRL_C_EVENT || sig == CTRL_BREAK_EVENT) { @@ -15036,7 +15036,7 @@ os_getrandom_impl(PyObject *module, Py_ssize_t size, int flags) } #endif /* HAVE_GETRANDOM_SYSCALL */ -#if defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM) +#if defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM) /* bpo-36085: Helper functions for managing DLL search directories * on win32 diff --git a/PC/clinic/msvcrtmodule.c.h b/PC/clinic/msvcrtmodule.c.h index 70f355cc6d6faf..b708c6cdde757c 100644 --- a/PC/clinic/msvcrtmodule.c.h +++ b/PC/clinic/msvcrtmodule.c.h @@ -626,7 +626,7 @@ msvcrt_set_error_mode(PyObject *module, PyObject *arg) #endif /* defined(_DEBUG) */ -#if (defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM)) +#if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM)) PyDoc_STRVAR(msvcrt_GetErrorMode__doc__, "GetErrorMode($module, /)\n" @@ -646,7 +646,7 @@ msvcrt_GetErrorMode(PyObject *module, PyObject *Py_UNUSED(ignored)) return msvcrt_GetErrorMode_impl(module); } -#endif /* (defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM)) */ +#endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM)) */ PyDoc_STRVAR(msvcrt_SetErrorMode__doc__, "SetErrorMode($module, mode, /)\n" @@ -707,4 +707,4 @@ msvcrt_SetErrorMode(PyObject *module, PyObject *arg) #ifndef MSVCRT_GETERRORMODE_METHODDEF #define MSVCRT_GETERRORMODE_METHODDEF #endif /* !defined(MSVCRT_GETERRORMODE_METHODDEF) */ -/*[clinic end generated code: output=66607ffeda8a5f8b input=a9049054013a1b77]*/ +/*[clinic end generated code: output=2db6197608a6aab3 input=a9049054013a1b77]*/ diff --git a/PC/msvcrtmodule.c b/PC/msvcrtmodule.c index b4d026c120913d..face4d03af9d4f 100644 --- a/PC/msvcrtmodule.c +++ b/PC/msvcrtmodule.c @@ -491,7 +491,7 @@ msvcrt_set_error_mode_impl(PyObject *module, int mode) } #endif /* _DEBUG */ -#if defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM) +#if defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM) /*[clinic input] msvcrt.GetErrorMode diff --git a/PC/pyconfig.h b/PC/pyconfig.h index b40085dd06fbe6..8a3bf8968ce29d 100644 --- a/PC/pyconfig.h +++ b/PC/pyconfig.h @@ -89,7 +89,7 @@ WIN32 is still required for the locale module. #endif /* Define to 1 if you support windows console io */ -#if defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM) +#if defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM) #define HAVE_WINDOWS_CONSOLE_IO 1 #endif #endif /* Py_BUILD_CORE || Py_BUILD_CORE_BUILTIN || Py_BUILD_CORE_MODULE */ From 659d1a3f88d7fa7071cda907afb5fd948d1494a1 Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Wed, 1 Mar 2023 19:04:47 +0100 Subject: [PATCH 085/100] Update Modules/_randommodule.c Co-authored-by: Eryk Sun --- Modules/_randommodule.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/_randommodule.c b/Modules/_randommodule.c index 3f9bdce6e3572f..6e22053239305a 100644 --- a/Modules/_randommodule.c +++ b/Modules/_randommodule.c @@ -263,7 +263,7 @@ random_seed_time_pid(RandomObject *self) key[0] = (uint32_t)(now & 0xffffffffU); key[1] = (uint32_t)(now >> 32); -#if defined(MS_WINDOWS) && !defined(MS_WINDOWS_DESKTOP) +#if defined(MS_WINDOWS) && !defined(MS_WINDOWS_DESKTOP) && !defined(MS_WINDOWS_SYSTEM) key[2] = (uint32_t)GetCurrentProcessId(); #elif defined(HAVE_GETPID) key[2] = (uint32_t)getpid(); From e9ff60ea631831121d1b4609663167095a5202a9 Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Thu, 2 Mar 2023 14:33:59 +0100 Subject: [PATCH 086/100] add MS_WINDOWS_CRT_DESKTOP --- Modules/mmapmodule.c | 2 +- Modules/posixmodule.c | 2 +- Modules/timemodule.c | 4 ++-- PC/pyconfig.h | 4 ++++ 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Modules/mmapmodule.c b/Modules/mmapmodule.c index 352af7bc030df7..fe76ca6eafaa88 100644 --- a/Modules/mmapmodule.c +++ b/Modules/mmapmodule.c @@ -1729,4 +1729,4 @@ PyInit_mmap(void) return PyModuleDef_Init(&mmapmodule); } -#endif /* !MS_WINDOWS || MS_WINDOWS_DESKTOP || MS_WINDOWS_SYSTEM || MS_WINDOWS_GAMES */ +#endif /* !MS_WINDOWS || MS_WINDOWS_DESKTOP || MS_WINDOWS_GAMES */ diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index d8eb9ef84323d7..94aee9b932c45c 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -7932,7 +7932,7 @@ static PyObject * os_getpid_impl(PyObject *module) /*[clinic end generated code: output=9ea6fdac01ed2b3c input=5a9a00f0ab68aa00]*/ { -#if !defined(MS_WINDOWS) || defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) +#if !defined(MS_WINDOWS) || defined(MS_WINDOWS_CRT_DESKTOP) return PyLong_FromPid(getpid()); #else return PyLong_FromUnsignedLong(GetCurrentProcessId()); diff --git a/Modules/timemodule.c b/Modules/timemodule.c index c612eaeca157a2..367523bbcf3683 100644 --- a/Modules/timemodule.c +++ b/Modules/timemodule.c @@ -1137,7 +1137,7 @@ time_tzset(PyObject *self, PyObject *unused) return NULL; } -#if !defined(MS_WINDOWS) || defined(MS_WINDOWS_DESKTOP) +#if !defined(MS_WINDOWS) || defined(MS_WINDOWS_CRT_DESKTOP) tzset(); #endif @@ -1757,7 +1757,7 @@ init_timezone(PyObject *m) */ #ifdef HAVE_DECL_TZNAME PyObject *otz0, *otz1; -#if !defined(MS_WINDOWS) || defined(MS_WINDOWS_DESKTOP) +#if !defined(MS_WINDOWS) || defined(MS_WINDOWS_CRT_DESKTOP) tzset(); #endif PyModule_AddIntConstant(m, "timezone", _Py_timezone); diff --git a/PC/pyconfig.h b/PC/pyconfig.h index 8a3bf8968ce29d..f1c56a961525c9 100644 --- a/PC/pyconfig.h +++ b/PC/pyconfig.h @@ -88,6 +88,10 @@ WIN32 is still required for the locale module. #define MS_WINDOWS_GAMES #endif +#if defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) +#define MS_WINDOWS_CRT_DESKTOP +#endif + /* Define to 1 if you support windows console io */ #if defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM) #define HAVE_WINDOWS_CONSOLE_IO 1 From 32c4886a3e03379cb600607904d9805d4f9d7bf9 Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Thu, 2 Mar 2023 20:15:23 +0100 Subject: [PATCH 087/100] Update Modules/posixmodule.c Co-authored-by: Eryk Sun --- Modules/posixmodule.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 94aee9b932c45c..b4ea0fb1673029 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -8403,7 +8403,7 @@ os_kill_impl(PyObject *module, pid_t pid, Py_ssize_t signal) Py_RETURN_NONE; } } -#endif /* MS_WINDOWS_APP || MS_WINDOWS_SYSTEM */ +#endif /* HAVE_WINDOWS_CONSOLE_IO */ /* If the signal is outside of what GenerateConsoleCtrlEvent can use, attempt to open and terminate the process. */ From 2f1fe409890997ccc387f7ace98abc768f35ac0b Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Thu, 2 Mar 2023 20:15:32 +0100 Subject: [PATCH 088/100] Update Modules/posixmodule.c Co-authored-by: Eryk Sun --- Modules/posixmodule.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index b4ea0fb1673029..2038f36f9e38d9 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -8391,7 +8391,7 @@ os_kill_impl(PyObject *module, pid_t pid, Py_ssize_t signal) DWORD err; HANDLE handle; -#if defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM) +#ifdef HAVE_WINDOWS_CONSOLE_IO /* Console processes which share a common console can be sent CTRL+C or CTRL+BREAK events, provided they handle said events. */ if (sig == CTRL_C_EVENT || sig == CTRL_BREAK_EVENT) { From 5854e918428cdb5a88248bf98a506ff288b0bead Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Fri, 3 Mar 2023 00:06:10 +0100 Subject: [PATCH 089/100] revert MS_WINDOWS_CRT_DESKTOP --- Modules/posixmodule.c | 2 +- Modules/timemodule.c | 4 ++-- PC/pyconfig.h | 4 ---- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 2038f36f9e38d9..4ef2a95ae06e33 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -7932,7 +7932,7 @@ static PyObject * os_getpid_impl(PyObject *module) /*[clinic end generated code: output=9ea6fdac01ed2b3c input=5a9a00f0ab68aa00]*/ { -#if !defined(MS_WINDOWS) || defined(MS_WINDOWS_CRT_DESKTOP) +#if !defined(MS_WINDOWS) || defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) return PyLong_FromPid(getpid()); #else return PyLong_FromUnsignedLong(GetCurrentProcessId()); diff --git a/Modules/timemodule.c b/Modules/timemodule.c index 367523bbcf3683..c50e689bb6986c 100644 --- a/Modules/timemodule.c +++ b/Modules/timemodule.c @@ -1137,7 +1137,7 @@ time_tzset(PyObject *self, PyObject *unused) return NULL; } -#if !defined(MS_WINDOWS) || defined(MS_WINDOWS_CRT_DESKTOP) +#if !defined(MS_WINDOWS) || defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) tzset(); #endif @@ -1757,7 +1757,7 @@ init_timezone(PyObject *m) */ #ifdef HAVE_DECL_TZNAME PyObject *otz0, *otz1; -#if !defined(MS_WINDOWS) || defined(MS_WINDOWS_CRT_DESKTOP) +#if !defined(MS_WINDOWS) || defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) tzset(); #endif PyModule_AddIntConstant(m, "timezone", _Py_timezone); diff --git a/PC/pyconfig.h b/PC/pyconfig.h index f1c56a961525c9..8a3bf8968ce29d 100644 --- a/PC/pyconfig.h +++ b/PC/pyconfig.h @@ -88,10 +88,6 @@ WIN32 is still required for the locale module. #define MS_WINDOWS_GAMES #endif -#if defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) -#define MS_WINDOWS_CRT_DESKTOP -#endif - /* Define to 1 if you support windows console io */ #if defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM) #define HAVE_WINDOWS_CONSOLE_IO 1 From d3d2e1ceb74d2f96586cab33c4a26e3342e06433 Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Fri, 3 Mar 2023 01:36:14 +0100 Subject: [PATCH 090/100] use MS_WINDOWS_SYSTEM --- Modules/posixmodule.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 4ef2a95ae06e33..5af1f6aeb8fd06 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -30,9 +30,9 @@ # include # include // UNLEN # include "osdefs.h" // SEP -# ifdef MS_WINDOWS_DESKTOP +# if defined(MS_WINDOWS_DESKTOP) | defined(MS_WINDOWS_SYSTEM) # define HAVE_SYMLINK -# endif +# endif /* MS_WINDOWS_DESKTOP | MS_WINDOWS_SYSTEM */ #endif #include "structmember.h" // PyMemberDef @@ -333,16 +333,20 @@ corresponding Unix manual entries for more information on calls."); # include #elif defined( _MSC_VER) /* Microsoft compiler */ -# ifdef MS_WINDOWS_DESKTOP +# if defined(MS_WINDOWS_DESKTOP) | defined(MS_WINDOWS_APP) | defined(MS_WINDOWS_SYSTEM) # define HAVE_GETPPID 1 +# endif /* MS_WINDOWS_DESKTOP | MS_WINDOWS_APP | MS_WINDOWS_SYSTEM */ +# if defined(MS_WINDOWS_DESKTOP) # define HAVE_GETLOGIN 1 +# endif /* MS_WINDOWS_DESKTOP */ +# if defined(MS_WINDOWS_DESKTOP) | defined(MS_WINDOWS_SYSTEM) # define HAVE_SPAWNV 1 # define HAVE_EXECV 1 # define HAVE_WSPAWNV 1 # define HAVE_WEXECV 1 # define HAVE_SYSTEM 1 # define HAVE_CWAIT 1 -# endif /* MS_WINDOWS_DESKTOP */ +# endif /* MS_WINDOWS_DESKTOP | MS_WINDOWS_SYSTEM */ # define HAVE_PIPE 1 # define HAVE_FSYNC 1 # define fsync _commit From b1ffce94d375d4935da36e5e4c3dccc5d59ccf5f Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Fri, 3 Mar 2023 02:02:26 +0100 Subject: [PATCH 091/100] Apply suggestions from code review Co-authored-by: Eryk Sun --- Modules/posixmodule.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 5af1f6aeb8fd06..814d52db3092f5 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -30,7 +30,7 @@ # include # include // UNLEN # include "osdefs.h" // SEP -# if defined(MS_WINDOWS_DESKTOP) | defined(MS_WINDOWS_SYSTEM) +# if defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) # define HAVE_SYMLINK # endif /* MS_WINDOWS_DESKTOP | MS_WINDOWS_SYSTEM */ #endif @@ -333,13 +333,13 @@ corresponding Unix manual entries for more information on calls."); # include #elif defined( _MSC_VER) /* Microsoft compiler */ -# if defined(MS_WINDOWS_DESKTOP) | defined(MS_WINDOWS_APP) | defined(MS_WINDOWS_SYSTEM) +# if defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM) # define HAVE_GETPPID 1 # endif /* MS_WINDOWS_DESKTOP | MS_WINDOWS_APP | MS_WINDOWS_SYSTEM */ # if defined(MS_WINDOWS_DESKTOP) # define HAVE_GETLOGIN 1 # endif /* MS_WINDOWS_DESKTOP */ -# if defined(MS_WINDOWS_DESKTOP) | defined(MS_WINDOWS_SYSTEM) +# if defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) # define HAVE_SPAWNV 1 # define HAVE_EXECV 1 # define HAVE_WSPAWNV 1 From 0b4d4075df829d4bb8884402b72ce91c0703bf79 Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Fri, 3 Mar 2023 03:02:41 +0100 Subject: [PATCH 092/100] Update Modules/socketmodule.c Co-authored-by: Eryk Sun --- Modules/socketmodule.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c index 44d6f5fc8ccead..b7927750e334b7 100644 --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -2883,7 +2883,10 @@ sock_accept(PySocketSockObject *s, PyObject *Py_UNUSED(ignored)) newfd = ctx.result; #ifdef MS_WINDOWS -#ifdef MS_WINDOWS_DESKTOP +#if defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM) +#ifndef HANDLE_FLAG_INHERIT +#define HANDLE_FLAG_INHERIT 0x00000001 +#endif if (!SetHandleInformation((HANDLE)newfd, HANDLE_FLAG_INHERIT, 0)) { PyErr_SetFromWindowsErr(0); SOCKETCLOSE(newfd); From d9976dcc6d01b216b020795d05bcdd7f1b9f673f Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Fri, 3 Mar 2023 21:17:30 +0100 Subject: [PATCH 093/100] handle failing malloc --- Modules/posixmodule.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 814d52db3092f5..a8fe82145a653b 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -1539,7 +1539,7 @@ convertenviron(void) #ifdef MS_WINDOWS /* _wenviron must be initialized in this way if the program is started through main() instead of wmain(). */ - _wgetenv(L""); + (void)_wgetenv(L""); e = _wenviron; #elif defined(WITH_NEXT_FRAMEWORK) || (defined(__APPLE__) && defined(Py_ENABLE_SHARED)) /* environ is not accessible as an extern in a shared object on OSX; use @@ -1788,6 +1788,9 @@ attributes_from_dir(LPCWSTR pszFile, BY_HANDLE_FILE_INFORMATION *info, ULONG *re if (n && (pszFile[n - 1] == L'\\' || pszFile[n - 1] == L'/')) { // cannot use PyMem_Malloc here because we do not hold the GIL filename = (LPCWSTR)malloc((n + 1) * sizeof(filename[0])); + if(!filename) { + return FALSE; + } wcsncpy_s((LPWSTR)filename, n + 1, pszFile, n); while (--n > 0 && (filename[n] == L'\\' || filename[n] == L'/')) { ((LPWSTR)filename)[n] = L'\0'; From 427de79353681ec4de08bc1b7ef99621fb20c7f5 Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Sat, 4 Mar 2023 07:38:57 +0100 Subject: [PATCH 094/100] Update Modules/posixmodule.c Co-authored-by: Eryk Sun --- Modules/posixmodule.c | 1 + 1 file changed, 1 insertion(+) diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index a8fe82145a653b..55498da54c64ed 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -1789,6 +1789,7 @@ attributes_from_dir(LPCWSTR pszFile, BY_HANDLE_FILE_INFORMATION *info, ULONG *re // cannot use PyMem_Malloc here because we do not hold the GIL filename = (LPCWSTR)malloc((n + 1) * sizeof(filename[0])); if(!filename) { + SetLastError(ERROR_NOT_ENOUGH_MEMORY); return FALSE; } wcsncpy_s((LPWSTR)filename, n + 1, pszFile, n); From 603cea744ad7b314ce9ff895fc19d2e1bab4334f Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Mon, 6 Mar 2023 20:07:18 +0100 Subject: [PATCH 095/100] Update Python/fileutils.c Co-authored-by: Eryk Sun --- Python/fileutils.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Python/fileutils.c b/Python/fileutils.c index e97a42e8d2e758..d0f2eac3b21d16 100644 --- a/Python/fileutils.c +++ b/Python/fileutils.c @@ -2113,7 +2113,7 @@ _Py_abspath(const wchar_t *path, wchar_t **abspath_p) // Note that this implementation does not handle all the same cases as the real // function, but we expect games are very unlikely to encounter the more obscure // cases. -#if defined(MS_WINDOWS) && !defined(MS_WINDOWS_APP) && !defined(MS_WINDOWS_SYSTEM) +#if defined(MS_WINDOWS_GAMES) && !defined(MS_WINDOWS_DESKTOP) HRESULT PathCchSkipRoot(const wchar_t *path, const wchar_t **rootEnd) { From 6db80a3f3f1d0e28ec7c208dc8bae694546afa11 Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Mon, 6 Mar 2023 20:07:42 +0100 Subject: [PATCH 096/100] Update Include/internal/pycore_fileutils.h Co-authored-by: Eryk Sun --- Include/internal/pycore_fileutils.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Include/internal/pycore_fileutils.h b/Include/internal/pycore_fileutils.h index 1a5c51e60a1c96..24de1f49e06661 100644 --- a/Include/internal/pycore_fileutils.h +++ b/Include/internal/pycore_fileutils.h @@ -254,7 +254,7 @@ PyAPI_FUNC(wchar_t *) _Py_normpath(wchar_t *path, Py_ssize_t size); // The Windows Games API family does not provide these functions // so provide our own implementations. Remove them in case they get added // to the Games API family -#if defined(MS_WINDOWS) && !defined(MS_WINDOWS_APP) && !defined(MS_WINDOWS_SYSTEM) +#if defined(MS_WINDOWS_GAMES) && !defined(MS_WINDOWS_DESKTOP) #include extern HRESULT PathCchSkipRoot(const wchar_t *pszPath, const wchar_t **ppszRootEnd); From 4d78066728b01e11a815ebccd398520d5fc0203d Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Mon, 6 Mar 2023 21:00:44 +0100 Subject: [PATCH 097/100] Update Include/internal/pycore_fileutils.h Co-authored-by: Eryk Sun --- Include/internal/pycore_fileutils.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Include/internal/pycore_fileutils.h b/Include/internal/pycore_fileutils.h index 24de1f49e06661..445ac0a3d955d9 100644 --- a/Include/internal/pycore_fileutils.h +++ b/Include/internal/pycore_fileutils.h @@ -258,7 +258,7 @@ PyAPI_FUNC(wchar_t *) _Py_normpath(wchar_t *path, Py_ssize_t size); #include extern HRESULT PathCchSkipRoot(const wchar_t *pszPath, const wchar_t **ppszRootEnd); -#endif /* defined(MS_WINDOWS) && !defined(MS_WINDOWS_APP) && !defined(MS_WINDOWS_SYSTEM) */ +#endif /* defined(MS_WINDOWS_GAMES) && !defined(MS_WINDOWS_DESKTOP) */ // Macros to protect CRT calls against instant termination when passed an // invalid parameter (bpo-23524). IPH stands for Invalid Parameter Handler. From 65cdd56155afde2f4917561d9cae846b9bbf8515 Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Mon, 6 Mar 2023 21:00:57 +0100 Subject: [PATCH 098/100] Update Python/fileutils.c Co-authored-by: Eryk Sun --- Python/fileutils.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Python/fileutils.c b/Python/fileutils.c index d0f2eac3b21d16..c58fbd1dc54bdb 100644 --- a/Python/fileutils.c +++ b/Python/fileutils.c @@ -2224,7 +2224,7 @@ PathCchCombineEx(wchar_t *buffer, size_t bufsize, const wchar_t *dirname, } return S_OK; } -#endif /* MS_WINDOWS && !MS_WINDOWS_APP && !MS_WINDOWS_SYSTEM */ +#endif /* defined(MS_WINDOWS_GAMES) && !defined(MS_WINDOWS_DESKTOP) */ // The caller must ensure "buffer" is big enough. static int From 35217ab31d02218d2989c400b448b5566dbb2ff0 Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Tue, 7 Mar 2023 18:39:13 +0100 Subject: [PATCH 099/100] Update Python/fileutils.c Co-authored-by: Eryk Sun --- Python/fileutils.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Python/fileutils.c b/Python/fileutils.c index c58fbd1dc54bdb..da172d7db64e34 100644 --- a/Python/fileutils.c +++ b/Python/fileutils.c @@ -2199,7 +2199,7 @@ PathCchCombineEx(wchar_t *buffer, size_t bufsize, const wchar_t *dirname, size_t file_len = relfile ? wcslen(relfile) : 0; /* path is at max dirname + filename + backslash + \0 */ size_t new_len = dir_len + file_len + 2; - if (bufsize >= MAXPATHLEN || new_len > bufsize) { + if (new_len > bufsize) { return E_INVALIDARG; } From 331b1f4289914c281c27f0974770bc572e31b7e3 Mon Sep 17 00:00:00 2001 From: Max Bachmann Date: Thu, 9 Mar 2023 15:10:50 +0100 Subject: [PATCH 100/100] dynamically import from api-ms-win-core-path-l1-1-0.dll --- Modules/posixmodule.c | 4 +- Python/fileutils.c | 146 ++++++++++++++---------------------------- 2 files changed, 52 insertions(+), 98 deletions(-) diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 55498da54c64ed..136e2d883f427f 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -26,7 +26,9 @@ #ifdef MS_WINDOWS # include -# include +# if !defined(MS_WINDOWS_GAMES) || defined(MS_WINDOWS_DESKTOP) +# include +# endif # include # include // UNLEN # include "osdefs.h" // SEP diff --git a/Python/fileutils.c b/Python/fileutils.c index da172d7db64e34..4ac759c45a3a1e 100644 --- a/Python/fileutils.c +++ b/Python/fileutils.c @@ -8,7 +8,11 @@ #ifdef MS_WINDOWS # include # include -# include // PathCchCombineEx +# if defined(MS_WINDOWS_GAMES) && !defined(MS_WINDOWS_DESKTOP) +# define PATHCCH_ALLOW_LONG_PATHS 0x01 +# else +# include // PathCchCombineEx +# endif extern int winerror_to_errno(int); #endif @@ -2107,123 +2111,71 @@ _Py_abspath(const wchar_t *path, wchar_t **abspath_p) #endif } -// The Windows Games API family does not provide these functions -// so provide our own implementations. Remove them in case they get added -// to the Games API family -// Note that this implementation does not handle all the same cases as the real -// function, but we expect games are very unlikely to encounter the more obscure -// cases. +// The Windows Games API family implements the PathCch* APIs in the Xbox OS, +// but does not expose them yet. Load them dynamically until +// 1) they are officially exposed +// 2) we stop supporting older versions of the GDK which do not expose them #if defined(MS_WINDOWS_GAMES) && !defined(MS_WINDOWS_DESKTOP) HRESULT PathCchSkipRoot(const wchar_t *path, const wchar_t **rootEnd) { - if (path[0] == '\\') { - /* relative path with root e.g. \Windows */ - if (path[1] != '\\') { - *rootEnd = path + 1; - return S_OK; + static int initialized = 0; + typedef HRESULT(__stdcall *PPathCchSkipRoot) (PCWSTR pszPath, + PCWSTR *ppszRootEnd); + static PPathCchSkipRoot _PathCchSkipRoot; + + if (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"); } - - /* UNC drives e.g. \\server\share or \\?\UNC\server\share */ - const wchar_t *end = path + 2; - if (!wcsnicmp(end, L"?\\UNC\\", 6)) { - end += 6; - } - - end = wcschr(end, '\\'); - if (!end) { - *rootEnd = path + wcslen(path); - return S_OK; + else { + _PathCchSkipRoot = NULL; } - end = wcschr(end + 1, '\\'); - *rootEnd = (!end) ? path + wcslen(path) : end + 1; - return S_OK; + initialized = 1; } - /* absolute / relative path with drive, e.g. C: or C:\ */ - else if (isalpha(path[0]) && path[1] == ':') { - *rootEnd = (path[2] == '\\') ? path + 3 : path + 2; - return S_OK; - } - - /* relative path */ - return E_INVALIDARG; -} -static HRESULT -PathCchStripToRoot(wchar_t *path, size_t size) -{ - wchar_t *end; - if (PathCchSkipRoot(path, &end) == S_OK) { - if (*end == '\0') { - return S_FALSE; - } - *end = '\0'; + if (!_PathCchSkipRoot) { + return E_NOINTERFACE; } - return E_INVALIDARG; + return _PathCchSkipRoot(path, rootEnd); } -static wchar_t* -PathAddBackslashW(wchar_t *path) -{ - size_t len; - if (!path) { - return NULL; - } - len = wcslen(path); - if (len && path[len - 1] != '\\') { - path[len++] = '\\'; - path[len] = '\0'; - } - return path + len; -} - -#ifndef PATHCCH_ALLOW_LONG_PATHS -#define PATHCCH_ALLOW_LONG_PATHS 0x01 -#endif - static HRESULT PathCchCombineEx(wchar_t *buffer, size_t bufsize, const wchar_t *dirname, const wchar_t *relfile, unsigned long flags) { - (void)flags; - - if ((isalpha(relfile[0]) && relfile[1] == ':') || - (relfile[0] == '\\' && relfile[1] == '\\')) - { - dirname = relfile; - relfile = NULL; - } - - size_t dir_len = wcslen(dirname); - size_t file_len = relfile ? wcslen(relfile) : 0; - /* path is at max dirname + filename + backslash + \0 */ - size_t new_len = dir_len + file_len + 2; - if (new_len > bufsize) { - return E_INVALIDARG; - } - - size_t combined_length = dir_len; - wcscpy(buffer, dirname); - if (!relfile || !relfile[0]) { - if(wcsncmp(buffer, L"\\\\?\\", 4)) { - buffer += 4; + static int initialized = 0; + typedef HRESULT(__stdcall *PPathCchCombineEx) (PWSTR pszPathOut, + size_t cchPathOut, + PCWSTR pszPathIn, + PCWSTR pszMore, + unsigned long dwFlags); + static PPathCchCombineEx _PathCchCombineEx; + + if (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"); } - if (isalpha(buffer[0]) && buffer[1] == ':' && !buffer[2]) { - PathAddBackslashW(buffer); + else { + _PathCchCombineEx = NULL; } + initialized = 1; } - else { - if (relfile[0] == '\\' && relfile[1] != '\\') - { - PathCchStripToRoot(buffer, combined_length); - relfile++; - } - PathAddBackslashW(buffer); - wcscat(buffer, relfile); + + if (!_PathCchCombineEx) { + return E_NOINTERFACE; } - return S_OK; + + return _PathCchCombineEx(buffer, bufsize, dirname, relfile, flags); } + #endif /* defined(MS_WINDOWS_GAMES) && !defined(MS_WINDOWS_DESKTOP) */ // The caller must ensure "buffer" is big enough.