From: Michał Górny Date: Sat, 27 Jan 2024 14:28:34 +0000 (+0100) Subject: fix: add `libc.so` fallback for musl systems to the ctypes impl X-Git-Tag: 3.1.18~5^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=afb040a800b2667a07dc441e8cdb94e55a0dcf65;p=thirdparty%2Fpsycopg.git fix: add `libc.so` fallback for musl systems to the ctypes impl Add a fallback to `libc.so` library name to fix loading the ctypes implementation on musl systems. On musl, `find_library("c")` does not work (the problem has been reported to CPython in 2014, and has not been resolved yet), causing the module to fail on `assert libcname`. Instead, add a fallback to using `libc.so` and let ctypes raise an exception if such a library does not exist. --- diff --git a/psycopg/psycopg/pq/_pq_ctypes.py b/psycopg/psycopg/pq/_pq_ctypes.py index 9ca1d1291..cfc686726 100644 --- a/psycopg/psycopg/pq/_pq_ctypes.py +++ b/psycopg/psycopg/pq/_pq_ctypes.py @@ -29,7 +29,10 @@ FILE_ptr = POINTER(FILE) if sys.platform == "linux": libcname = ctypes.util.find_library("c") - assert libcname + if not libcname: + # Likely this is a system using musl libc, see the following bug: + # https://github.com/python/cpython/issues/65821 + libcname = "libc.so" libc = ctypes.cdll.LoadLibrary(libcname) fdopen = libc.fdopen