Skip to content

Commit

Permalink
Various ctypes fixes (#149)
Browse files Browse the repository at this point in the history
* Various ctypes fixes
  • Loading branch information
cgohlke authored Dec 21, 2022
1 parent 90e75e7 commit b67eae3
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions libtiff/libtiff_ctypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
try:
os.chdir(os.path.dirname(__file__))
if os.name == 'nt':
# assume that the directory of libtiff.dll is in PATH.
lib = ctypes.util.find_library('libtiff.dll')
if lib is None:
# Fallback to the old "libtiff3" name
lib = ctypes.util.find_library('libtiff3')
if lib is None:
# assume that the directory of the libtiff DLL is in PATH.
for lib in ('tiff', 'libtiff', 'libtiff3'):
lib = ctypes.util.find_library(lib)
if lib is not None:
break
else:
# try default installation path:
lib = r'C:\Program Files\GnuWin32\bin\libtiff3.dll'
if os.path.isfile(lib):
Expand Down Expand Up @@ -68,6 +68,7 @@
i = libtiff_version_str.lower().split().index(b'version')
assert i != -1, repr(libtiff_version_str.decode())
libtiff_version = libtiff_version_str.split()[i + 1].decode()
libtiff_version_tuple = tuple(int(i) for i in libtiff_version.split('.'))

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


# types defined by tiff.h
class c_ttag_t(ctypes.c_uint):
class c_ttag_t(ctypes.c_uint32):
pass


class c_tdir_t(ctypes.c_uint16):
if libtiff_version_tuple[:2] >= (4, 5):
c_tdir_t_base = ctypes.c_uint32
else:
c_tdir_t_base = ctypes.c_uint16

class c_tdir_t(c_tdir_t_base):
pass


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


class c_tsize_t(ctypes.c_int32):
class c_tsize_t(ctypes.c_ssize_t):
pass


Expand Down

0 comments on commit b67eae3

Please sign in to comment.