|
17 | 17 | #endif
|
18 | 18 |
|
19 | 19 | #ifdef __APPLE__
|
20 |
| -# include <dlfcn.h> |
21 | 20 | # include <mach-o/dyld.h>
|
22 | 21 | #endif
|
23 | 22 |
|
| 23 | +#ifdef HAVE_DLFCN_H |
| 24 | +# include <dlfcn.h> |
| 25 | +#endif |
| 26 | + |
24 | 27 | /* Reference the precompiled getpath.py */
|
25 | 28 | #include "Python/frozen_modules/getpath.h"
|
26 | 29 |
|
@@ -803,36 +806,27 @@ progname_to_dict(PyObject *dict, const char *key)
|
803 | 806 | static int
|
804 | 807 | library_to_dict(PyObject *dict, const char *key)
|
805 | 808 | {
|
806 |
| -#ifdef MS_WINDOWS |
807 | 809 | #ifdef Py_ENABLE_SHARED
|
| 810 | + static char path[MAXPATHLEN + 1] = {0}; |
| 811 | + |
| 812 | +#ifdef MS_WINDOWS |
808 | 813 | extern HMODULE PyWin_DLLhModule;
|
809 | 814 | if (PyWin_DLLhModule) {
|
810 | 815 | return winmodule_to_dict(dict, key, PyWin_DLLhModule);
|
811 | 816 | }
|
812 | 817 | #endif
|
813 |
| -#elif defined(WITH_NEXT_FRAMEWORK) |
814 |
| - static char modPath[MAXPATHLEN + 1]; |
815 |
| - static int modPathInitialized = -1; |
816 |
| - if (modPathInitialized < 0) { |
817 |
| - modPathInitialized = 0; |
818 |
| - |
819 |
| - /* On Mac OS X we have a special case if we're running from a framework. |
820 |
| - This is because the python home should be set relative to the library, |
821 |
| - which is in the framework, not relative to the executable, which may |
822 |
| - be outside of the framework. Except when we're in the build |
823 |
| - directory... */ |
824 |
| - Dl_info pythonInfo; |
825 |
| - if (dladdr(&Py_Initialize, &pythonInfo)) { |
826 |
| - if (pythonInfo.dli_fname) { |
827 |
| - strncpy(modPath, pythonInfo.dli_fname, MAXPATHLEN); |
828 |
| - modPathInitialized = 1; |
829 |
| - } |
| 818 | + |
| 819 | +#if HAVE_DLADDR |
| 820 | + Dl_info libpython_info; |
| 821 | + if (dladdr(&Py_Initialize, &libpython_info) && libpython_info.dli_fname) { |
| 822 | + strncpy(path, pythonInfo.dli_fname, MAXPATHLEN); |
| 823 | + if (path[sizeof(path)-1] == '\0') { |
| 824 | + return decode_to_dict(dict, key, path); |
830 | 825 | }
|
831 | 826 | }
|
832 |
| - if (modPathInitialized > 0) { |
833 |
| - return decode_to_dict(dict, key, modPath); |
834 |
| - } |
835 | 827 | #endif
|
| 828 | +#endif |
| 829 | + |
836 | 830 | return PyDict_SetItemString(dict, key, Py_None) == 0;
|
837 | 831 | }
|
838 | 832 |
|
|
0 commit comments