Patchwork D10756: exewrapper: avoid directly linking against python3X.dll

login
register
mail settings
Submitter phabricator
Date May 20, 2021, 2:23 p.m.
Message ID <differential-rev-PHID-DREV-6r5jr6n7cnrs5w3vgfni-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/49076/
State Superseded
Headers show

Comments

phabricator - May 20, 2021, 2:23 p.m.
mharbison72 created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  Subsequent code calls `LoadLibrary()` to attempt to load the DLL, but because of
  this symbol reference, there is an attempt to load the DLL used during the build
  prior to `_main()` running.  This causes the whole process to fail if the DLL
  isn't in the standard search path.  That also means it will never load the DLL
  for HackableMercurial.  (Maybe we should get rid of that for py3, since you can
  install python for a user without admin rights?)
  
  This could also be resolved by calling `GetProcAddress()` on the symbol and
  dereferencing it, but using the environment variable is consistent with the
  *.bat file since fc8a5c9ecee0 <https://phab.mercurial-scm.org/rHGfc8a5c9ecee0877c01280ccb775387efd2bd62e6>.  (The environment variable persists after the
  interpreter is initialized.)
  
  Far more concerning is somehow I've gotten my system into a state where setting
  the flag causes any output to the pager to be lost (as if it wasn't set at all)
  in MSYS, cmd.exe, WSL, and PowerShell using py3.9.0, but the environment
  variable works properly.  I'm sure this flag worked on some versions of py3, so
  I'm not sure what's going on here.  This is using py3.9.0.
  
  With or without the flag/envvar, there is proper output if the command is
  directly paged by piping to `more.com` (in any environment) or `less` (in MSYS
  and WSL), or if paging is disabled with `--pager=no`.  Legacy mode is required
  though when Mercurial decides to spin up a pager.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D10756

AFFECTED FILES
  mercurial/exewrapper.c

CHANGE DETAILS




To: mharbison72, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/mercurial/exewrapper.c b/mercurial/exewrapper.c
--- a/mercurial/exewrapper.c
+++ b/mercurial/exewrapper.c
@@ -48,7 +48,7 @@ 
 	int(__cdecl * Py_Main)(int argc, TCHAR *argv[]);
 
 #if PY_MAJOR_VERSION >= 3
-	Py_LegacyWindowsStdioFlag = 1;
+	_wputenv(L"PYTHONLEGACYWINDOWSSTDIO=1");
 #endif
 
 	if (GetModuleFileName(NULL, pyscript, _countof(pyscript)) == 0) {