From 1e2d8c6c4973dc0290284f2135ed098bcced44c0 Mon Sep 17 00:00:00 2001 From: AN Long Date: Tue, 31 Oct 2023 22:13:42 +0800 Subject: [PATCH 1/2] gh-59703: use the dladdr instead of deprecated macOS APIs in getpath.c --- ...023-10-31-22-13-05.gh-issue-59703.SML6Ag.rst | 1 + Modules/getpath.c | 17 ++++++----------- 2 files changed, 7 insertions(+), 11 deletions(-) create mode 100644 Misc/NEWS.d/next/macOS/2023-10-31-22-13-05.gh-issue-59703.SML6Ag.rst 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 index 000000000000000..f16f09c10cb0ed5 --- /dev/null +++ b/Misc/NEWS.d/next/macOS/2023-10-31-22-13-05.gh-issue-59703.SML6Ag.rst @@ -0,0 +1 @@ +Use the ``dladdr`` instead of deprecated macOS APIs in ``getpath.c``. diff --git a/Modules/getpath.c b/Modules/getpath.c index 6f76a84e78bf625..596ee46d5cdcefe 100644 --- a/Modules/getpath.c +++ b/Modules/getpath.c @@ -18,7 +18,7 @@ #endif #ifdef __APPLE__ -# include +# include #endif /* Reference the precompiled getpath.py */ @@ -769,16 +769,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; } } } From 6c723768786ef99babeb4a7cce6cfddd1860c78f Mon Sep 17 00:00:00 2001 From: Ned Deily Date: Mon, 20 Nov 2023 23:39:00 -0500 Subject: [PATCH 2/2] Expand NEWS entry. --- .../next/macOS/2023-10-31-22-13-05.gh-issue-59703.SML6Ag.rst | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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 index f16f09c10cb0ed5..eeb014dd92ba36f 100644 --- 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 @@ -1 +1,4 @@ -Use the ``dladdr`` instead of deprecated macOS APIs in ``getpath.c``. +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. +