gh-102255: Improve build support for Windows API partitions (GH-102256)

Add `MS_WINDOWS_DESKTOP`, `MS_WINDOWS_APPS`, `MS_WINDOWS_SYSTEM` and `MS_WINDOWS_GAMES` preprocessor definitions to allow switching off functionality missing from particular API partitions ("partitions" are used in Windows to identify overlapping subsets of APIs).
CPython only officially supports `MS_WINDOWS_DESKTOP` and `MS_WINDOWS_SYSTEM` (APPS is included by normal desktop builds, but APPS without DESKTOP is not covered). Other configurations are a convenience for people building their own runtimes.
`MS_WINDOWS_GAMES` is for the Xbox subset of the Windows API, which is also available on client OS, but is restricted compared to `MS_WINDOWS_DESKTOP`. These restrictions may change over time, as they relate to the build headers rather than the OS support, and so we assume that Xbox builds will use the latest available version of the GDK.
This commit is contained in:
Max Bachmann 2023-03-09 22:09:12 +01:00 committed by GitHub
parent ca066bdbed
commit c6858d1e7f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
36 changed files with 633 additions and 100 deletions

View file

@ -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
#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,
#ifdef MS_WINDOWS
#ifdef HAVE_WINDOWS_CONSOLE_IO
&PyWindowsConsoleIO_Type,
#endif
};
@ -718,7 +718,7 @@ PyInit__io(void)
}
// Set type base classes
#ifdef MS_WINDOWS
#ifdef HAVE_WINDOWS_CONSOLE_IO
PyWindowsConsoleIO_Type.tp_base = &PyRawIOBase_Type;
#endif

View file

@ -26,9 +26,9 @@ extern PyType_Spec fileio_spec;
extern PyType_Spec stringio_spec;
extern PyType_Spec textiowrapper_spec;
#ifdef MS_WINDOWS
#ifdef HAVE_WINDOWS_CONSOLE_IO
extern PyTypeObject PyWindowsConsoleIO_Type;
#endif /* MS_WINDOWS */
#endif /* HAVE_WINDOWS_CONSOLE_IO */
/* 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
#ifdef HAVE_WINDOWS_CONSOLE_IO
extern char _PyIO_get_console_type(PyObject *);
#endif

View file

@ -8,7 +8,7 @@ preserve
#endif
#if defined(MS_WINDOWS)
#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) */
#endif /* defined(HAVE_WINDOWS_CONSOLE_IO) */
#if defined(MS_WINDOWS)
#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 @@ exit:
return return_value;
}
#endif /* defined(MS_WINDOWS) */
#endif /* defined(HAVE_WINDOWS_CONSOLE_IO) */
#if defined(MS_WINDOWS)
#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) */
#endif /* defined(HAVE_WINDOWS_CONSOLE_IO) */
#if defined(MS_WINDOWS)
#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) */
#endif /* defined(HAVE_WINDOWS_CONSOLE_IO) */
#if defined(MS_WINDOWS)
#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) */
#endif /* defined(HAVE_WINDOWS_CONSOLE_IO) */
#if defined(MS_WINDOWS)
#if defined(HAVE_WINDOWS_CONSOLE_IO)
PyDoc_STRVAR(_io__WindowsConsoleIO_readinto__doc__,
"readinto($self, buffer, /)\n"
@ -239,9 +239,9 @@ exit:
return return_value;
}
#endif /* defined(MS_WINDOWS) */
#endif /* defined(HAVE_WINDOWS_CONSOLE_IO) */
#if defined(MS_WINDOWS)
#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) */
#endif /* defined(HAVE_WINDOWS_CONSOLE_IO) */
#if defined(MS_WINDOWS)
#if defined(HAVE_WINDOWS_CONSOLE_IO)
PyDoc_STRVAR(_io__WindowsConsoleIO_read__doc__,
"read($self, size=-1, /)\n"
@ -305,9 +305,9 @@ exit:
return return_value;
}
#endif /* defined(MS_WINDOWS) */
#endif /* defined(HAVE_WINDOWS_CONSOLE_IO) */
#if defined(MS_WINDOWS)
#if defined(HAVE_WINDOWS_CONSOLE_IO)
PyDoc_STRVAR(_io__WindowsConsoleIO_write__doc__,
"write($self, b, /)\n"
@ -348,9 +348,9 @@ exit:
return return_value;
}
#endif /* defined(MS_WINDOWS) */
#endif /* defined(HAVE_WINDOWS_CONSOLE_IO) */
#if defined(MS_WINDOWS)
#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) */
#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=4920e9068e0cf08a input=a9049054013a1b77]*/
/*[clinic end generated code: output=163e934aa9b0ef16 input=a9049054013a1b77]*/

View file

@ -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 <windows.h>
#endif

View file

@ -11,7 +11,7 @@
#include "pycore_fileutils.h" // _Py_BEGIN_SUPPRESS_IPH
#include "pycore_object.h" // _PyObject_GC_UNTRACK()
#ifdef MS_WINDOWS
#ifdef HAVE_WINDOWS_CONSOLE_IO
#include "structmember.h" // PyMemberDef
#ifdef HAVE_SYS_TYPES_H
@ -22,7 +22,9 @@
#endif
#include <stddef.h> /* For offsetof */
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#include <windows.h>
#include <fcntl.h>
@ -1177,4 +1179,4 @@ PyTypeObject PyWindowsConsoleIO_Type = {
0, /* tp_finalize */
};
#endif /* MS_WINDOWS */
#endif /* HAVE_WINDOWS_CONSOLE_IO */

View file

@ -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 <windows.h>
#endif
@ -457,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);
@ -474,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);
}

View file

@ -12,7 +12,9 @@
*/
#ifdef MS_WINDOWS
# define WIN32_LEAN_AND_MEAN
# ifndef WIN32_LEAN_AND_MEAN
# define WIN32_LEAN_AND_MEAN
# endif
# include <windows.h>
# include <winsock2.h>
# include <process.h> /* getpid() */

View file

@ -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.

View file

@ -77,6 +77,10 @@
# include <process.h> // getpid()
#endif
#ifdef MS_WINDOWS
# include <windows.h>
#endif
/* Period parameters -- These are all magic. Don't change. */
#define N 624
#define M 397
@ -259,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) && !defined(MS_WINDOWS_SYSTEM)
key[2] = (uint32_t)GetCurrentProcessId();
#elif defined(HAVE_GETPID)
key[2] = (uint32_t)getpid();

View file

@ -28,6 +28,10 @@
/* Include symbols from _socket module */
#include "socketmodule.h"
#ifdef MS_WINDOWS
# include <wincrypt.h>
#endif
#include "_ssl.h"
/* Redefined below for Windows debug builds after important #includes */

View file

@ -39,8 +39,11 @@
#include "structmember.h" // PyMemberDef
#ifndef WINDOWS_LEAN_AND_MEAN
#define WINDOWS_LEAN_AND_MEAN
#endif
#include "windows.h"
#include <winioctl.h>
#include <crtdbg.h>
#include "winreparse.h"
@ -63,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;
@ -1201,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

View file

@ -10988,7 +10988,7 @@ exit:
#endif /* defined(HAVE_GETRANDOM_SYSCALL) */
#if defined(MS_WINDOWS)
#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 @@ exit:
return return_value;
}
#endif /* defined(MS_WINDOWS) */
#endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM)) */
#if defined(MS_WINDOWS)
#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 @@ exit:
return return_value;
}
#endif /* defined(MS_WINDOWS) */
#endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM)) */
#if (defined(WIFEXITED) || defined(MS_WINDOWS))
@ -11796,4 +11796,4 @@ exit:
#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=9495478e51701b8a input=a9049054013a1b77]*/

View file

@ -5,7 +5,9 @@
/* Windows socket errors (WSA*) */
#ifdef MS_WINDOWS
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#include <windows.h>
/* The following constants were added to errno.h in VS2010 but have
preferred WSA equivalents. */

View file

@ -953,7 +953,7 @@ faulthandler_unregister_py(PyObject *self, PyObject *args)
static void
faulthandler_suppress_crash_report(void)
{
#ifdef MS_WINDOWS
#ifdef MS_WINDOWS_DESKTOP
UINT mode;
/* Configure Windows to not display the Windows Error Reporting dialog */

View file

@ -745,10 +745,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;

View file

@ -29,6 +29,10 @@
#include "structmember.h" // PyMemberDef
#include <stddef.h> // 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
#define UNIX
# ifdef HAVE_FCNTL_H
@ -647,7 +651,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_DESKTOP) || defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM)
if (!FlushViewOfFile(self->data+offset, size)) {
PyErr_SetFromWindowsErr(GetLastError());
return NULL;
@ -1724,3 +1728,5 @@ PyInit_mmap(void)
{
return PyModuleDef_Init(&mmapmodule);
}
#endif /* !MS_WINDOWS || MS_WINDOWS_DESKTOP || MS_WINDOWS_GAMES */

View file

@ -26,11 +26,15 @@
#ifdef MS_WINDOWS
# include <windows.h>
# include <pathcch.h>
# if !defined(MS_WINDOWS_GAMES) || defined(MS_WINDOWS_DESKTOP)
# include <pathcch.h>
# endif
# include <winioctl.h>
# include <lmcons.h> // UNLEN
# include "osdefs.h" // SEP
# define HAVE_SYMLINK
# if defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM)
# define HAVE_SYMLINK
# endif /* MS_WINDOWS_DESKTOP | MS_WINDOWS_SYSTEM */
#endif
#include "structmember.h" // PyMemberDef
@ -311,7 +315,7 @@ corresponding Unix manual entries for more information on calls.");
# include <sys/syscall.h>
#endif
#if defined(MS_WINDOWS)
#ifdef HAVE_WINDOWS_CONSOLE_IO
# define TERMSIZE_USE_CONIO
#elif defined(HAVE_SYS_IOCTL_H)
# include <sys/ioctl.h>
@ -321,7 +325,7 @@ corresponding Unix manual entries for more information on calls.");
# if defined(TIOCGWINSZ)
# define TERMSIZE_USE_IOCTL
# endif
#endif /* MS_WINDOWS */
#endif /* HAVE_WINDOWS_CONSOLE_IO */
/* Various compilers have only certain posix functions */
/* XXX Gosh I wish these were all moved into pyconfig.h */
@ -329,21 +333,25 @@ corresponding Unix manual entries for more information on calls.");
# define HAVE_OPENDIR 1
# define HAVE_SYSTEM 1
# include <process.h>
#else
# ifdef _MSC_VER
/* Microsoft compiler */
#elif defined( _MSC_VER)
/* Microsoft compiler */
# 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_PIPE 1
# define HAVE_SYSTEM 1
# define HAVE_CWAIT 1
# define HAVE_FSYNC 1
# define fsync _commit
# endif /* _MSC_VER */
# endif /* MS_WINDOWS_DESKTOP | MS_WINDOWS_SYSTEM */
# define HAVE_PIPE 1
# define HAVE_FSYNC 1
# define fsync _commit
#endif /* ! __WATCOMC__ || __QNX__ */
/*[clinic input]
@ -1536,7 +1544,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
@ -1785,6 +1793,10 @@ 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) {
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
return FALSE;
}
wcsncpy_s((LPWSTR)filename, n + 1, pszFile, n);
while (--n > 0 && (filename[n] == L'\\' || filename[n] == L'/')) {
((LPWSTR)filename)[n] = L'\0';
@ -7933,10 +7945,10 @@ static PyObject *
os_getpid_impl(PyObject *module)
/*[clinic end generated code: output=9ea6fdac01ed2b3c input=5a9a00f0ab68aa00]*/
{
#ifdef MS_WINDOWS_NON_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) */
@ -8392,6 +8404,7 @@ os_kill_impl(PyObject *module, pid_t pid, Py_ssize_t signal)
DWORD err;
HANDLE handle;
#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) {
@ -8399,9 +8412,11 @@ os_kill_impl(PyObject *module, pid_t pid, Py_ssize_t signal)
err = GetLastError();
PyErr_SetFromWindowsErr(err);
}
else
else {
Py_RETURN_NONE;
}
}
#endif /* HAVE_WINDOWS_CONSOLE_IO */
/* If the signal is outside of what GenerateConsoleCtrlEvent can use,
attempt to open and terminate the process. */
@ -13776,7 +13791,9 @@ os_cpu_count_impl(PyObject *module)
{
int ncpu = 0;
#ifdef MS_WINDOWS
#ifdef MS_WINDOWS_DESKTOP
ncpu = GetActiveProcessorCount(ALL_PROCESSOR_GROUPS);
#endif
#elif defined(__hpux)
ncpu = mpctl(MPC_GETNUMSPUS, NULL, NULL);
#elif defined(HAVE_SYSCONF) && defined(_SC_NPROCESSORS_ONLN)
@ -13848,6 +13865,10 @@ os_set_inheritable_impl(PyObject *module, int fd, int inheritable)
#ifdef MS_WINDOWS
#ifndef HANDLE_FLAG_INHERIT
#define HANDLE_FLAG_INHERIT 0x00000001
#endif
/*[clinic input]
os.get_handle_inheritable -> bool
handle: intptr_t
@ -15023,7 +15044,8 @@ error:
}
#endif /* HAVE_GETRANDOM_SYSCALL */
#ifdef MS_WINDOWS
#if defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM)
/* bpo-36085: Helper functions for managing DLL search directories
* on win32
*/
@ -15114,7 +15136,7 @@ os__remove_dll_directory_impl(PyObject *module, PyObject *cookie)
Py_RETURN_NONE;
}
#endif
#endif /* MS_WINDOWS_APP || MS_WINDOWS_SYSTEM */
/* Only check if WIFEXITED is available: expect that it comes

View file

@ -57,8 +57,10 @@ extern void bzero(void *, int);
#endif
#ifdef MS_WINDOWS
# define WIN32_LEAN_AND_MEAN
# include <winsock.h>
# ifndef WIN32_LEAN_AND_MEAN
# define WIN32_LEAN_AND_MEAN
# endif
# include <winsock2.h>
#else
# define SOCKET int
#endif

View file

@ -270,7 +270,7 @@ shutdown(how) -- shut down traffic in one or both directions\n\
# include <fcntl.h>
#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 <Rpc.h>
/* 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 <versionhelpers.h>
@ -348,13 +346,18 @@ remove_unusable_flags(PyObject *m)
{
PyObject *dict;
OSVERSIONINFOEX info;
DWORDLONG dwlConditionMask;
dict = PyModule_GetDict(m);
if (dict == NULL) {
return -1;
}
#ifndef MS_WINDOWS_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 +365,30 @@ 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<sizeof(win_runtime_flags)/sizeof(FlagRuntimeInfo); i++) {
#ifdef MS_WINDOWS_DESKTOP
info.dwBuildNumber = win_runtime_flags[i].build_number;
/* greater than or equal to the specified version?
Compatibility Mode will not cheat VerifyVersionInfo(...) */
if (VerifyVersionInfo(
&info,
VER_MAJORVERSION|VER_MINORVERSION|VER_BUILDNUMBER,
dwlConditionMask)) {
BOOL isSupported = VerifyVersionInfo(
&info,
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 &&
info.dwBuildNumber >= win_runtime_flags[i].build_number);
#endif
if (isSupported) {
break;
}
else {
@ -497,14 +511,14 @@ remove_unusable_flags(PyObject *m)
#endif
#endif
#ifdef MS_WINDOWS
#ifdef MS_WINDOWS_DESKTOP
#define sockaddr_rc SOCKADDR_BTH_REDEF
#define USE_BLUETOOTH 1
#define AF_BLUETOOTH AF_BTH
#define BTPROTO_RFCOMM BTHPROTO_RFCOMM
#define _BT_RC_MEMB(sa, memb) ((sa)->memb)
#endif
#endif /* MS_WINDOWS_DESKTOP */
/* Convert "sock_addr_t *" to "struct sockaddr *". */
#define SAS2SA(x) (&((x)->sa))
@ -2869,11 +2883,16 @@ sock_accept(PySocketSockObject *s, PyObject *Py_UNUSED(ignored))
newfd = ctx.result;
#ifdef MS_WINDOWS
#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);
goto finally;
}
#endif
#else
#if defined(HAVE_ACCEPT4) && defined(SOCK_CLOEXEC)
@ -5434,11 +5453,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,
@ -6150,8 +6164,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))
@ -6160,8 +6175,9 @@ 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)
if (newfd == INVALID_SOCKET) {
return set_error();
}
if (!SetHandleInformation((HANDLE)newfd, HANDLE_FLAG_INHERIT, 0)) {
closesocket(newfd);
@ -6171,13 +6187,15 @@ socket_dup(PyObject *self, PyObject *fdobj)
#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;
}

View file

@ -30,7 +30,9 @@
# include <i86.h>
#else
# ifdef MS_WINDOWS
# define WIN32_LEAN_AND_MEAN
# ifndef WIN32_LEAN_AND_MEAN
# define WIN32_LEAN_AND_MEAN
# endif
# include <windows.h>
# endif /* MS_WINDOWS */
#endif /* !__WATCOMC__ || __QNX__ */
@ -1135,7 +1137,9 @@ time_tzset(PyObject *self, PyObject *unused)
return NULL;
}
#if !defined(MS_WINDOWS) || defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM)
tzset();
#endif
/* Reset timezone, altzone, daylight and tzname */
if (init_timezone(m) < 0) {
@ -1753,7 +1757,9 @@ init_timezone(PyObject *m)
*/
#ifdef HAVE_DECL_TZNAME
PyObject *otz0, *otz1;
#if !defined(MS_WINDOWS) || defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_SYSTEM)
tzset();
#endif
PyModule_AddIntConstant(m, "timezone", _Py_timezone);
#ifdef HAVE_ALTZONE
PyModule_AddIntConstant(m, "altzone", altzone);