diff options
author | Martin v. Löwis <martin@v.loewis.de> | 2010-12-03 20:14:31 (GMT) |
---|---|---|
committer | Martin v. Löwis <martin@v.loewis.de> | 2010-12-03 20:14:31 (GMT) |
commit | 4d0d471a8031de90a2b1ce99c4ac4780e60b3bc9 (patch) | |
tree | c8f1fef715f8d158e58f17cab14af65455de1d77 /PC/getpathp.c | |
parent | c4df7845143f9afe0d20f4421a41904f3cbb991a (diff) | |
download | cpython-4d0d471a8031de90a2b1ce99c4ac4780e60b3bc9.zip cpython-4d0d471a8031de90a2b1ce99c4ac4780e60b3bc9.tar.gz cpython-4d0d471a8031de90a2b1ce99c4ac4780e60b3bc9.tar.bz2 |
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 3a87411..cd3a4b2 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; +} |