From f092b70760fd981847be56437260f97e1e134eaa Mon Sep 17 00:00:00 2001 From: Benedikt Reinartz Date: Mon, 22 Feb 2021 14:13:22 +0100 Subject: [PATCH 1/2] Adjust static libpython detection `dladdr` may only return the basename of the executable image, so we have to adjust the lookup accordingly. --- pythonnet/find_libpython/__init__.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pythonnet/find_libpython/__init__.py b/pythonnet/find_libpython/__init__.py index 185540c8f..a48273fee 100644 --- a/pythonnet/find_libpython/__init__.py +++ b/pythonnet/find_libpython/__init__.py @@ -87,8 +87,11 @@ def _linked_libpython_unix(): ctypes.pointer(dlinfo)) if retcode == 0: # means error return None - path = os.path.realpath(dlinfo.dli_fname.decode()) - if path == os.path.realpath(sys.executable): + path = dlinfo.dli_fname.decode() + + # Compare basenames only, this should always be enough except for very + # pathological cases + if os.path.basename(path) == os.path.basename(os.path.realpath(sys.executable)): return None return path From 2a33bed9b3b7da30fb2a9217733f7977ef26a74f Mon Sep 17 00:00:00 2001 From: Benedikt Reinartz Date: Mon, 22 Feb 2021 14:47:26 +0100 Subject: [PATCH 2/2] Check for Py_ENABLE_SHARED on Unix --- pythonnet/find_libpython/__init__.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/pythonnet/find_libpython/__init__.py b/pythonnet/find_libpython/__init__.py index a48273fee..3ae28970e 100644 --- a/pythonnet/find_libpython/__init__.py +++ b/pythonnet/find_libpython/__init__.py @@ -77,6 +77,9 @@ class Dl_info(ctypes.Structure): def _linked_libpython_unix(): + if not sysconfig.get_config_var("Py_ENABLE_SHARED"): + return None + libdl = ctypes.CDLL(ctypes.util.find_library("dl")) libdl.dladdr.argtypes = [ctypes.c_void_p, ctypes.POINTER(Dl_info)] libdl.dladdr.restype = ctypes.c_int @@ -87,12 +90,7 @@ def _linked_libpython_unix(): ctypes.pointer(dlinfo)) if retcode == 0: # means error return None - path = dlinfo.dli_fname.decode() - - # Compare basenames only, this should always be enough except for very - # pathological cases - if os.path.basename(path) == os.path.basename(os.path.realpath(sys.executable)): - return None + path = os.path.realpath(dlinfo.dli_fname.decode()) return path pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy