1. Python CFFI
  2. Untitled project
  3. cffi
  4. Issues
Issue #54 wontfix

Accept a list of alternative names in ffi.dlopen()

Simon Sapin
created an issue

So, ffi.dlopen('cairo') opens libcairo.so.2 on Linux and ffi.dlopen('libcairo-2') opens libcairo-2.dll on Windows, but I haven’t found a name that works on both. I’ll add something like this to cairocffi:

def dlopen(names):
    for name in names:
        try:
            return ffi.dlopen(name)
        except OSError:
            pass
    ffi.dlopen(names[0])  # Trigger the exception again

cairo = dlopen(['cairo', 'libcairo-2'])  # Maybe add variants for other platforms

It would be nice if ffi.dlopen() could accept a list and do this itself.

Comments (2)

  1. Armin Rigo

    You can also do

    ffi.dlopen('libcairo-2' if sys.platform == 'win32' else 'cairo')
    

    which seems short enough not to warrant this list-of-variants version.

  2. Log in to comment