Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ Unreleased.
- ``'magickernelsharp2013'``
- ``'magickernelsharp2021'``

- Fixed :meth:`Image.length_of_bytes() <wand.image.BaseImage.length_of_bytes>` method
by refactoring & applying :const:`c_magick_size_t <wand.cdefs.wandtypes.c_magick_size_t>`
type. [:issue:`686`]
- [DOC] Fixed typos in documentation [:pull:`685` by Shawn Presser]


Expand Down
4 changes: 2 additions & 2 deletions wand/cdefs/magick_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from ctypes import (CFUNCTYPE, POINTER, c_bool, c_char_p, c_double, c_int,
c_size_t, c_ubyte, c_void_p)

from wand.cdefs.wandtypes import c_ssize_t
from wand.cdefs.wandtypes import c_ssize_t, c_magick_size_t

__all__ = ('MagickProgressMonitor', 'load')

Expand Down Expand Up @@ -545,7 +545,7 @@ def load(lib, IM_VERSION):
c_void_p, POINTER(c_double), POINTER(c_double)
]
lib.MagickGetImageKurtosis.restype = c_bool
lib.MagickGetImageLength.argtypes = [c_void_p, POINTER(c_size_t)]
lib.MagickGetImageLength.argtypes = [c_void_p, POINTER(c_magick_size_t)]
lib.MagickGetImageLength.restype = c_bool
if is_im_7:
lib.MagickGetImageMask.argtypes = [c_void_p, c_int]
Expand Down
10 changes: 5 additions & 5 deletions wand/cdefs/magick_property.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
.. versionadded:: 0.5.0
"""
from ctypes import (POINTER, c_bool, c_char_p, c_double, c_int, c_size_t,
c_ubyte, c_uint, c_ulong, c_ulonglong, c_void_p)
c_ubyte, c_uint, c_ulong, c_void_p)

from wand.cdefs.wandtypes import c_ssize_t
from wand.cdefs.wandtypes import c_ssize_t, c_magick_size_t

__all__ = ('load',)

Expand Down Expand Up @@ -91,9 +91,9 @@ def load(lib, IM_VERSION):
lib.MagickGetPointsize.restype = c_double
lib.MagickGetQuantumRange.argtypes = [POINTER(c_size_t)]
lib.MagickGetResource.argtypes = [c_int]
lib.MagickGetResource.restype = c_ulonglong
lib.MagickGetResource.restype = c_magick_size_t
lib.MagickGetResourceLimit.argtypes = [c_int]
lib.MagickGetResourceLimit.restype = c_ulonglong
lib.MagickGetResourceLimit.restype = c_magick_size_t
lib.MagickGetSamplingFactors.argtypes = [c_void_p, POINTER(c_size_t)]
lib.MagickGetSamplingFactors.restype = POINTER(c_double)
lib.MagickGetSize.argtypes = [c_void_p, POINTER(c_uint), POINTER(c_uint)]
Expand Down Expand Up @@ -172,7 +172,7 @@ def load(lib, IM_VERSION):
lib.MagickSetPointsize.restype = c_bool
lib.MagickSetResolution.argtypes = [c_void_p, c_double, c_double]
lib.MagickSetResolution.restype = c_bool
lib.MagickSetResourceLimit.argtypes = [c_int, c_ulonglong]
lib.MagickSetResourceLimit.argtypes = [c_int, c_magick_size_t]
lib.MagickSetResourceLimit.restype = c_bool
lib.MagickSetSamplingFactors.argtypes = [
c_void_p, c_size_t, POINTER(c_double)
Expand Down
12 changes: 6 additions & 6 deletions wand/cdefs/wandtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"""
import ctypes
import os
import platform
import sys

__all__ = ('c_magick_real_t', 'c_magick_size_t', 'c_ssize_t')
Expand Down Expand Up @@ -34,11 +35,10 @@
del env_real


# FIXME: Might need to rewrite to check against c_void_p size;
# like `c_ssize_t` above, and not against window platform.
if ctypes.sizeof(ctypes.c_size_t) == 8:
c_magick_size_t = ctypes.c_size_t
elif ctypes.sizeof(ctypes.c_ulonglong) == 8:
c_magick_size_t = ctypes.c_ulonglong
if platform.system() != 'Windows':
if ctypes.sizeof(ctypes.c_ulonglong) == 8:
c_magick_size_t = ctypes.c_ulonglong
else:
c_magick_size_t = ctypes.c_size_t
else:
c_magick_size_t = ctypes.c_uint64
3 changes: 2 additions & 1 deletion wand/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from .cdefs.structures import (AffineMatrix, CCObjectInfo, CCObjectInfo70A,
CCObjectInfo710, ChannelFeature, GeometryInfo,
PixelInfo, RectangleInfo)
from .cdefs.wandtypes import c_magick_size_t
from .color import Color
from .compat import binary, encode_filename, text, to_bytes
from .exceptions import (MissingDelegateError, WandException,
Expand Down Expand Up @@ -2067,7 +2068,7 @@ def length_of_bytes(self):

.. versionadded:: 0.5.4
"""
size_ptr = ctypes.c_size_t(0)
size_ptr = c_magick_size_t(0)
library.MagickGetImageLength(self.wand, ctypes.byref(size_ptr))
return size_ptr.value

Expand Down
5 changes: 3 additions & 2 deletions wand/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from collections import abc

from .api import library
from .cdefs.wandtypes import c_magick_size_t
from .exceptions import TYPE_MAP, WandException
from .version import MAGICK_VERSION_NUMBER

Expand Down Expand Up @@ -356,8 +357,8 @@ def set_resource_limit(self, resource, limit):
.. versionadded:: 0.5.1
"""
genesis()
ull = ctypes.c_ulonglong(limit)
library.MagickSetResourceLimit(self._to_idx(resource), ull)
magick_size = c_magick_size_t(limit)
library.MagickSetResourceLimit(self._to_idx(resource), magick_size)


#: (:class:`ResourceLimits`) Helper to get & set Magick Resource Limits.
Expand Down
Loading