Subject: Re: bug#35371: [core-updates] python-cffi fails its test suite

From: Maxim Cournoyer <[email-masked]>
Date: Sat, 04 May 2019 23:27:33 -0400

Maxim Cournoyer <[email-masked]> writes:

[...]

> _________________________________ test_dlopen __________________________________
>
>     def test_dlopen():
>         ffi = FFI()
>         ffi.cdef("double sin(double x);")
>>       m = ffi.dlopen(lib_m)                           # unicode literal
>
> testing/cffi0/test_unicode_literals.py:65: 
> _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
> cffi/api.py:141: in dlopen
>     lib, function_cache = _make_ffi_library(self, name, flags)
> cffi/api.py:802: in _make_ffi_library
>     backendlib = _load_backend_lib(backend, libname, flags)
> _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
>
> backend = <module '_cffi_backend' from '/tmp/guix-build-python-cffi-1.11.5.drv-0/cffi-1.11.5/build/lib.linux-x86_64-3.7/_cffi_backend.cpython-37m-x86_64-linux-gnu.so'>
> name = 'm', flags = 0
>
>     def _load_backend_lib(backend, name, flags):
>         import os
>         if name is None:
>             if sys.platform != "win32":
>                 return backend.load_library(None, flags)
>             name = "c"    # Windows: load_library(None) fails, but this works
>                           # on Python 2 (backward compatibility hack only)
>         first_error = None
>         if '.' in name or '/' in name or os.sep in name:
>             try:
>                 return backend.load_library(name, flags)
>             except OSError as e:
>                 first_error = e
>         import ctypes.util
>         path = ctypes.util.find_library(name)
>         if path is None:
>             if name == "c" and sys.platform == "win32" and sys.version_info >= (3,):
>                 raise OSError("dlopen(None) cannot work on Windows for Python 3 "
>                               "(see http://bugs.python.org/issue23606)")
>             msg = ("ctypes.util.find_library() did not manage "
>                    "to locate a library called %r" % (name,))
>             if first_error is not None:
>                 msg = "%s.  Additionally, %s" % (first_error, msg)
>>           raise OSError(msg)
> E           OSError: ctypes.util.find_library() did not manage to locate a library called 'm'
>
> cffi/api.py:797: OSError

The problem was caused by find_library not being able to open linker
scripts (it only understands ELF binaries); libm.so is a linker
script. The solution is to replace the shared library references by
their absolute, ELF binary location (e.g., for libm, that is
/gnu/store/...-glibc-2.28/lib/libm.so.6).

Fixed by commit 4e933afda42c41a5425fe460a0ee7ba5435e612b.