diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b98514aaf94522..0c972f02f8ade3 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -60,7 +60,7 @@ jobs: if: needs.check_source.outputs.run_tests == 'true' steps: - uses: actions/checkout@v2 - - uses: actions/setup-python@v2 + - uses: actions/setup-python@v4 - name: Install Dependencies run: | sudo ./.github/workflows/posix-deps-apt.sh @@ -91,7 +91,7 @@ jobs: if: needs.check_source.outputs.run_tests == 'true' steps: - uses: actions/checkout@v3 - - uses: actions/setup-python@v3 + - uses: actions/setup-python@v4 - name: Install Dependencies run: sudo ./.github/workflows/posix-deps-apt.sh - name: Add ccache to PATH diff --git a/Include/cpython/fileutils.h b/Include/cpython/fileutils.h index ccf37e9468d615..ff840263fe9ffd 100644 --- a/Include/cpython/fileutils.h +++ b/Include/cpython/fileutils.h @@ -135,9 +135,7 @@ PyAPI_FUNC(wchar_t*) _Py_wrealpath( size_t resolved_path_len); #endif -#ifndef MS_WINDOWS PyAPI_FUNC(int) _Py_isabs(const wchar_t *path); -#endif PyAPI_FUNC(int) _Py_abspath(const wchar_t *path, wchar_t **abspath_p); diff --git a/Lib/distutils/ccompiler.py b/Lib/distutils/ccompiler.py index 4c47f2ed245d4f..1ddf382280afef 100644 --- a/Lib/distutils/ccompiler.py +++ b/Lib/distutils/ccompiler.py @@ -876,9 +876,9 @@ def executable_filename(self, basename, strip_dir=0, output_dir=''): def library_filename(self, libname, lib_type='static', # or 'shared' strip_dir=0, output_dir=''): assert output_dir is not None - if lib_type not in ("static", "shared", "dylib", "xcode_stub"): + if lib_type not in ("static", "shared", "dll", "dylib", "xcode_stub"): raise ValueError( - "'lib_type' must be \"static\", \"shared\", \"dylib\", or \"xcode_stub\"") + "'lib_type' must be \"static\", \"shared\", \"dll\", \"dylib\", or \"xcode_stub\"") fmt = getattr(self, lib_type + "_lib_format") ext = getattr(self, lib_type + "_lib_extension") diff --git a/Lib/distutils/unixccompiler.py b/Lib/distutils/unixccompiler.py index d00c48981eb6d6..ebea9129e86207 100644 --- a/Lib/distutils/unixccompiler.py +++ b/Lib/distutils/unixccompiler.py @@ -75,9 +75,10 @@ class UnixCCompiler(CCompiler): obj_extension = ".o" static_lib_extension = ".a" shared_lib_extension = ".so" + dll_lib_extension = ".dll.a" dylib_lib_extension = ".dylib" xcode_stub_lib_extension = ".tbd" - static_lib_format = shared_lib_format = dylib_lib_format = "lib%s%s" + static_lib_format = shared_lib_format = dll_lib_format = dylib_lib_format = "lib%s%s" xcode_stub_lib_format = dylib_lib_format if sys.platform == "cygwin": exe_extension = ".exe" @@ -265,6 +266,7 @@ def library_option(self, lib): def find_library_file(self, dirs, lib, debug=0): shared_f = self.library_filename(lib, lib_type='shared') + dll_f = self.library_filename(lib, lib_type='dll') dylib_f = self.library_filename(lib, lib_type='dylib') xcode_stub_f = self.library_filename(lib, lib_type='xcode_stub') static_f = self.library_filename(lib, lib_type='static') @@ -299,6 +301,7 @@ def find_library_file(self, dirs, lib, debug=0): for dir in dirs: shared = os.path.join(dir, shared_f) + dll = os.path.join(dir, dll_f) dylib = os.path.join(dir, dylib_f) static = os.path.join(dir, static_f) xcode_stub = os.path.join(dir, xcode_stub_f) @@ -316,7 +319,9 @@ def find_library_file(self, dirs, lib, debug=0): # data to go on: GCC seems to prefer the shared library, so I'm # assuming that *all* Unix C compilers do. And of course I'm # ignoring even GCC's "-static" option. So sue me. - if os.path.exists(dylib): + if os.path.exists(dll): + return dll + elif os.path.exists(dylib): return dylib elif os.path.exists(xcode_stub): return xcode_stub diff --git a/Lib/os.py b/Lib/os.py index d26cfc99939f39..5d5373a430cc28 100644 --- a/Lib/os.py +++ b/Lib/os.py @@ -682,12 +682,18 @@ def __getitem__(self, key): def __setitem__(self, key, value): key = self.encodekey(key) value = self.encodevalue(value) - putenv(key, value) + if sys.platform.startswith('win'): + putenv(str(key), str(value)) + else: + putenv(key, value) self._data[key] = value def __delitem__(self, key): encodedkey = self.encodekey(key) - unsetenv(encodedkey) + if sys.platform.startswith('win'): + unsetenv(str(encodedkey)) + else: + unsetenv(encodedkey) try: del self._data[encodedkey] except KeyError: diff --git a/Lib/posixpath.py b/Lib/posixpath.py index 195374613a779f..d68d2c8bca5be0 100644 --- a/Lib/posixpath.py +++ b/Lib/posixpath.py @@ -243,11 +243,13 @@ def expanduser(path): if 'HOME' not in os.environ: import pwd try: - userhome = pwd.getpwuid(os.getuid()).pw_dir + if not sys.platform.startswith('win'): + userhome = pwd.getpwuid(os.getuid()).pw_dir except KeyError: # bpo-10496: if the current user identifier doesn't exist in the # password database, return the path unchanged return path + return path else: userhome = os.environ['HOME'] else: diff --git a/Lib/site.py b/Lib/site.py index 939893eb5ee93b..907cba1fec3f38 100644 --- a/Lib/site.py +++ b/Lib/site.py @@ -288,10 +288,6 @@ def joinuser(*args): def _get_path(userbase): version = sys.version_info - if os.name == 'nt': - ver_nodot = sys.winver.replace('.', '') - return f'{userbase}\\Python{ver_nodot}\\site-packages' - if sys.platform == 'darwin' and sys._framework: return f'{userbase}/lib/python/site-packages' @@ -365,18 +361,11 @@ def getsitepackages(prefixes=None): if sys.platlibdir != "lib": libdirs.append("lib") - if os.sep == '/': - for libdir in libdirs: - path = os.path.join(prefix, libdir, - "python%d.%d" % sys.version_info[:2], - "site-packages") - sitepackages.append(path) - else: - sitepackages.append(prefix) - - for libdir in libdirs: - path = os.path.join(prefix, libdir, "site-packages") - sitepackages.append(path) + for libdir in libdirs: + path = os.path.join(prefix, libdir, + "python%d.%d" % sys.version_info[:2], + "site-packages") + sitepackages.append(path) return sitepackages def addsitepackages(known_paths, prefixes=None): diff --git a/Mac/Makefile.in b/Mac/Makefile.in index f9691288414538..4b48462ac809ab 100644 --- a/Mac/Makefile.in +++ b/Mac/Makefile.in @@ -13,7 +13,7 @@ exec_prefix=@exec_prefix@ LIBDEST=$(prefix)/lib/python$(VERSION) RUNSHARED=@RUNSHARED@ BUILDEXE=@BUILDEXEEXT@ -BUILDPYTHON=$(builddir)/python$(BUILDEXE) +BUILDPYTHON=python$(BUILDEXE) DESTDIR= LDFLAGS=@LDFLAGS@ FRAMEWORKUNIXTOOLSPREFIX=@FRAMEWORKUNIXTOOLSPREFIX@ @@ -226,7 +226,7 @@ install_Python: esac; \ done; \ done - $(INSTALL_PROGRAM) $(STRIPFLAG) $(BUILDPYTHON) "$(DESTDIR)$(APPINSTALLDIR)/Contents/MacOS/$(PYTHONFRAMEWORK)" + $(INSTALL_PROGRAM) $(STRIPFLAG) $(builddir)/$(BUILDPYTHON) "$(DESTDIR)$(APPINSTALLDIR)/Contents/MacOS/$(PYTHONFRAMEWORK)" sed -e "s!%bundleid%!$(PYTHONFRAMEWORKIDENTIFIER)!g" \ -e "s!%version%!`$(RUNSHARED) $(BUILDPYTHON) \ -c 'import platform; print(platform.python_version())'`!g" \ diff --git a/Mac/PythonLauncher/Makefile.in b/Mac/PythonLauncher/Makefile.in index 4c05f26e8358bc..7a3e1ea61acaec 100644 --- a/Mac/PythonLauncher/Makefile.in +++ b/Mac/PythonLauncher/Makefile.in @@ -11,7 +11,7 @@ builddir= ../.. RUNSHARED= @RUNSHARED@ BUILDEXE= @BUILDEXEEXT@ -BUILDPYTHON= $(builddir)/python$(BUILDEXE) +BUILDPYTHON= python$(BUILDEXE) PYTHONFRAMEWORK=@PYTHONFRAMEWORK@ # Deployment target selected during configure, to be checked diff --git a/Makefile.pre.in b/Makefile.pre.in index ee85f35b10da41..8d55d4c2b96b08 100644 --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -302,7 +302,8 @@ IO_OBJS= \ Modules/_io/bufferedio.o \ Modules/_io/textio.o \ Modules/_io/bytesio.o \ - Modules/_io/stringio.o + Modules/_io/stringio.o \ + Modules/_io/winconsoleio.o ########################################################################## @@ -456,7 +457,9 @@ LIBRARY_OBJS_OMIT_FROZEN= \ LIBRARY_OBJS= \ $(LIBRARY_OBJS_OMIT_FROZEN) \ - Python/frozen.o + Python/frozen.o \ + PC/frozen_dllmain.o \ + PC/dl_nt.o ########################################################################## # DTrace @@ -626,10 +629,10 @@ sharedmods: $(BUILDPYTHON) pybuilddir.txt Modules/_math.o *\ -s*|s*) quiet="-q";; \ *) quiet="";; \ esac; \ - echo "$(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)' \ + echo "$(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED) $(LIBPYTHON)' OPT='$(OPT)' \ _TCLTK_INCLUDES='$(TCLTK_INCLUDES)' _TCLTK_LIBS='$(TCLTK_LIBS)' \ $(PYTHON_FOR_BUILD) $(srcdir)/setup.py $$quiet build"; \ - $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)' \ + $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED) $(LIBPYTHON)' OPT='$(OPT)' \ _TCLTK_INCLUDES='$(TCLTK_INCLUDES)' _TCLTK_LIBS='$(TCLTK_LIBS)' \ $(PYTHON_FOR_BUILD) $(srcdir)/setup.py $$quiet build @@ -823,6 +826,11 @@ Python/dynload_hpux.o: $(srcdir)/Python/dynload_hpux.c Makefile -DSHLIB_EXT='"$(EXT_SUFFIX)"' \ -o $@ $(srcdir)/Python/dynload_hpux.c +Python/dynload_win.o: $(srcdir)/Python/dynload_win.c Makefile + $(CC) -c $(PY_CORE_CFLAGS) \ + -DSOABI='"$(SOABI)"' \ + -o $@ $(srcdir)/Python/dynload_win.c + Python/sysmodule.o: $(srcdir)/Python/sysmodule.c Makefile $(srcdir)/Include/pydtrace.h $(CC) -c $(PY_CORE_CFLAGS) \ -DABIFLAGS='"$(ABIFLAGS)"' \ @@ -1284,10 +1292,10 @@ altinstall: commoninstall $$ensurepip --root=$(DESTDIR)/ ; \ fi -commoninstall: check-clean-src @FRAMEWORKALTINSTALLFIRST@ \ +commoninstall: check-clean-src @FRAMEWORKINSTALLFIRST@ \ altbininstall libinstall inclinstall libainstall \ sharedinstall oldsharedinstall altmaninstall \ - @FRAMEWORKALTINSTALLLAST@ + @FRAMEWORKINSTALLLAST@ # Install shared libraries enabled by Setup DESTDIRS= $(exec_prefix) $(LIBDIR) $(BINLIBDEST) $(DESTSHARED) diff --git a/Modules/Setup b/Modules/Setup index 87c6a152f86eac..f3ab5b407105ea 100644 --- a/Modules/Setup +++ b/Modules/Setup @@ -101,7 +101,7 @@ PYTHONPATH=$(COREPYTHONPATH) # This only contains the minimal set of modules required to run the # setup.py script in the root of the Python source tree. -posix -DPy_BUILD_CORE_BUILTIN -I$(srcdir)/Include/internal posixmodule.c # posix (UNIX) system calls +# posix -DPy_BUILD_CORE_BUILTIN -I$(srcdir)/Include/internal posixmodule.c # posix (UNIX) system calls errno errnomodule.c # posix (UNIX) errno values pwd pwdmodule.c # this is needed to find out the user's home dir # if $HOME is not set @@ -123,7 +123,7 @@ _thread -DPy_BUILD_CORE_BUILTIN -I$(srcdir)/Include/internal _threadmodule.c # l _locale -DPy_BUILD_CORE_BUILTIN _localemodule.c # -lintl # Standard I/O baseline -_io -DPy_BUILD_CORE_BUILTIN -I$(srcdir)/Include/internal -I$(srcdir)/Modules/_io _io/_iomodule.c _io/iobase.c _io/fileio.c _io/bytesio.c _io/bufferedio.c _io/textio.c _io/stringio.c +_io -DPy_BUILD_CORE_BUILTIN -I$(srcdir)/Include/internal -I$(srcdir)/Modules/_io _io/_iomodule.c _io/iobase.c _io/fileio.c _io/bytesio.c _io/bufferedio.c _io/textio.c _io/stringio.c _io/winconsoleio.c # faulthandler module faulthandler faulthandler.c diff --git a/Modules/_ctypes/_ctypes.c b/Modules/_ctypes/_ctypes.c index 84378c40357b07..40fd6555d4df69 100644 --- a/Modules/_ctypes/_ctypes.c +++ b/Modules/_ctypes/_ctypes.c @@ -105,7 +105,7 @@ bytes(cdata) #include "structmember.h" // PyMemberDef #include -#ifdef MS_WIN32 +#ifdef MS_WINDOWS #include #include #ifndef IS_INTRESOURCE @@ -129,7 +129,7 @@ static PyTypeObject Simple_Type; strong reference to _ctypes._unpickle() function */ static PyObject *_unpickle; -#ifdef MS_WIN32 +#ifdef MS_WINDOWS PyObject *ComError; // Borrowed reference to: &PyComError_Type #endif @@ -754,7 +754,7 @@ CDataType_in_dll(PyObject *type, PyObject *args) return NULL; } -#ifdef MS_WIN32 +#ifdef MS_WINDOWS Py_BEGIN_ALLOW_THREADS address = (void *)GetProcAddress(handle, name); Py_END_ALLOW_THREADS @@ -3365,7 +3365,7 @@ static PyGetSetDef PyCFuncPtr_getsets[] = { { NULL, NULL } }; -#ifdef MS_WIN32 +#ifdef MS_WINDOWS static PPROC FindAddress(void *handle, const char *name, PyObject *type) { PPROC address; @@ -3515,7 +3515,7 @@ _validate_paramflags(PyTypeObject *type, PyObject *paramflags) static int _get_name(PyObject *obj, const char **pname) { -#ifdef MS_WIN32 +#ifdef MS_WINDOWS if (PyLong_Check(obj)) { /* We have to use MAKEINTRESOURCEA for Windows CE. Works on Windows as well, of course. @@ -3567,7 +3567,7 @@ PyCFuncPtr_FromDll(PyTypeObject *type, PyObject *args, PyObject *kwds) return NULL; } -#ifdef MS_WIN32 +#ifdef MS_WINDOWS if (PySys_Audit("ctypes.dlsym", ((uintptr_t)name & ~0xFFFF) ? "Os" : "On", dll, name) < 0) { @@ -3602,7 +3602,7 @@ PyCFuncPtr_FromDll(PyTypeObject *type, PyObject *args, PyObject *kwds) return NULL; } -#ifdef MS_WIN32 +#ifdef MS_WINDOWS address = FindAddress(handle, name, (PyObject *)type); if (!address) { if (!IS_INTRESOURCE(name)) @@ -3658,7 +3658,7 @@ PyCFuncPtr_FromDll(PyTypeObject *type, PyObject *args, PyObject *kwds) return (PyObject *)self; } -#ifdef MS_WIN32 +#ifdef MS_WINDOWS static PyObject * PyCFuncPtr_FromVtblIndex(PyTypeObject *type, PyObject *args, PyObject *kwds) { @@ -3714,7 +3714,7 @@ PyCFuncPtr_new(PyTypeObject *type, PyObject *args, PyObject *kwds) if (1 <= PyTuple_GET_SIZE(args) && PyTuple_Check(PyTuple_GET_ITEM(args, 0))) return PyCFuncPtr_FromDll(type, args, kwds); -#ifdef MS_WIN32 +#ifdef MS_WINDOWS if (2 <= PyTuple_GET_SIZE(args) && PyLong_Check(PyTuple_GET_ITEM(args, 0))) return PyCFuncPtr_FromVtblIndex(type, args, kwds); #endif @@ -3894,7 +3894,7 @@ _build_callargs(PyCFuncPtrObject *self, PyObject *argtypes, /* Trivial cases, where we either return inargs itself, or a slice of it. */ if (argtypes == NULL || paramflags == NULL || PyTuple_GET_SIZE(argtypes) == 0) { -#ifdef MS_WIN32 +#ifdef MS_WINDOWS if (self->index) return PyTuple_GetSlice(inargs, 1, PyTuple_GET_SIZE(inargs)); #endif @@ -3907,7 +3907,7 @@ _build_callargs(PyCFuncPtrObject *self, PyObject *argtypes, if (callargs == NULL) return NULL; -#ifdef MS_WIN32 +#ifdef MS_WINDOWS /* For a COM method, skip the first arg */ if (self->index) { inargs_index = 1; @@ -4112,7 +4112,7 @@ PyCFuncPtr_call(PyCFuncPtrObject *self, PyObject *inargs, PyObject *kwds) PyObject *result; PyObject *callargs; PyObject *errcheck; -#ifdef MS_WIN32 +#ifdef MS_WINDOWS IUnknown *piunk = NULL; #endif void *pProc = NULL; @@ -4131,7 +4131,7 @@ PyCFuncPtr_call(PyCFuncPtrObject *self, PyObject *inargs, PyObject *kwds) pProc = *(void **)self->b_ptr; -#ifdef MS_WIN32 +#ifdef MS_WINDOWS if (self->index) { /* It's a COM method */ CDataObject *this; @@ -4200,7 +4200,7 @@ PyCFuncPtr_call(PyCFuncPtrObject *self, PyObject *inargs, PyObject *kwds) result = _ctypes_callproc(pProc, callargs, -#ifdef MS_WIN32 +#ifdef MS_WINDOWS piunk, self->iid, #endif @@ -4271,7 +4271,7 @@ PyCFuncPtr_dealloc(PyCFuncPtrObject *self) static PyObject * PyCFuncPtr_repr(PyCFuncPtrObject *self) { -#ifdef MS_WIN32 +#ifdef MS_WINDOWS if (self->index) return PyUnicode_FromFormat("", self->index - 0x1000, @@ -4287,7 +4287,7 @@ static int PyCFuncPtr_bool(PyCFuncPtrObject *self) { return ((*(void **)self->b_ptr != NULL) -#ifdef MS_WIN32 +#ifdef MS_WINDOWS || (self->index != 0) #endif ); @@ -5472,7 +5472,7 @@ PyTypeObject PyCPointer_Type = { PyDoc_STRVAR(_ctypes__doc__, "Create and manipulate C compatible data types in Python."); -#ifdef MS_WIN32 +#ifdef MS_WINDOWS PyDoc_STRVAR(comerror_doc, "Raised when a COM method call failed."); @@ -5552,7 +5552,7 @@ static PyTypeObject PyComError_Type = { 0, /* tp_alloc */ 0, /* tp_new */ }; -#endif // MS_WIN32 +#endif // MS_WINDOWS static PyObject * string_at(const char *ptr, int size) @@ -5744,7 +5744,7 @@ _ctypes_add_types(PyObject *mod) TYPE_READY(&DictRemover_Type); TYPE_READY(&StructParam_Type); -#ifdef MS_WIN32 +#ifdef MS_WINDOWS TYPE_READY_BASE(&PyComError_Type, (PyTypeObject*)PyExc_Exception); #endif @@ -5773,7 +5773,7 @@ _ctypes_add_objects(PyObject *mod) MOD_ADD("_pointer_type_cache", Py_NewRef(_ctypes_ptrtype_cache)); -#ifdef MS_WIN32 +#ifdef MS_WINDOWS MOD_ADD("COMError", Py_NewRef(ComError)); MOD_ADD("FUNCFLAG_HRESULT", PyLong_FromLong(FUNCFLAG_HRESULT)); MOD_ADD("FUNCFLAG_STDCALL", PyLong_FromLong(FUNCFLAG_STDCALL)); @@ -5829,7 +5829,7 @@ _ctypes_mod_exec(PyObject *mod) if (_ctypes_add_types(mod) < 0) { return -1; } -#ifdef MS_WIN32 +#ifdef MS_WINDOWS ComError = (PyObject*)&PyComError_Type; #endif diff --git a/Modules/_ctypes/callproc.c b/Modules/_ctypes/callproc.c index 48694760dbedf1..a95d48131f4527 100644 --- a/Modules/_ctypes/callproc.c +++ b/Modules/_ctypes/callproc.c @@ -59,7 +59,7 @@ #include -#ifdef MS_WIN32 +#ifdef MS_WINDOWS #include #include #else @@ -70,7 +70,7 @@ #include #endif -#ifdef MS_WIN32 +#ifdef MS_WINDOWS #include #endif @@ -234,7 +234,7 @@ set_errno(PyObject *self, PyObject *args) return set_error_internal(self, args, 0); } -#ifdef MS_WIN32 +#ifdef MS_WINDOWS static PyObject * get_last_error(PyObject *self, PyObject *args) @@ -737,7 +737,7 @@ static int ConvParam(PyObject *obj, Py_ssize_t index, struct argument *pa) } } -#if defined(MS_WIN32) && !defined(_WIN32_WCE) +#if defined(MS_WINDOWS) && !defined(_WIN32_WCE) /* Per: https://msdn.microsoft.com/en-us/library/7572ztz4.aspx To be returned by value in RAX, user-defined types must have a length @@ -768,7 +768,7 @@ ffi_type *_ctypes_get_ffi_type(PyObject *obj) dict = PyType_stgdict(obj); if (dict == NULL) return &ffi_type_sint; -#if defined(MS_WIN32) && !defined(_WIN32_WCE) +#if defined(MS_WINDOWS) && !defined(_WIN32_WCE) /* This little trick works correctly with MSVC. It returns small structures in registers */ @@ -809,7 +809,7 @@ static int _call_function_pointer(int flags, int *space; ffi_cif cif; int cc; -#if defined(MS_WIN32) && !defined(DONT_USE_SEH) +#if defined(MS_WINDOWS) && !defined(DONT_USE_SEH) DWORD dwExceptionCode = 0; EXCEPTION_RECORD record; #endif @@ -903,7 +903,7 @@ static int _call_function_pointer(int flags, space[0] = errno; errno = temp; } -#ifdef MS_WIN32 +#ifdef MS_WINDOWS if (flags & FUNCFLAG_USE_LASTERROR) { int temp = space[1]; space[1] = GetLastError(); @@ -914,7 +914,7 @@ static int _call_function_pointer(int flags, #endif #endif ffi_call(&cif, (void *)pProc, resmem, avalues); -#ifdef MS_WIN32 +#ifdef MS_WINDOWS #ifndef DONT_USE_SEH } __except (HandleException(GetExceptionInformation(), @@ -936,7 +936,7 @@ static int _call_function_pointer(int flags, if ((flags & FUNCFLAG_PYTHONAPI) == 0) Py_BLOCK_THREADS Py_XDECREF(error_object); -#ifdef MS_WIN32 +#ifdef MS_WINDOWS #ifndef DONT_USE_SEH if (dwExceptionCode) { SetException(dwExceptionCode, &record); @@ -1040,7 +1040,7 @@ void _ctypes_extend_error(PyObject *exc_class, const char *fmt, ...) } -#ifdef MS_WIN32 +#ifdef MS_WINDOWS static PyObject * GetComError(HRESULT errcode, GUID *riid, IUnknown *pIunk) @@ -1135,7 +1135,7 @@ GetComError(HRESULT errcode, GUID *riid, IUnknown *pIunk) */ PyObject *_ctypes_callproc(PPROC pProc, PyObject *argtuple, -#ifdef MS_WIN32 +#ifdef MS_WINDOWS IUnknown *pIunk, GUID *iid, #endif @@ -1155,7 +1155,7 @@ PyObject *_ctypes_callproc(PPROC pProc, PyObject *retval = NULL; n = argcount = PyTuple_GET_SIZE(argtuple); -#ifdef MS_WIN32 +#ifdef MS_WINDOWS /* an optional COM object this pointer */ if (pIunk) ++argcount; @@ -1175,7 +1175,7 @@ PyObject *_ctypes_callproc(PPROC pProc, } memset(args, 0, sizeof(struct argument) * argcount); argtype_count = argtypes ? PyTuple_GET_SIZE(argtypes) : 0; -#ifdef MS_WIN32 +#ifdef MS_WINDOWS if (pIunk) { args[0].ffi_type = &ffi_type_pointer; args[0].value.p = pIunk; @@ -1281,7 +1281,7 @@ PyObject *_ctypes_callproc(PPROC pProc, } #endif -#ifdef MS_WIN32 +#ifdef MS_WINDOWS if (iid && pIunk) { if (*(int *)resbuf & 0x80000000) retval = GetComError(*(HRESULT *)resbuf, iid, pIunk); @@ -1310,7 +1310,7 @@ _parse_voidp(PyObject *obj, void **address) return 1; } -#ifdef MS_WIN32 +#ifdef MS_WINDOWS PyDoc_STRVAR(format_error_doc, "FormatError([integer]) -> string\n\ @@ -1600,7 +1600,7 @@ call_function(PyObject *self, PyObject *args) result = _ctypes_callproc((PPROC)func, arguments, -#ifdef MS_WIN32 +#ifdef MS_WINDOWS NULL, NULL, #endif @@ -1635,7 +1635,7 @@ call_cdeclfunction(PyObject *self, PyObject *args) result = _ctypes_callproc((PPROC)func, arguments, -#ifdef MS_WIN32 +#ifdef MS_WINDOWS NULL, NULL, #endif @@ -2001,7 +2001,7 @@ PyMethodDef _ctypes_module_methods[] = { {"_unpickle", unpickle, METH_VARARGS }, {"buffer_info", buffer_info, METH_O, "Return buffer interface information"}, {"resize", resize, METH_VARARGS, "Resize the memory buffer of a ctypes instance"}, -#ifdef MS_WIN32 +#ifdef MS_WINDOWS {"get_last_error", get_last_error, METH_NOARGS}, {"set_last_error", set_last_error, METH_VARARGS}, {"CopyComPointer", copy_com_pointer, METH_VARARGS, copy_com_pointer_doc}, diff --git a/Modules/_ctypes/ctypes.h b/Modules/_ctypes/ctypes.h index 9600ddc7413b2e..b2039eaded4810 100644 --- a/Modules/_ctypes/ctypes.h +++ b/Modules/_ctypes/ctypes.h @@ -2,7 +2,10 @@ # include #endif -#ifndef MS_WIN32 +#ifdef MS_WINDOWS +#include +#include +#else #define max(a, b) ((a) > (b) ? (a) : (b)) #define min(a, b) ((a) < (b) ? (a) : (b)) @@ -94,7 +97,7 @@ typedef struct { PyObject *restype; PyObject *checker; PyObject *errcheck; -#ifdef MS_WIN32 +#ifdef MS_WINDOWS int index; GUID *iid; #endif @@ -269,7 +272,7 @@ typedef int(* PPROC)(void); PyObject *_ctypes_callproc(PPROC pProc, PyObject *arguments, -#ifdef MS_WIN32 +#ifdef MS_WINDOWS IUnknown *pIUnk, GUID *iid, #endif @@ -358,7 +361,7 @@ extern int _ctypes_simple_instance(PyObject *obj); extern PyObject *_ctypes_ptrtype_cache; PyObject *_ctypes_get_errobj(int **pspace); -#ifdef MS_WIN32 +#ifdef MS_WINDOWS extern PyObject *ComError; #endif diff --git a/Modules/_ctypes/ctypes_dlfcn.h b/Modules/_ctypes/ctypes_dlfcn.h index 54cdde9a4fdb02..ec1cade201ca00 100644 --- a/Modules/_ctypes/ctypes_dlfcn.h +++ b/Modules/_ctypes/ctypes_dlfcn.h @@ -5,7 +5,7 @@ extern "C" { #endif /* __cplusplus */ -#ifndef MS_WIN32 +#ifndef MS_WINDOWS #include diff --git a/Modules/_cursesmodule.c b/Modules/_cursesmodule.c index e043f747310b6d..364f46e2e59f11 100644 --- a/Modules/_cursesmodule.c +++ b/Modules/_cursesmodule.c @@ -126,6 +126,10 @@ static const char PyCursesVersion[] = "2.2"; #include #endif +#if defined(MS_WINDOWS) +#include +#endif + #if !defined(HAVE_NCURSES_H) && (defined(sgi) || defined(__sun) || defined(SCO5)) #define STRICT_SYSV_CURSES /* Don't use ncurses extensions */ typedef chtype attr_t; /* No attr_t type is available */ diff --git a/Modules/_ssl.c b/Modules/_ssl.c index f1bb39f57b2298..268821f0f033e0 100644 --- a/Modules/_ssl.c +++ b/Modules/_ssl.c @@ -5312,7 +5312,7 @@ _ssl_nid2obj_impl(PyObject *module, int nid) return result; } -#ifdef _MSC_VER +#ifdef MS_WINDOWS static PyObject* certEncodingType(DWORD encodingType) @@ -5631,7 +5631,7 @@ _ssl_enum_crls_impl(PyObject *module, const char *store_name) } } -#endif /* _MSC_VER */ +#endif /* MS_WINDOWS */ /* List of functions exported by this module. */ static PyMethodDef PySSL_methods[] = { diff --git a/Modules/clinic/_ssl.c.h b/Modules/clinic/_ssl.c.h index b59b129af8a095..27cc4da5beaa07 100644 --- a/Modules/clinic/_ssl.c.h +++ b/Modules/clinic/_ssl.c.h @@ -1244,7 +1244,7 @@ _ssl_nid2obj(PyObject *module, PyObject *arg) return return_value; } -#if defined(_MSC_VER) +#if defined(MS_WINDOWS) PyDoc_STRVAR(_ssl_enum_certificates__doc__, "enum_certificates($module, /, store_name)\n" @@ -1296,9 +1296,9 @@ _ssl_enum_certificates(PyObject *module, PyObject *const *args, Py_ssize_t nargs return return_value; } -#endif /* defined(_MSC_VER) */ +#endif /* defined(MS_WINDOWS) */ -#if defined(_MSC_VER) +#if defined(MS_WINDOWS) PyDoc_STRVAR(_ssl_enum_crls__doc__, "enum_crls($module, /, store_name)\n" @@ -1349,7 +1349,7 @@ _ssl_enum_crls(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObje return return_value; } -#endif /* defined(_MSC_VER) */ +#endif /* defined(MS_WINDOWS) */ #ifndef _SSL_ENUM_CERTIFICATES_METHODDEF #define _SSL_ENUM_CERTIFICATES_METHODDEF diff --git a/Modules/getpath.c b/Modules/getpath.c index ef6dd59a084d8d..0989c93428a245 100644 --- a/Modules/getpath.c +++ b/Modules/getpath.c @@ -418,7 +418,11 @@ add_exe_suffix(wchar_t **progpath_p) /* Check for already have an executable suffix */ size_t n = wcslen(progpath); size_t s = wcslen(EXE_SUFFIX); +#ifndef MS_WINDOWS if (wcsncasecmp(EXE_SUFFIX, progpath + n - s, s) == 0) { +#else + if (_wcsnicmp(EXE_SUFFIX, progpath + n - s, s) == 0) { +#endif return _PyStatus_OK(); } @@ -1191,10 +1195,12 @@ calculate_argv0_path(PyCalculatePath *calculate, } #endif +#ifndef MS_WINDOWS status = resolve_symlinks(&calculate->argv0_path); if (_PyStatus_EXCEPTION(status)) { return status; } +#endif reduce(calculate->argv0_path); diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 3d74b22f7288a6..bb94d45e98ecbb 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -303,7 +303,7 @@ corresponding Unix manual entries for more information on calls."); # define HAVE_SYSTEM 1 # include #else -# ifdef _MSC_VER +# ifdef _WIN32 /* Microsoft compiler */ # define HAVE_GETPPID 1 # define HAVE_GETLOGIN 1 @@ -336,7 +336,7 @@ corresponding Unix manual entries for more information on calls."); # define HAVE_SYSTEM 1 # define HAVE_WAIT 1 # define HAVE_TTYNAME 1 -# endif /* _MSC_VER */ +# endif /* _WIN32 */ #endif /* ! __WATCOMC__ || __QNX__ */ _Py_IDENTIFIER(__fspath__); @@ -416,7 +416,7 @@ extern char *ctermid_r(char *); # endif #endif -#ifdef _MSC_VER +#ifdef _WIN32 # ifdef HAVE_DIRECT_H # include # endif @@ -438,7 +438,7 @@ extern char *ctermid_r(char *); # include // ShellExecute() # include // UNLEN # define HAVE_SYMLINK -#endif /* _MSC_VER */ +#endif /* _WIN32 */ #ifndef MAXPATHLEN # if defined(PATH_MAX) && PATH_MAX > 1024 diff --git a/Modules/pwdmodule.c b/Modules/pwdmodule.c index 14d3f9dcb1c60f..23cbdec2480490 100644 --- a/Modules/pwdmodule.c +++ b/Modules/pwdmodule.c @@ -4,7 +4,9 @@ #include "Python.h" #include "posixmodule.h" +#ifndef MS_WINDOWS #include +#endif #include "clinic/pwdmodule.c.h" /*[clinic input] @@ -84,6 +86,7 @@ mkpwent(PyObject *module, struct passwd *p) if (v == NULL) return NULL; +#ifndef MS_WINDOWS #define SETI(i,val) PyStructSequence_SET_ITEM(v, i, PyLong_FromLong((long) val)) #define SETS(i,val) sets(v, i, val) @@ -105,6 +108,7 @@ mkpwent(PyObject *module, struct passwd *p) #undef SETS #undef SETI +#endif if (PyErr_Occurred()) { Py_XDECREF(v); @@ -129,6 +133,9 @@ static PyObject * pwd_getpwuid(PyObject *module, PyObject *uidobj) /*[clinic end generated code: output=c4ee1d4d429b86c4 input=ae64d507a1c6d3e8]*/ { +#ifdef MS_WINDOWS + return NULL; +#else PyObject *retval = NULL; uid_t uid; int nomem = 0; @@ -197,6 +204,7 @@ pwd_getpwuid(PyObject *module, PyObject *uidobj) PyMem_RawFree(buf); #endif return retval; +#endif } /*[clinic input] @@ -260,7 +268,9 @@ pwd_getpwnam_impl(PyObject *module, PyObject *name) Py_END_ALLOW_THREADS #else +#ifndef MS_WINDOWS p = getpwnam(name_chars); +#endif #endif if (p == NULL) { if (nomem == 1) { diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c index 6a9ac2ceb734e8..d5718932cfc940 100644 --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -264,44 +264,11 @@ shutdown(how) -- shut down traffic in one or both directions\n\ # include # endif -/* 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 -#define IPPROTO_TCP IPPROTO_TCP -#define IPPROTO_PUP IPPROTO_PUP -#define IPPROTO_UDP IPPROTO_UDP -#define IPPROTO_IDP IPPROTO_IDP -#define IPPROTO_ND IPPROTO_ND -#define IPPROTO_RAW IPPROTO_RAW -#define IPPROTO_MAX IPPROTO_MAX -#define IPPROTO_HOPOPTS IPPROTO_HOPOPTS -#define IPPROTO_IPV4 IPPROTO_IPV4 -#define IPPROTO_IPV6 IPPROTO_IPV6 -#define IPPROTO_ROUTING IPPROTO_ROUTING -#define IPPROTO_FRAGMENT IPPROTO_FRAGMENT -#define IPPROTO_ESP IPPROTO_ESP -#define IPPROTO_AH IPPROTO_AH -#define IPPROTO_ICMPV6 IPPROTO_ICMPV6 -#define IPPROTO_NONE IPPROTO_NONE -#define IPPROTO_DSTOPTS IPPROTO_DSTOPTS -#define IPPROTO_EGP IPPROTO_EGP -#define IPPROTO_PIM IPPROTO_PIM -#define IPPROTO_ICLFXBM IPPROTO_ICLFXBM // WinSock2 only -#define IPPROTO_ST IPPROTO_ST // WinSock2 only -#define IPPROTO_CBT IPPROTO_CBT // WinSock2 only -#define IPPROTO_IGP IPPROTO_IGP // WinSock2 only -#define IPPROTO_RDP IPPROTO_RDP // WinSock2 only -#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 // For if_nametoindex() and if_indextoname() #include +#include /* remove some flags on older version Windows during run-time. https://msdn.microsoft.com/en-us/library/windows/desktop/ms738596.aspx */ diff --git a/Objects/exceptions.c b/Objects/exceptions.c index 9639b4436a078b..2041f2e7c07d50 100644 --- a/Objects/exceptions.c +++ b/Objects/exceptions.c @@ -791,7 +791,7 @@ MiddlingExtendsException(PyExc_ImportError, ModuleNotFoundError, ImportError, */ #ifdef MS_WINDOWS -#include "errmap.h" +#include "PC/errmap.h" #endif /* Where a function has a single filename, such as open() or some diff --git a/PC/dl_nt.c b/PC/dl_nt.c index 7f17ee168727f0..7a1d56cec4b3a4 100644 --- a/PC/dl_nt.c +++ b/PC/dl_nt.c @@ -8,18 +8,29 @@ forgotten) from the programmer. */ +#ifdef MS_WINDOWS + #include "Python.h" #include "windows.h" #ifdef Py_ENABLE_SHARED +#if defined(__aarch64_) +#define PY_EXT "-arm64" +#elif defined(__x86_64__) +#define PY_EXT "" +#endif + +#define _STRINGIFY(x) #x +#define STRINGIFY(x) _STRINGIFY(x) +#define MS_DLL_ID STRINGIFY(PYTHON_VERSION) STRINGIFY(PY_EXT) + // Python Globals HMODULE PyWin_DLLhModule = NULL; const char *PyWin_DLLVersionString = MS_DLL_ID; -BOOL WINAPI DllMain (HANDLE hInst, - ULONG ul_reason_for_call, - LPVOID lpReserved) +BOOL RegisterInstance(HANDLE hInst, + ULONG ul_reason_for_call) { switch (ul_reason_for_call) { @@ -33,4 +44,9 @@ BOOL WINAPI DllMain (HANDLE hInst, return TRUE; } +#undef STRINGIFY +#undef _STRINGIFY + #endif /* Py_ENABLE_SHARED */ + +#endif diff --git a/PC/errmap.h b/PC/errmap.h index a7489ab75c6561..1c98440fea889e 100644 --- a/PC/errmap.h +++ b/PC/errmap.h @@ -1,3 +1,5 @@ +#include + int winerror_to_errno(int winerror) { diff --git a/PC/frozen_dllmain.c b/PC/frozen_dllmain.c index 0156c5008bc93a..b6f84116d6264b 100644 --- a/PC/frozen_dllmain.c +++ b/PC/frozen_dllmain.c @@ -44,6 +44,8 @@ changed, here is a snippet from the pythoncom extension module. // end of example code from pythoncom's DllMain.cpp ***************************************************************************/ +#ifdef MS_WINDOWS +#include "pymacro.h" #include "windows.h" static char *possibleModules[] = { @@ -54,6 +56,8 @@ static char *possibleModules[] = { }; BOOL CallModuleDllMain(char *modName, DWORD dwReason); +BOOL RegisterInstance(HANDLE hInst, + ULONG ul_reason_for_call); /* @@ -87,7 +91,7 @@ void PyWinFreeze_ExeTerm(void) BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved) { - BOOL ret = TRUE; + BOOL ret = RegisterInstance(hInstance, dwReason); switch (dwReason) { case DLL_PROCESS_ATTACH: { @@ -131,4 +135,4 @@ BOOL CallModuleDllMain(char *modName, DWORD dwReason) } return (*pfndllmain)(hmod, dwReason, NULL); } - +#endif diff --git a/PC/getpathp.c b/PC/getpathp.c index 7c0eeab5dbab4a..307da4d0735616 100644 --- a/PC/getpathp.c +++ b/PC/getpathp.c @@ -1,4 +1,4 @@ - +#ifdef MS_WINDOWS /* Return the initial module search path. */ /* Used by DOS, Windows 3.1, Windows 95/98, Windows NT. */ @@ -1111,11 +1111,12 @@ _Py_CheckPython3(void) } python3_checked = 1; +#define STRINGIFY(x) #x /* If there is a python3.dll next to the python3y.dll, use that DLL */ if (!get_dllpath(py3path)) { reduce(py3path); - join(py3path, PY3_DLLNAME); + join(py3path, STRINGIFY(PY3_DLLNAME)); hPython3 = LoadLibraryExW(py3path, NULL, LOAD_LIBRARY_SEARCH_DEFAULT_DIRS); if (hPython3 != NULL) { return 1; @@ -1124,7 +1125,7 @@ _Py_CheckPython3(void) /* If we can locate python3.dll in our application dir, use that DLL */ - hPython3 = LoadLibraryExW(PY3_DLLNAME, NULL, LOAD_LIBRARY_SEARCH_APPLICATION_DIR); + hPython3 = LoadLibraryExW(STRINGIFY(PY3_DLLNAME), NULL, LOAD_LIBRARY_SEARCH_APPLICATION_DIR); if (hPython3 != NULL) { return 1; } @@ -1133,8 +1134,9 @@ _Py_CheckPython3(void) that has not been a normal install layout for a while */ wcscpy(py3path, Py_GetPrefix()); if (py3path[0]) { - join(py3path, L"DLLs\\" PY3_DLLNAME); + join(py3path, L"DLLs\\" STRINGIFY(PY3_DLLNAME)); hPython3 = LoadLibraryExW(py3path, NULL, LOAD_LIBRARY_SEARCH_DEFAULT_DIRS); } return hPython3 != NULL; } +#endif diff --git a/Programs/_testembed.c b/Programs/_testembed.c index 34c44120a20129..f7981dc22ea21c 100644 --- a/Programs/_testembed.c +++ b/Programs/_testembed.c @@ -1878,10 +1878,20 @@ static struct TestCase TestCases[] = { {NULL, NULL} }; +#ifdef MS_WINDOWS +int wmain(int argc, wchar_t *argv[]) +#else int main(int argc, char *argv[]) +#endif { if (argc > 1) { for (struct TestCase *tc = TestCases; tc && tc->name; tc++) { +#ifdef MS_WINDOWS + char arg[1024]; + mbstowcs(argv[1], arg, sizeof(arg)); +#else + char *arg = argv[1]; +#endif if (strcmp(argv[1], tc->name) == 0) return (*tc->func)(); } diff --git a/Python/dynload_shlib.c b/Python/dynload_shlib.c index 23828898d35a5d..81888fff009ab5 100644 --- a/Python/dynload_shlib.c +++ b/Python/dynload_shlib.c @@ -20,6 +20,22 @@ #ifdef HAVE_DLFCN_H #include +#else +static const char *dlerror() +{ + return ""; +} + +static void *dlopen(const char *path, int flags) +{ + return LoadLibrary(path); +} + +static void *dlsym(void *handle, const char *name) +{ + return GetProcAddress(handle, name); +} + #endif #if (defined(__OpenBSD__) || defined(__NetBSD__)) && !defined(__ELF__) @@ -37,7 +53,11 @@ const char *_PyImport_DynLoadFiletab[] = { #ifdef __CYGWIN__ ".dll", -#else /* !__CYGWIN__ */ +#elif defined(__APPLE__) + "." SOABI ".dylib", +#elif defined(__MINGW32__) + "." SOABI ".dll", +#else /* !__CYGWIN__ && !__APPLE__ && !__MINGW32__ */ "." SOABI ".so", #ifdef ALT_SOABI "." ALT_SOABI ".so", @@ -67,11 +87,13 @@ _PyImport_FindSharedFuncptr(const char *prefix, char pathbuf[260]; int dlopenflags=0; +#ifndef MS_WINDOWS if (strchr(pathname, '/') == NULL) { /* Prefix bare filename with "./" */ PyOS_snprintf(pathbuf, sizeof(pathbuf), "./%-.255s", pathname); pathname = pathbuf; } +#endif PyOS_snprintf(funcname, sizeof(funcname), LEAD_UNDERSCORE "%.20s_%.200s", prefix, shortname); @@ -95,7 +117,9 @@ _PyImport_FindSharedFuncptr(const char *prefix, } } +#if HAVE_DLFCN_H dlopenflags = _PyInterpreterState_GET()->dlopenflags; +#endif handle = dlopen(pathname, dlopenflags); diff --git a/Python/dynload_win.c b/Python/dynload_win.c index 5702ab2cd71ba1..b935c17085dbe5 100644 --- a/Python/dynload_win.c +++ b/Python/dynload_win.c @@ -27,6 +27,7 @@ #define PYD_UNTAGGED_SUFFIX PYD_DEBUG_SUFFIX ".pyd" const char *_PyImport_DynLoadFiletab[] = { + "." SOABI ".dll", PYD_TAGGED_SUFFIX, PYD_UNTAGGED_SUFFIX, NULL @@ -119,14 +120,14 @@ static char *GetPythonImport (HINSTANCE hModule) import_off); while (DWORD_AT(import_data)) { import_name = dllbase + DWORD_AT(import_data+12); - if (strlen(import_name) >= 6 && - !strncmp(import_name,"python",6)) { + if (strlen(import_name) >= 9 && + !strncmp(import_name,"libpython",9)) { char *pch; #ifndef _DEBUG /* In a release version, don't claim that python3.dll is a Python DLL. */ - if (strcmp(import_name, "python3.dll") == 0) { + if (strcmp(import_name, "libpython3.dll") == 0) { import_data += 20; continue; } @@ -136,11 +137,11 @@ static char *GetPythonImport (HINSTANCE hModule) by numbers to the end of the basename */ pch = import_name + 6; #ifdef _DEBUG - while (*pch && pch[0] != '_' && pch[1] != 'd' && pch[2] != '.') { + while (*pch && pch[0] != '_' && pch[1] != 'd') { #else - while (*pch && *pch != '.') { + while (*pch) { #endif - if (*pch >= '0' && *pch <= '9') { + if ((*pch >= '0' && *pch <= '9') || (*pch == '.')) { pch++; } else { pch = NULL; @@ -260,9 +261,9 @@ dl_funcptr _PyImport_FindSharedFuncptrWindows(const char *prefix, PyOS_snprintf(buffer, sizeof(buffer), #ifdef _DEBUG - "python%d%d_d.dll", + "libpython%d.%d_d.dll", #else - "python%d%d.dll", + "libpython%d.%d.dll", #endif PY_MAJOR_VERSION,PY_MINOR_VERSION); import_python = GetPythonImport(hDLL); diff --git a/Python/fileutils.c b/Python/fileutils.c index 3b53baa00eeb10..863f88b51167c5 100644 --- a/Python/fileutils.c +++ b/Python/fileutils.c @@ -6,6 +6,7 @@ #ifdef MS_WINDOWS # include +# include # include extern int winerror_to_errno(int); #endif @@ -1976,13 +1977,15 @@ _Py_wrealpath(const wchar_t *path, #endif -#ifndef MS_WINDOWS int _Py_isabs(const wchar_t *path) { +#ifdef MS_WINDOWS + return !PathIsRelativeW(path); +#else return (path[0] == SEP); -} #endif +} /* Get an absolute path. diff --git a/Python/frozenmain.c b/Python/frozenmain.c index dd04d609d24f93..a6855033334dde 100644 --- a/Python/frozenmain.c +++ b/Python/frozenmain.c @@ -8,7 +8,6 @@ #ifdef MS_WINDOWS extern void PyWinFreeze_ExeInit(void); extern void PyWinFreeze_ExeTerm(void); -extern int PyInitFrozenExtensions(void); #endif /* Main program */ @@ -75,9 +74,6 @@ Py_FrozenMain(int argc, char **argv) PyMem_RawFree(oldloc); oldloc = NULL; -#ifdef MS_WINDOWS - PyInitFrozenExtensions(); -#endif /* MS_WINDOWS */ if (argc >= 1) Py_SetProgramName(argv_copy[0]); diff --git a/Python/importdl.c b/Python/importdl.c index 6d2554741f9822..52c9828f0d144b 100644 --- a/Python/importdl.c +++ b/Python/importdl.c @@ -12,16 +12,9 @@ #include "importdl.h" -#ifdef MS_WINDOWS -extern dl_funcptr _PyImport_FindSharedFuncptrWindows(const char *prefix, - const char *shortname, - PyObject *pathname, - FILE *fp); -#else extern dl_funcptr _PyImport_FindSharedFuncptr(const char *prefix, const char *shortname, const char *pathname, FILE *fp); -#endif static const char * const ascii_only_prefix = "PyInit"; static const char * const nonascii_prefix = "PyInitU"; @@ -92,9 +85,7 @@ get_encoded_name(PyObject *name, const char **hook_prefix) { PyObject * _PyImport_LoadDynamicModuleWithSpec(PyObject *spec, FILE *fp) { -#ifndef MS_WINDOWS PyObject *pathbytes = NULL; -#endif PyObject *name_unicode = NULL, *name = NULL, *path = NULL, *m = NULL; const char *name_buf, *hook_prefix; const char *oldcontext; @@ -127,10 +118,6 @@ _PyImport_LoadDynamicModuleWithSpec(PyObject *spec, FILE *fp) goto error; } -#ifdef MS_WINDOWS - exportfunc = _PyImport_FindSharedFuncptrWindows(hook_prefix, name_buf, - path, fp); -#else pathbytes = PyUnicode_EncodeFSDefault(path); if (pathbytes == NULL) goto error; @@ -138,7 +125,6 @@ _PyImport_LoadDynamicModuleWithSpec(PyObject *spec, FILE *fp) PyBytes_AS_STRING(pathbytes), fp); Py_DECREF(pathbytes); -#endif if (exportfunc == NULL) { if (!PyErr_Occurred()) { diff --git a/Python/initconfig.c b/Python/initconfig.c index 0341e7baa210c9..e2c92b6ef9a87b 100644 --- a/Python/initconfig.c +++ b/Python/initconfig.c @@ -2668,12 +2668,10 @@ config_run_filename_abspath(PyConfig *config) return _PyStatus_OK(); } -#ifndef MS_WINDOWS if (_Py_isabs(config->run_filename)) { /* path is already absolute */ return _PyStatus_OK(); } -#endif wchar_t *abs_filename; if (_Py_abspath(config->run_filename, &abs_filename) < 0) { diff --git a/Python/pathconfig.c b/Python/pathconfig.c index 1017a571f2b829..c6a3d7e69bc5fd 100644 --- a/Python/pathconfig.c +++ b/Python/pathconfig.c @@ -227,7 +227,9 @@ _PyPathConfig_AsDict(void) { wchar_t py3path[MAX_PATH]; - HMODULE hPython3 = GetModuleHandleW(PY3_DLLNAME); +#define STRINGIFY(x) #x + HMODULE hPython3 = GetModuleHandleW(STRINGIFY(PY3_DLLNAME)); +#undef STRINGIFY PyObject *obj; if (hPython3 && GetModuleFileNameW(hPython3, py3path, Py_ARRAY_LENGTH(py3path))) diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index eeaf20b4617a20..2254ac8e0ecdf2 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -316,7 +316,11 @@ _coerce_default_locale_settings(int warn, const _LocaleCoercionTarget *target) _Py_SetLocaleFromEnv(LC_ALL); /* Set the relevant locale environment variable */ +#ifdef _WIN32 + if (setlocale(LC_CTYPE, newloc)) { +#else if (setenv("LC_CTYPE", newloc, 1)) { +#endif fprintf(stderr, "Error setting LC_CTYPE, skipping C locale coercion\n"); return 0; diff --git a/Python/sysmodule.c b/Python/sysmodule.c index ac49f7867a5cb3..5eeea60223b9e7 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -36,6 +36,7 @@ Data members: #ifdef MS_WINDOWS #define WIN32_LEAN_AND_MEAN #include +#define MS_COREDLL 1 #endif /* MS_WINDOWS */ #ifdef MS_COREDLL diff --git a/Python/thread_pthread.h b/Python/thread_pthread.h index 35b9810aa377f2..57216c94f74105 100644 --- a/Python/thread_pthread.h +++ b/Python/thread_pthread.h @@ -359,6 +359,9 @@ PyThread_get_thread_native_id(void) #elif defined(__NetBSD__) lwpid_t native_id; native_id = _lwp_self(); +#elif defined(_WIN32) + void *native_id; + native_id = pthread_gethandle(pthread_self()); #endif return (unsigned long) native_id; } diff --git a/configure b/configure index 19f1bd59ba8b18..5274beb0e821f1 100755 --- a/configure +++ b/configure @@ -3334,6 +3334,7 @@ then # ac_sys_system and ac_sys_release are used for setting # a lot of different things including 'define_xopen_source' # in the case statement below. + ac_sys_release= case "$host" in *-*-linux-android*) ac_sys_system=Linux-android @@ -3344,6 +3345,10 @@ then *-*-cygwin*) ac_sys_system=Cygwin ;; + *-*-darwin*) + ac_sys_system=Darwin + ac_sys_release=20.0 + ;; *-*-vxworks*) ac_sys_system=VxWorks ;; @@ -3352,7 +3357,6 @@ then MACHDEP="unknown" as_fn_error $? "cross build not supported for $host" "$LINENO" 5 esac - ac_sys_release= else ac_sys_system=`uname -s` if test "$ac_sys_system" = "AIX" \ @@ -3394,6 +3398,9 @@ if test "$cross_compiling" = yes; then *-*-cygwin*) _host_cpu= ;; + *-*-darwin*) + _host_cpu=$host_cpu + ;; *-*-vxworks*) _host_cpu=$host_cpu ;; @@ -5364,8 +5371,14 @@ cat >> conftest.c <> conftest.c <) +#include +#endif +#if defined(__APPLE__) && __has_include() +#include +#endif #undef bfin #undef cris #undef fr30 @@ -731,12 +756,62 @@ cat >> conftest.c <> conftest.c </dev/null)] ) @@ -1066,11 +1173,11 @@ AC_MSG_RESULT($EXPORTSYMS) # in the same bahaviour as before. AC_SUBST(GNULD) AC_MSG_CHECKING(for GNU ld) -ac_prog=ld +ac_prog=${LINKCC} if test "$GCC" = yes; then ac_prog=`$CC -print-prog-name=ld` fi -case `"$ac_prog" -V 2>&1 < /dev/null` in +case `"$ac_prog" -Wl,-V 2>&1 < /dev/null` in *GNU*) GNULD=yes;; *) @@ -1085,7 +1192,7 @@ AC_ARG_ENABLE(shared, if test -z "$enable_shared" then case $ac_sys_system in - CYGWIN*) + CYGWIN*|MinGW*) enable_shared="yes";; *) enable_shared="no";; @@ -1135,9 +1242,11 @@ if test $enable_shared = "yes"; then PY_ENABLE_SHARED=1 AC_DEFINE(Py_ENABLE_SHARED, 1, [Defined if Python is built as a shared library.]) case $ac_sys_system in - CYGWIN*) + CYGWIN*|MinGW*) + BLDLIBRARY='-L. -lpython$(LDVERSION)' LDLIBRARY='libpython$(LDVERSION).dll.a' DLLLIBRARY='libpython$(LDVERSION).dll' + PY3LIBRARY='$(LDLIBRARY)' ;; SunOS*) LDLIBRARY='libpython$(LDVERSION).so' @@ -1185,7 +1294,7 @@ if test $enable_shared = "yes"; then else # shared is disabled PY_ENABLE_SHARED=0 case $ac_sys_system in - CYGWIN*) + CYGWIN*|MinGW*) BLDLIBRARY='$(LIBRARY)' LDLIBRARY='libpython$(LDVERSION).dll.a' ;; @@ -1234,7 +1343,7 @@ AC_PROG_MKDIR_P AC_SUBST(LN) if test -z "$LN" ; then case $ac_sys_system in - CYGWIN*) LN="ln -s";; + CYGWIN*|MinGW*) LN="ln -s";; *) LN=ln;; esac fi @@ -2503,6 +2612,16 @@ case $ac_sys_system/$ac_sys_release in } ]])],[ac_osx_32bit=yes],[ac_osx_32bit=no],[ac_osx_32bit=yes]) +if test "$cross_compiling" = yes; then : + case $cpu in + aarch64|arm64) + MACOSX_DEFAULT_ARCH="arm64" + ;; + x86_64) + MACOSX_DEFAULT_ARCH="x86_64" + ;; + esac +else if test "${ac_osx_32bit}" = "yes"; then case `/usr/bin/arch` in i386) @@ -2532,6 +2651,7 @@ case $ac_sys_system/$ac_sys_release in esac fi +fi LIBTOOL_CRUFT=$LIBTOOL_CRUFT" -lSystem -lSystemStubs -arch_only ${MACOSX_DEFAULT_ARCH}" LIBTOOL_CRUFT=$LIBTOOL_CRUFT' -install_name $(PYTHONFRAMEWORKINSTALLDIR)/Versions/$(VERSION)/$(PYTHONFRAMEWORK)' @@ -2631,7 +2751,8 @@ if test -z "$SHLIB_SUFFIX"; then *) SHLIB_SUFFIX=.sl;; esac ;; - CYGWIN*) SHLIB_SUFFIX=.dll;; + Darwin*) SHLIB_SUFFIX=.dylib;; + CYGWIN*|MinGW*) SHLIB_SUFFIX=.dll;; *) SHLIB_SUFFIX=.so;; esac fi @@ -2756,6 +2877,9 @@ then CYGWIN*) LDSHARED="gcc -shared -Wl,--enable-auto-image-base" LDCXXSHARED="g++ -shared -Wl,--enable-auto-image-base";; + MinGW*) + LDSHARED='$(CC) -shared' + LDCXXSHARED='$(CXX) -shared';; *) LDSHARED="ld";; esac fi @@ -2779,6 +2903,7 @@ then else CCSHARED="+z"; fi;; Linux-android*) ;; + Linux-musl*) ;; Linux*|GNU*) CCSHARED="-fPIC";; FreeBSD*|NetBSD*|OpenBSD*|DragonFly*) CCSHARED="-fPIC";; OpenUNIX*|UnixWare*) @@ -2807,6 +2932,7 @@ then LINKFORSHARED="-Wl,-E -Wl,+s";; # LINKFORSHARED="-Wl,-E -Wl,+s -Wl,+b\$(BINLIBDEST)/lib-dynload";; Linux-android*) LINKFORSHARED="-pie -Xlinker -export-dynamic";; + Linux-musl*) LINKFORSHARED="-pie -Xlinker -export-dynamic";; Linux*|GNU*) LINKFORSHARED="-Xlinker -export-dynamic";; # -u libsys_s pulls in all symbols in libsys Darwin/*) @@ -2848,7 +2974,7 @@ then LINKFORSHARED="-Xlinker --export-dynamic" fi;; esac;; - CYGWIN*) + CYGWIN*|MinGW*) if test $enable_shared = "no" then LINKFORSHARED='-Wl,--out-implib=$(LDLIBRARY)' @@ -2872,7 +2998,7 @@ AC_MSG_CHECKING(CFLAGSFORSHARED) if test ! "$LIBRARY" = "$LDLIBRARY" then case $ac_sys_system in - CYGWIN*) + CYGWIN*|MinGW*) # Cygwin needs CCSHARED when building extension DLLs # but not when building the interpreter DLL. CFLAGSFORSHARED='';; @@ -3362,7 +3488,7 @@ if test "$posix_threads" = "yes"; then fi AC_CHECK_FUNCS(pthread_sigmask, [case $ac_sys_system in - CYGWIN*) + CYGWIN*|MinGW*) AC_DEFINE(HAVE_BROKEN_PTHREAD_SIGMASK, 1, [Define if pthread_sigmask() does not work on your system.]) ;; @@ -3672,6 +3798,7 @@ if test -z "$DYNLOADFILE" then case $ac_sys_system/$ac_sys_release in hp*|HP*) DYNLOADFILE="dynload_hpux.o";; + MinGW*) DYNLOADFILE="dynload_shlib.o";; *) # use dynload_shlib.c and dlopen() if we have it; otherwise stub # out any dynamic loading @@ -4843,15 +4970,14 @@ AC_MSG_CHECKING(LDVERSION) LDVERSION='$(VERSION)$(ABIFLAGS)' AC_MSG_RESULT($LDVERSION) -# On Android and Cygwin the shared libraries must be linked with libpython. +# On Android and Cygwin/MinGW the shared libraries must be linked with libpython. AC_SUBST(LIBPYTHON) -if test -n "$ANDROID_API_LEVEL" -o "$MACHDEP" = "cygwin"; then +if test -n "$ANDROID_API_LEVEL" -o "$MACHDEP" = "cygwin" -o "$MACHDEP" = "win32"; then LIBPYTHON="-lpython${VERSION}${ABIFLAGS}" else LIBPYTHON='' fi - AC_SUBST(BINLIBDEST) BINLIBDEST='$(LIBDIR)/python$(VERSION)' diff --git a/setup.py b/setup.py index 85a2b26357db46..af5d4e41ec7ce6 100644 --- a/setup.py +++ b/setup.py @@ -83,7 +83,7 @@ def get_platform(): HOST_PLATFORM = get_platform() MS_WINDOWS = (HOST_PLATFORM == 'win32') CYGWIN = (HOST_PLATFORM == 'cygwin') -MACOS = (HOST_PLATFORM == 'darwin') +MACOS = (HOST_PLATFORM.startswith('darwin')) AIX = (HOST_PLATFORM.startswith('aix')) VXWORKS = ('vxworks' in HOST_PLATFORM) CC = os.environ.get("CC") @@ -680,10 +680,10 @@ def add_multiarch_paths(self): os.unlink(tmpfile) if multiarch_path_component != '': - add_dir_to_list(self.compiler.library_dirs, - '/usr/lib/' + multiarch_path_component) - add_dir_to_list(self.compiler.include_dirs, - '/usr/include/' + multiarch_path_component) + # add_dir_to_list(self.compiler.library_dirs, + # '/usr/lib/' + multiarch_path_component) + # add_dir_to_list(self.compiler.include_dirs, + # '/usr/include/' + multiarch_path_component) return if not find_executable('dpkg-architecture'): @@ -701,10 +701,10 @@ def add_multiarch_paths(self): if ret == 0: with open(tmpfile) as fp: multiarch_path_component = fp.readline().strip() - add_dir_to_list(self.compiler.library_dirs, - '/usr/lib/' + multiarch_path_component) - add_dir_to_list(self.compiler.include_dirs, - '/usr/include/' + multiarch_path_component) + # add_dir_to_list(self.compiler.library_dirs, + # '/usr/lib/' + multiarch_path_component) + # add_dir_to_list(self.compiler.include_dirs, + # '/usr/include/' + multiarch_path_component) finally: os.unlink(tmpfile) @@ -825,9 +825,9 @@ def configure_compiler(self): # Ensure that /usr/local is always used, but the local build # directories (i.e. '.' and 'Include') must be first. See issue # 10520. - if not CROSS_COMPILING: - add_dir_to_list(self.compiler.library_dirs, '/usr/local/lib') - add_dir_to_list(self.compiler.include_dirs, '/usr/local/include') + # if not CROSS_COMPILING: + # add_dir_to_list(self.compiler.library_dirs, '/usr/local/lib') + # add_dir_to_list(self.compiler.include_dirs, '/usr/local/include') # only change this for cross builds for 3.3, issues on Mageia if CROSS_COMPILING: self.add_cross_compiling_paths() @@ -1163,8 +1163,8 @@ def detect_readline_curses(self): panel_library = 'panel' if curses_library == 'ncursesw': curses_defines.append(('HAVE_NCURSESW', '1')) - if not CROSS_COMPILING: - curses_includes.append('/usr/include/ncursesw') + # if not CROSS_COMPILING: + # curses_includes.append('/usr/include/ncursesw') # Bug 1464056: If _curses.so links with ncursesw, # _curses_panel.so must link with panelw. panel_library = 'panelw'