Skip to content

Commit e7308c1

Browse files
committed
lowlevel: support libopenslide.so.1 soname
Try loading libopenslide.so.1 or OS-specific equivalent, and fall back to libopenslide.so.0 if missing. Signed-off-by: Benjamin Gilbert <[email protected]>
1 parent 9d06a40 commit e7308c1

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

openslide/lowlevel.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# openslide-python - Python bindings for the OpenSlide library
33
#
44
# Copyright (c) 2010-2013 Carnegie Mellon University
5-
# Copyright (c) 2016-2021 Benjamin Gilbert
5+
# Copyright (c) 2016-2023 Benjamin Gilbert
66
#
77
# This library is free software; you can redistribute it and/or modify it
88
# under the terms of version 2.1 of the GNU Lesser General Public License
@@ -51,9 +51,17 @@
5151

5252

5353
def _load_library():
54+
def try_load(names):
55+
for name in names:
56+
try:
57+
return cdll.LoadLibrary(name)
58+
except OSError:
59+
if name == names[-1]:
60+
raise
61+
5462
if platform.system() == 'Windows':
5563
try:
56-
return cdll.LoadLibrary('libopenslide-0.dll')
64+
return try_load(['libopenslide-1.dll', 'libopenslide-0.dll'])
5765
except FileNotFoundError:
5866
import os
5967

@@ -68,7 +76,7 @@ def _load_library():
6876
)
6977
elif platform.system() == 'Darwin':
7078
try:
71-
return cdll.LoadLibrary('libopenslide.0.dylib')
79+
return try_load(['libopenslide.1.dylib', 'libopenslide.0.dylib'])
7280
except OSError:
7381
# MacPorts doesn't add itself to the dyld search path, but
7482
# does add itself to the find_library() search path
@@ -83,7 +91,7 @@ def _load_library():
8391
)
8492
return cdll.LoadLibrary(lib)
8593
else:
86-
return cdll.LoadLibrary('libopenslide.so.0')
94+
return try_load(['libopenslide.so.1', 'libopenslide.so.0'])
8795

8896

8997
_lib = _load_library()

0 commit comments

Comments
 (0)