From 137b0cd807dbf1d28f03eff81f5ebf96b31a60f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filipe=20La=C3=ADns?= Date: Sun, 15 Dec 2024 19:33:02 +0000 Subject: [PATCH 01/12] GH-127970: find the runtime library when dladdr is available MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Filipe Laíns # include #endif +#ifdef HAVE_DLFCN_H +# include +#endif + /* Reference the precompiled getpath.py */ #include "Python/frozen_modules/getpath.h" @@ -803,36 +806,27 @@ progname_to_dict(PyObject *dict, const char *key) static int library_to_dict(PyObject *dict, const char *key) { -#ifdef MS_WINDOWS #ifdef Py_ENABLE_SHARED + static char path[MAXPATHLEN + 1] = {0}; + +#ifdef MS_WINDOWS extern HMODULE PyWin_DLLhModule; if (PyWin_DLLhModule) { return winmodule_to_dict(dict, key, PyWin_DLLhModule); } #endif -#elif defined(WITH_NEXT_FRAMEWORK) - static char modPath[MAXPATHLEN + 1]; - static int modPathInitialized = -1; - if (modPathInitialized < 0) { - modPathInitialized = 0; - - /* On Mac OS X we have a special case if we're running from a framework. - This is because the python home should be set relative to the library, - 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... */ - Dl_info pythonInfo; - if (dladdr(&Py_Initialize, &pythonInfo)) { - if (pythonInfo.dli_fname) { - strncpy(modPath, pythonInfo.dli_fname, MAXPATHLEN); - modPathInitialized = 1; - } + +#if HAVE_DLADDR + Dl_info libpython_info; + if (dladdr(&Py_Initialize, &libpython_info) && libpython_info.dli_fname) { + strncpy(path, libpython_info.dli_fname, MAXPATHLEN); + if (path[sizeof(path)-1] == '\0') { + return decode_to_dict(dict, key, path); } } - if (modPathInitialized > 0) { - return decode_to_dict(dict, key, modPath); - } #endif +#endif + return PyDict_SetItemString(dict, key, Py_None) == 0; } diff --git a/configure b/configure index 57be576e3cae99..e10d6eedde59e0 100755 --- a/configure +++ b/configure @@ -18260,6 +18260,12 @@ if test "x$ac_cv_func_ctermid" = xyes then : printf "%s\n" "#define HAVE_CTERMID 1" >>confdefs.h +fi +ac_fn_c_check_func "$LINENO" "dladdr" "ac_cv_func_dladdr" +if test "x$ac_cv_func_dladdr" = xyes +then : + printf "%s\n" "#define HAVE_DLADDR 1" >>confdefs.h + fi ac_fn_c_check_func "$LINENO" "dup" "ac_cv_func_dup" if test "x$ac_cv_func_dup" = xyes diff --git a/configure.ac b/configure.ac index bd0221481c5341..227b5587f0c509 100644 --- a/configure.ac +++ b/configure.ac @@ -5098,7 +5098,7 @@ fi # checks for library functions AC_CHECK_FUNCS([ \ accept4 alarm bind_textdomain_codeset chmod chown clock closefrom close_range confstr \ - copy_file_range ctermid dup dup3 execv explicit_bzero explicit_memset \ + copy_file_range ctermid dladdr dup dup3 execv explicit_bzero explicit_memset \ faccessat fchmod fchmodat fchown fchownat fdopendir fdwalk fexecve \ fork fork1 fpathconf fstatat ftime ftruncate futimens futimes futimesat \ gai_strerror getegid geteuid getgid getgrent getgrgid getgrgid_r \ diff --git a/pyconfig.h.in b/pyconfig.h.in index 166c195a8c66fc..45be7556c99bd5 100644 --- a/pyconfig.h.in +++ b/pyconfig.h.in @@ -286,6 +286,9 @@ /* Define if you have the 'dirfd' function or macro. */ #undef HAVE_DIRFD +/* Define to 1 if you have the `dladdr' function. */ +#undef HAVE_DLADDR + /* Define to 1 if you have the header file. */ #undef HAVE_DLFCN_H From f0278af81804dffccf1f80934dedc27dc0f8d40c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filipe=20La=C3=ADns?= Date: Sun, 15 Dec 2024 19:52:00 +0000 Subject: [PATCH 02/12] Add news MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Filipe Laíns Date: Sun, 15 Dec 2024 20:25:34 +0000 Subject: [PATCH 03/12] Fix news path MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Filipe Laíns Core_and_Builtins}/2024-12-15-19-51-54.gh-issue-127970.vdUp-y.rst (100%) diff --git a/Misc/NEWS.d/next/Core and Builtins/2024-12-15-19-51-54.gh-issue-127970.vdUp-y.rst b/Misc/NEWS.d/next/Core_and_Builtins/2024-12-15-19-51-54.gh-issue-127970.vdUp-y.rst similarity index 100% rename from Misc/NEWS.d/next/Core and Builtins/2024-12-15-19-51-54.gh-issue-127970.vdUp-y.rst rename to Misc/NEWS.d/next/Core_and_Builtins/2024-12-15-19-51-54.gh-issue-127970.vdUp-y.rst From aadc56ef21ba3ec6edef9be466d32abe6cd28cd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filipe=20La=C3=ADns?= Date: Sun, 15 Dec 2024 20:32:34 +0000 Subject: [PATCH 04/12] Don't use global variables MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Filipe Laíns Date: Sun, 15 Dec 2024 20:33:21 +0000 Subject: [PATCH 05/12] Remove unnecessary array initialization MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Filipe Laíns Date: Sun, 15 Dec 2024 21:04:45 +0000 Subject: [PATCH 06/12] Move path definition to inside HAVE_DLADDR MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Filipe Laíns Date: Tue, 17 Dec 2024 11:29:44 +0000 Subject: [PATCH 07/12] Rewrite news to frame this as a feature MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Filipe Laíns ` +function defined by the UNIX standard — this includes Linux, Android, macOS, iOS, +FreeBSD, etc. This was already the case on Windows and macOS Framework builds. From 00b1c2dc7f3de930d82a1174fe68ab35aec77205 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filipe=20La=C3=ADns?= Date: Tue, 17 Dec 2024 11:37:55 +0000 Subject: [PATCH 08/12] Fix news formating MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Filipe Laíns ` -function defined by the UNIX standard — this includes Linux, Android, macOS, iOS, -FreeBSD, etc. This was already the case on Windows and macOS Framework builds. +`dladdr `_ +function defined by the UNIX standard — this includes Linux, Android, macOS, +iOS, FreeBSD, etc. This was already the case on Windows and macOS Framework +builds. From ca4a3e36eaa0c472a05ee3884d46380b549c4711 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filipe=20La=C3=ADns?= Date: Tue, 17 Dec 2024 19:38:51 +0000 Subject: [PATCH 09/12] Fix macOS framework builds MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Filipe Laíns Date: Tue, 17 Dec 2024 19:42:59 +0000 Subject: [PATCH 10/12] Fix preprocessor check MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Filipe Laíns Date: Tue, 7 Jan 2025 10:29:09 +0000 Subject: [PATCH 11/12] Skip strncpy MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Filipe Laíns Date: Wed, 8 Jan 2025 11:39:35 +0000 Subject: [PATCH 12/12] Update generated files (make regen-configure) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Filipe Laíns header file. */