diff -r b74897b69184 Doc/library/sys.rst --- a/Doc/library/sys.rst Wed Nov 02 20:33:07 2016 -0400 +++ b/Doc/library/sys.rst Thu Nov 03 10:18:12 2016 +0900 @@ -244,6 +244,9 @@ the real path to its executable, :data:`sys.executable` will be an empty string or ``None``. + .. versionchanged:: 3.7 + Included executable suffix to path, if platform has it. + .. function:: exit([arg]) diff -r b74897b69184 Makefile.pre.in --- a/Makefile.pre.in Wed Nov 02 20:33:07 2016 -0400 +++ b/Makefile.pre.in Thu Nov 03 10:18:12 2016 +0900 @@ -751,6 +751,7 @@ -DEXEC_PREFIX='"$(exec_prefix)"' \ -DVERSION='"$(VERSION)"' \ -DVPATH='"$(VPATH)"' \ + -DEXE_SUFFIX='"$(EXE)"' \ -o $@ $(srcdir)/Modules/getpath.c Programs/python.o: $(srcdir)/Programs/python.c diff -r b74897b69184 Modules/getpath.c --- a/Modules/getpath.c Wed Nov 02 20:33:07 2016 -0400 +++ b/Modules/getpath.c Thu Nov 03 10:18:12 2016 +0900 @@ -101,8 +101,9 @@ #endif -#if !defined(PREFIX) || !defined(EXEC_PREFIX) || !defined(VERSION) || !defined(VPATH) -#error "PREFIX, EXEC_PREFIX, VERSION, and VPATH must be constant defined" +#if !defined(PREFIX) || !defined(EXEC_PREFIX) || !defined(VERSION) || \ + !defined(VPATH) || !defined(EXE_SUFFIX) +#error "PREFIX, EXEC_PREFIX, VERSION, VPATH, and EXE_SUFFIX must be constant defined" #endif #ifndef LANDMARK @@ -254,6 +255,36 @@ wcscpy(path, buffer); } + +/* add_exe_suffix requires that progpath be allocated at least + MAXPATHLEN + 1 bytes. +*/ +static void +add_exe_suffix(wchar_t *progpath) +{ + wchar_t *_suffix; + size_t n, k; + + _suffix = Py_DecodeLocale(EXE_SUFFIX, NULL); + if (_suffix == NULL) { + Py_FatalError("Unable to decode suffix variables in getpath.c: " + "memory error"); + } + + n = wcslen(progpath); + k = wcslen(_suffix); + /* Check for already have an executable suffix */ + if (wcsncasecmp(_suffix, progpath+n-k, k) != 0) { + if (n + k > MAXPATHLEN) { + Py_FatalError("progpath overflow in getpath.c's add_exe_suffix()"); + } + wcsncpy(progpath+n, _suffix, k); + progpath[n+k] = '\0'; + } + PyMem_RawFree(_suffix); +} + + /* search for a prefix value in an environment file. If found, copy it to the provided buffer, which is expected to be no more than MAXPATHLEN bytes long. @@ -563,6 +594,10 @@ PyMem_RawFree(path_buffer); if (progpath[0] != SEP && progpath[0] != '\0') absolutize(progpath); + + if (EXE_SUFFIX[0] != '\0' && progpath[0] != '\0') + add_exe_suffix(progpath); + wcsncpy(argv0_path, progpath, MAXPATHLEN); argv0_path[MAXPATHLEN] = '\0';