changeset 29019:210bb28ca4fb stable

exewrapper: add .dll to LoadLibrary() argument LoadLibrary() changes behavior depending on whether the argument passed to it contains a period. From the MSDN docs: If no file name extension is specified in the lpFileName parameter, the default library extension .dll is appended. However, the file name string can include a trailing point character (.) to indicate that the module name has no extension. When no path is specified, the function searches for loaded modules whose base name matches the base name of the module to be loaded. If the name matches, the load succeeds. Otherwise, the function searches for the file. As the subsequent patch will show, some environments on Windows define their Python library as e.g. "libpython2.7.dll." The existing code would pass "libpython2.7" into LoadLibrary(). It would assume "7" was the file extension and look for a "libpython2.dll" to load. By passing ".dll" into LoadLibrary(), we force it to search for the exact basename we want, even if it contains a period.
author Gregory Szorc <gregory.szorc@gmail.com>
date Wed, 27 Apr 2016 09:23:39 -0700
parents 602cc9bf036e
children ee2e4a2c3690
files mercurial/exewrapper.c
diffstat 1 files changed, 3 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/exewrapper.c	Wed Apr 27 14:02:54 2016 -0700
+++ b/mercurial/exewrapper.c	Wed Apr 27 09:23:39 2016 -0700
@@ -96,7 +96,8 @@
 			/* path pyhome exists, let's use it */
 			FindClose(hfind);
 			strcpy_s(pydllfile, sizeof(pydllfile), pyhome);
-			strcat_s(pydllfile, sizeof(pydllfile), "\\" HGPYTHONLIB);
+			strcat_s(pydllfile, sizeof(pydllfile),
+				 "\\" HGPYTHONLIB ".dll");
 			pydll = LoadLibrary(pydllfile);
 			if (pydll == NULL) {
 				err = "failed to load private Python DLL "
@@ -114,7 +115,7 @@
 	}
 
 	if (pydll == NULL) {
-		pydll = LoadLibrary(HGPYTHONLIB);
+		pydll = LoadLibrary(HGPYTHONLIB ".dll");
 		if (pydll == NULL) {
 			err = "failed to load Python DLL " HGPYTHONLIB ".dll";
 			goto bail;