Skip to content

Commit afb040a

Browse files
mgornydvarrazzo
authored andcommitted
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.
1 parent 06ef0d9 commit afb040a

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

‎psycopg/psycopg/pq/_pq_ctypes.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ class FILE(Structure):
2929

3030
if sys.platform == "linux":
3131
libcname = ctypes.util.find_library("c")
32-
assert libcname
32+
if not libcname:
33+
# Likely this is a system using musl libc, see the following bug:
34+
# https://github.com/python/cpython/issues/65821
35+
libcname = "libc.so"
3336
libc = ctypes.cdll.LoadLibrary(libcname)
3437

3538
fdopen = libc.fdopen

0 commit comments

Comments
 (0)