]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
When loading the Python dll to run the postinstall script, try to load
authorThomas Heller <theller@ctypes.org>
Thu, 15 Apr 2004 17:50:42 +0000 (17:50 +0000)
committerThomas Heller <theller@ctypes.org>
Thu, 15 Apr 2004 17:50:42 +0000 (17:50 +0000)
it from the install directory (as reported by the registry) in case it
is not found on the default Loadlibrary search path.

Fixes SF 935091: bdist_winist post-install script fails on non-admin Python

Will port to the trunk later.

PC/bdist_wininst/install.c

index 597bd9e8eb0919259b45a36abb1956ba6d18611c..ba98aa3aaf0d6f20acf12a7cdd75c22279336e4e 100644 (file)
@@ -1352,14 +1352,15 @@ SelectPythonDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
                                                                    (LPARAM)pbuf);
                                                result = sscanf(pbuf, "Python Version %d.%d",
                                                                 &py_major, &py_minor);
-                                               if (result == 2)
+                                               if (result == 2) {
 #ifdef _DEBUG
-                                                       wsprintf(pythondll, "c:\\python22\\PCBuild\\python%d%d_d.dll",
-                                                                 py_major, py_minor);
+                                                       wsprintf(pythondll, "python%d%d_d.dll",
+                                                                py_major, py_minor);
 #else
-                                               wsprintf(pythondll, "python%d%d.dll",
-                                                         py_major, py_minor);
+                                                       wsprintf(pythondll, "python%d%d.dll",
+                                                                py_major, py_minor);
 #endif
+                                               }
                                                free(pbuf);
                                        } else
                                                strcpy(pythondll, "");
@@ -1523,6 +1524,22 @@ static void CloseLogfile(void)
                fclose(logfile);
 }
 
+static HINSTANCE LoadPythonDll(char *fname)
+{
+       char fullpath[_MAX_PATH];
+       LONG size = sizeof(fullpath);
+       HINSTANCE h = LoadLibrary(fname);
+       if (h)
+               return h;
+       if (ERROR_SUCCESS != RegQueryValue(HKEY_CURRENT_USER,
+                                          "SOFTWARE\\Python\\PythonCore\\2.3\\InstallPath",
+                                          fullpath, &size))
+               return NULL;
+       strcat(fullpath, "\\");
+       strcat(fullpath, fname);
+       return LoadLibrary(fullpath);
+}
+
 BOOL CALLBACK
 InstallFilesDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
 {
@@ -1616,7 +1633,7 @@ InstallFilesDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
                                                "Compiling files to .pyc...");
 
                                SetDlgItemText(hDialog, IDC_INFO, "Loading python...");
-                               hPython = LoadLibrary(pythondll);
+                               hPython = LoadPythonDll(pythondll);
                                if (hPython) {
                                        errors = compile_filelist(hPython, FALSE);
                                        FreeLibrary(hPython);
@@ -1635,7 +1652,7 @@ InstallFilesDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
                                                "Compiling files to .pyo...");
 
                                SetDlgItemText(hDialog, IDC_INFO, "Loading python...");
-                               hPython = LoadLibrary(pythondll);
+                               hPython = LoadPythonDll(pythondll);
                                if (hPython) {
                                        errors = compile_filelist(hPython, TRUE);
                                        FreeLibrary(hPython);
@@ -1711,7 +1728,7 @@ FinishedDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
 
                        argv[0] = fname;
 
-                       hPython = LoadLibrary(pythondll);
+                       hPython = LoadPythonDll(pythondll);
                        if (hPython) {
                                int result;
                                result = run_installscript(hPython, fname, 2, argv);