]> 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 00:15:41 +0000 (00:15 +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 9d4dd18141886d052228664f62ef38271b8b8499..1b0f391f2df81eea2b506634cca8d1f2a90cf3d3 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