]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
fix: add `libc.so` fallback for musl systems to the ctypes impl
authorMichał Górny <mgorny@gentoo.org>
Sat, 27 Jan 2024 14:28:34 +0000 (15:28 +0100)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Mon, 29 Jan 2024 02:24:13 +0000 (02:24 +0000)
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.

psycopg/psycopg/pq/_pq_ctypes.py

index 9ca1d12918f6d18f24d2f3394be8ebc712812e03..cfc68672664fa1599b83202d2cfd1904d9770f0d 100644 (file)
@@ -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