]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-59703: use the system dladdr function in getpath.c for macOS framework builds...
authorAN Long <aisk@users.noreply.github.com>
Tue, 21 Nov 2023 05:15:25 +0000 (13:15 +0800)
committerGitHub <noreply@github.com>
Tue, 21 Nov 2023 05:15:25 +0000 (00:15 -0500)
Co-authored-by: Ned Deily <nad@python.org>
Misc/NEWS.d/next/macOS/2023-10-31-22-13-05.gh-issue-59703.SML6Ag.rst [new file with mode: 0644]
Modules/getpath.c

diff --git a/Misc/NEWS.d/next/macOS/2023-10-31-22-13-05.gh-issue-59703.SML6Ag.rst b/Misc/NEWS.d/next/macOS/2023-10-31-22-13-05.gh-issue-59703.SML6Ag.rst
new file mode 100644 (file)
index 0000000..eeb014d
--- /dev/null
@@ -0,0 +1,4 @@
+For macOS framework builds, in ``getpath.c`` use the system ``dladdr``
+function to find the path to the shared library rather than depending
+on deprecated macOS APIs.
+
index 50ba090ee548ca59751135b7bff5dcebc5682ebc..be1a9cf9cc47821de09f28c9268a90b8dc0303da 100644 (file)
@@ -17,7 +17,7 @@
 #endif
 
 #ifdef __APPLE__
-#  include <mach-o/dyld.h>
+#  include <dlfcn.h>
 #endif
 
 /* Reference the precompiled getpath.py */
@@ -768,16 +768,11 @@ library_to_dict(PyObject *dict, const char *key)
            which is in the framework, not relative to the executable, which may
            be outside of the framework. Except when we're in the build
            directory... */
-        NSSymbol symbol = NSLookupAndBindSymbol("_Py_Initialize");
-        if (symbol != NULL) {
-            NSModule pythonModule = NSModuleForSymbol(symbol);
-            if (pythonModule != NULL) {
-                /* Use dylib functions to find out where the framework was loaded from */
-                const char *path = NSLibraryNameForModule(pythonModule);
-                if (path) {
-                    strncpy(modPath, path, MAXPATHLEN);
-                    modPathInitialized = 1;
-                }
+        Dl_info pythonInfo;
+        if (dladdr(&Py_Initialize, &pythonInfo)) {
+            if (pythonInfo.dli_fname) {
+                strncpy(modPath, pythonInfo.dli_fname, MAXPATHLEN);
+                modPathInitialized = 1;
             }
         }
     }