diff -r b0668185dc15 Modules/getpath.c --- a/Modules/getpath.c Tue Jun 25 23:13:47 2013 +0200 +++ b/Modules/getpath.c Wed Jun 26 17:48:39 2013 +0200 @@ -363,6 +363,21 @@ reduce(prefix); } while (prefix[0]); + /* search relative to the python shared library */ + if (_PyImport_GetModulePath(prefix, MAXPATHLEN)) { + /* make this work on *nix and win32 ../lib/python3 */ + reduce(prefix); + reduce(prefix); + if (wcslen(prefix) + 1 + wcslen(lib_python) < MAXPATHLEN) { + joinpath(prefix, lib_python); + if (wcslen(prefix) + 1 + wcslen(LANDMARK) < MAXPATHLEN) { + joinpath(prefix, LANDMARK); + if (ismodule(prefix)) + return 1; + } + } + } + /* Look at configure's PREFIX */ wcsncpy(prefix, _prefix, MAXPATHLEN); joinpath(prefix, lib_python); @@ -440,6 +455,21 @@ reduce(exec_prefix); } while (exec_prefix[0]); + /* search relative to the python shared library */ + if (_PyImport_GetModulePath(exec_prefix, MAXPATHLEN)) { + /* make this work on *nix and win32 ../lib/python3/lib-dynload */ + reduce(exec_prefix); + reduce(exec_prefix); + if (wcslen(exec_prefix) + 1 + wcslen(lib_python) < MAXPATHLEN) { + joinpath(exec_prefix, lib_python); + if (wcslen(exec_prefix) + 12 < MAXPATHLEN) { + joinpath(exec_prefix, L"lib-dynload"); + if (isdir(exec_prefix)) + return 1; + } + } + } + /* Look at configure's EXEC_PREFIX */ wcsncpy(exec_prefix, _exec_prefix, MAXPATHLEN); joinpath(exec_prefix, lib_python); diff -r b0668185dc15 Python/dynload_aix.c --- a/Python/dynload_aix.c Tue Jun 25 23:13:47 2013 +0200 +++ b/Python/dynload_aix.c Wed Jun 26 17:48:39 2013 +0200 @@ -181,3 +181,9 @@ return p; } + +int +_PyImport_GetModulePath(const wchar_t *path, size_t len) +{ + return 0; +} diff -r b0668185dc15 Python/dynload_dl.c --- a/Python/dynload_dl.c Tue Jun 25 23:13:47 2013 +0200 +++ b/Python/dynload_dl.c Wed Jun 26 17:48:39 2013 +0200 @@ -20,3 +20,10 @@ PyOS_snprintf(funcname, sizeof(funcname), "PyInit_%.200s", shortname); return dl_loadmod(Py_GetProgramName(), pathname, funcname); } + +int +_PyImport_GetModulePath(const wchar_t *path, size_t len) +{ + return 0; +} + diff -r b0668185dc15 Python/dynload_hpux.c --- a/Python/dynload_hpux.c Tue Jun 25 23:13:47 2013 +0200 +++ b/Python/dynload_hpux.c Wed Jun 26 17:48:39 2013 +0200 @@ -62,3 +62,10 @@ return p; } + +int +_PyImport_GetModulePath(const wchar_t *path, size_t len) +{ + return 0; +} + diff -r b0668185dc15 Python/dynload_next.c --- a/Python/dynload_next.c Tue Jun 25 23:13:47 2013 +0200 +++ b/Python/dynload_next.c Wed Jun 26 17:48:39 2013 +0200 @@ -108,3 +108,10 @@ p = (dl_funcptr)NSAddressOfSymbol(theSym); return p; } + +int +_PyImport_GetModulePath(const wchar_t *path, size_t len) +{ + return 0; +} + diff -r b0668185dc15 Python/dynload_shlib.c --- a/Python/dynload_shlib.c Tue Jun 25 23:13:47 2013 +0200 +++ b/Python/dynload_shlib.c Wed Jun 26 17:48:39 2013 +0200 @@ -149,3 +149,21 @@ p = (dl_funcptr) dlsym(handle, funcname); return p; } + +int +_PyImport_GetModulePath(const wchar_t *path, size_t len) +{ + Dl_info info; + wchar_t* buffer; + static const int dummy = 0; + if (0 == dladdr(&dummy, &info)) + return 0; + if (!info.dli_fname) + return 0; + buffer = _Py_char2wchar(info.dli_fname, NULL); + if (!buffer) + return 0; + wcsncpy(path, buffer, len); + PyMem_Free(buffer); + return 1; +} diff -r b0668185dc15 Python/dynload_win.c --- a/Python/dynload_win.c Tue Jun 25 23:13:47 2013 +0200 +++ b/Python/dynload_win.c Wed Jun 26 17:48:39 2013 +0200 @@ -295,3 +295,23 @@ return p; } + +int +_PyImport_GetModulePath(const wchar_t *path, size_t len) +{ + HMODULE handle; + DWORD flags; + static const wchar_t dummy = 0; + + flags = GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT + | GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS; + + if (!GetModuleHandleExW(flags, &dummy, &handle)) + return 0; + + DWORD retval = GetModuleFileNameW(handle, path, len); + if (retval == 0 || len <= retval) + return 0; + + return 1; +}