8000 Ensure compatibility with a single shared libvips library (#444) · libvips/pyvips@c380493 · GitHub
[go: up one dir, main page]

Skip to content

Commit c380493

Browse files
authored
Ensure compatibility with a single shared libvips library (#444)
See: #443
1 parent a9688b9 commit c380493

File tree

1 file changed

+25
-18
lines changed

1 file changed

+25
-18
lines changed

pyvips/__init__.py

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -54,28 +54,35 @@
5454

5555
# yuk
5656
if _is_windows:
57-
_glib_libname = 'libglib-2.0-0.dll'
58-
_gobject_libname = 'libgobject-2.0-0.dll'
59-
_vips_libname = 'libvips-42.dll'
57+
vips_lib = ffi.dlopen('libvips-42.dll')
6058
elif _is_mac:
61-
_glib_libname = None
62-
_vips_libname = 'libvips.42.dylib'
63-
_gobject_libname = 'libgobject-2.0.dylib'
59+
vips_lib = ffi.dlopen('libvips.42.dylib')
6460
else:
65-
_glib_libname = None
66-
_vips_libname = 'libvips.so.42'
67-
_gobject_libname = 'libgobject-2.0.so.0'
68-
69-
# possibly use ctypes.util.find_library() to locate the lib?
70-
gobject_lib = ffi.dlopen(_gobject_libname)
71-
vips_lib = ffi.dlopen(_vips_libname)
72-
if _glib_libname:
73-
glib_lib = ffi.dlopen(_glib_libname)
74-
else:
75-
glib_lib = gobject_lib
61+
vips_lib = ffi.dlopen('libvips.so.42')
7662

7763
logger.debug('Loaded lib %s', vips_lib)
78-
logger.debug('Loaded lib %s', gobject_lib)
64+
65+
if _is_windows:
66+
# On Windows, `GetProcAddress()` can only search in a specified DLL and
67+
# doesn't look into its dependent libraries for symbols. Therefore, we
68+
# check if the GLib DLLs are available. If these can not be found, we
69+
# assume that GLib is statically linked into libvips.
70+
try:
71+
glib_lib = ffi.dlopen('libglib-2.0-0.dll')
72+
gobject_lib = ffi.dlopen('libgobject-2.0-0.dll')
73+
74+
logger.debug('Loaded lib %s', glib_lib)
75+
logger.debug('Loaded lib %s', gobject_lib)
76+
except Exception:
77+
glib_lib = vips_lib
78+
gobject_lib = vips_lib
79+
else:
80+
# macOS and *nix uses `dlsym()`, which also searches for named symbols
81+
# in the dependencies of the shared library. Therefore, we can support
82+
# a single shared libvips library with all dependencies statically
83+
# linked.
84+
glib_lib = vips_lib
85+
gobject_lib = vips_lib
7986

8087
ffi.cdef('''
8188
int vips_init (const char* argv0);

0 commit comments

Comments
 (0)
0