# HG changeset patch # User Matt Harbison # Date 1545000165 18000 # Node ID ef7119cd496514100b5fb3984ba4781b6c1d0c6c # Parent 2465e0b27a0d0e6b7af29fe746ae6952bd4395eb py3: enable legacy stdio mode in exewrapper This drops the test failure count from 166 to 117. The failures were typically in the form of `hg serve -d` spawning but crashing immediately, leaving clients with "bad http status" lines, connection refusals, and so forth. The underlying message on the server side was either "OSError: [WinError 6] The handle is invalid" or "OSError: [WinError 1] Incorrect function". Additionally, no output was rendered if the pager was activated. Thanks to Yuya for diagnosing the problem. The failure count drops to 107 when PYTHONLEGACYWINDOWSSTDIO=1 is defined in the environment. These failures seem to revolve around the dummyssh server process, and dumbhttp.py. So I'll probably add that to the test runner. One small regression here (only in py3) is that if hg.exe is already built, a messagebox appears when building it again saying that python37.dll can't be loaded. Python3 isn't in PATH by default, and setup.py tries running bare `hg` first. But MSYS prepends '.' to PATH, so it runs the local hg, but can't find the library. It falls back to the python used to invoke setup.py, so ultimately it works. I'm not sure if it's better to strip '.' from PATH or just skip right to `sys.executable hg` on Windows. Also, something seems to be wrong with run-tests._usecorrectpython(). I accidentially left off the 'PYTHON="py -3"' when building (thus making py2 stuff), and yet managed to invoke run-tests.py with "py -3". (And that only had 67 failures.) diff -r 2465e0b27a0d -r ef7119cd4965 mercurial/exewrapper.c --- a/mercurial/exewrapper.c Sun Dec 16 17:36:51 2018 -0500 +++ b/mercurial/exewrapper.c Sun Dec 16 17:42:45 2018 -0500 @@ -7,6 +7,7 @@ GNU General Public License version 2 or any later version. */ +#include #include #include #include @@ -46,6 +47,10 @@ void(__cdecl * Py_SetPythonHome)(TCHAR * home); int(__cdecl * Py_Main)(int argc, TCHAR *argv[]); +#if PY_MAJOR_VERSION >= 3 + Py_LegacyWindowsStdioFlag = 1; +#endif + if (GetModuleFileName(NULL, pyscript, _countof(pyscript)) == 0) { err = "GetModuleFileName failed"; goto bail; diff -r 2465e0b27a0d -r ef7119cd4965 tests/run-tests.py --- a/tests/run-tests.py Sun Dec 16 17:36:51 2018 -0500 +++ b/tests/run-tests.py Sun Dec 16 17:42:45 2018 -0500 @@ -2640,6 +2640,10 @@ self._tmpbindir = self._bindir self._pythondir = os.path.join(self._installdir, b"lib", b"python") + # Force the use of hg.exe instead of relying on MSYS to recognize hg is + # a python script and feed it to python.exe. Legacy stdio is force + # enabled by hg.exe, and this is a more realistic way to launch hg + # anyway. if os.name == 'nt' and not self._hgcommand.endswith(b'.exe'): self._hgcommand += b'.exe'