Skip to content

Commit b67eae3

Browse files
authored
Various ctypes fixes (#149)
* Various ctypes fixes
1 parent 90e75e7 commit b67eae3

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

libtiff/libtiff_ctypes.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@
2323
try:
2424
os.chdir(os.path.dirname(__file__))
2525
if os.name == 'nt':
26-
# assume that the directory of libtiff.dll is in PATH.
27-
lib = ctypes.util.find_library('libtiff.dll')
28-
if lib is None:
29-
# Fallback to the old "libtiff3" name
30-
lib = ctypes.util.find_library('libtiff3')
31-
if lib is None:
26+
# assume that the directory of the libtiff DLL is in PATH.
27+
for lib in ('tiff', 'libtiff', 'libtiff3'):
28+
lib = ctypes.util.find_library(lib)
29+
if lib is not None:
30+
break
31+
else:
3232
# try default installation path:
3333
lib = r'C:\Program Files\GnuWin32\bin\libtiff3.dll'
3434
if os.path.isfile(lib):
@@ -68,6 +68,7 @@
6868
i = libtiff_version_str.lower().split().index(b'version')
6969
assert i != -1, repr(libtiff_version_str.decode())
7070
libtiff_version = libtiff_version_str.split()[i + 1].decode()
71+
libtiff_version_tuple = tuple(int(i) for i in libtiff_version.split('.'))
7172

7273
tiff_h_name = 'tiff_h_%s' % (libtiff_version.replace('.', '_'))
7374
try:
@@ -182,11 +183,16 @@ def _generate_lines_without_continuations(file_obj):
182183

183184

184185
# types defined by tiff.h
185-
class c_ttag_t(ctypes.c_uint):
186+
class c_ttag_t(ctypes.c_uint32):
186187
pass
187188

188189

189-
class c_tdir_t(ctypes.c_uint16):
190+
if libtiff_version_tuple[:2] >= (4, 5):
191+
c_tdir_t_base = ctypes.c_uint32
192+
else:
193+
c_tdir_t_base = ctypes.c_uint16
194+
195+
class c_tdir_t(c_tdir_t_base):
190196
pass
191197

192198

@@ -202,7 +208,7 @@ class c_ttile_t(ctypes.c_uint32):
202208
pass
203209

204210

205-
class c_tsize_t(ctypes.c_int32):
211+
class c_tsize_t(ctypes.c_ssize_t):
206212
pass
207213

208214

0 commit comments

Comments
 (0)