diff options
author | Martin v. Löwis <martin@v.loewis.de> | 2010-12-03 20:14:31 +0000 |
---|---|---|
committer | Martin v. Löwis <martin@v.loewis.de> | 2010-12-03 20:14:31 +0000 |
commit | bbbb00332d45ae20db0b9032efcb3bf397e2df3d (patch) | |
tree | 64339836deec8ec39dcf8735685892f9f0933d41 /PC/getpathp.c | |
parent | 53971b6f36f0c0df64b44be4cbe03f7446c00bbb (diff) | |
download | cpython-bbbb00332d45ae20db0b9032efcb3bf397e2df3d.tar.gz |
Merge branches/pep-0384.
Diffstat (limited to 'PC/getpathp.c')
-rw-r--r-- | PC/getpathp.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/PC/getpathp.c b/PC/getpathp.c index 3a87411d0f..cd3a4b2504 100644 --- a/PC/getpathp.c +++ b/PC/getpathp.c @@ -707,3 +707,38 @@ Py_GetProgramFullPath(void) calculate_path(); return progpath; } + +/* Load python3.dll before loading any extension module that might refer + to it. That way, we can be sure that always the python3.dll corresponding + to this python DLL is loaded, not a python3.dll that might be on the path + by chance. + Return whether the DLL was found. +*/ +static int python3_checked = 0; +static HANDLE hPython3; +int +_Py_CheckPython3() +{ + wchar_t py3path[MAXPATHLEN+1]; + wchar_t *s; + if (python3_checked) + return hPython3 != NULL; + python3_checked = 1; + + /* If there is a python3.dll next to the python3y.dll, + assume this is a build tree; use that DLL */ + wcscpy(py3path, dllpath); + s = wcsrchr(py3path, L'\\'); + if (!s) + s = py3path; + wcscpy(s, L"\\python3.dll"); + hPython3 = LoadLibraryExW(py3path, NULL, LOAD_WITH_ALTERED_SEARCH_PATH); + if (hPython3 != NULL) + return 1; + + /* Check sys.prefix\DLLs\python3.dll */ + wcscpy(py3path, Py_GetPrefix()); + wcscat(py3path, L"\\DLLs\\python3.dll"); + hPython3 = LoadLibraryExW(py3path, NULL, LOAD_WITH_ALTERED_SEARCH_PATH); + return hPython3 != NULL; +} |