R: Problem with OpenSlide Python
Jan Harkes
jaharkes at cs.cmu.edu
Tue Nov 7 17:36:28 EST 2017
What that code is doing is creating a buffer of, w times h, 32-bit integers. The float cast in the modified code made no sense because we don't need a buffer of floats and if we did it would use the proper ctypes type, c_float64 or something similar.
If you are passing floating point values for w and h, you probably end up with a slightly too small memory buffer, f.i. 2.5 * 3 is 7.5, so it rounds to 7 or 8 integers but you actually would need 9. So if you really need to use floating point width and height, make sure to round them up to the next integer value to ensure you don't get buffer overflows and the resulting random memory corruption and crashes.
Jan
On November 7, 2017 4:56:26 PM EST, Francesco Daneluzzi <fdane at live.it> wrote:
>I solved by running OpenSlide on Python 2.7 instead of 3.5. The same
>code now works and w and h are float. I don’t know if this can help
>you. I post you my configuration:
>- Anaconda Python 5.0.1 with 2.7 env (previously 3.5)
>- Windows 10 Edu (x64)
>- OpenSlide 1.1.1 installed from whl
>
>
>
>However, thanks for the answer.
>
>Kind regards,
>Francesco
>
>
>
>________________________________
>Da: Benjamin Gilbert <bgilbert at cs.cmu.edu>
>Inviato: Tuesday, November 7, 2017 9:14:03 PM
>A: openslide-users at lists.andrew.cmu.edu
>Cc: Francesco Daneluzzi
>Oggetto: Re: Problem with OpenSlide Python
>
>On Mon, Nov 06, 2017 at 12:08:04PM +0000, Francesco Daneluzzi wrote:
>> File
>"C:\Users\Francesco\Anaconda3\envs\py35\lib\site-packages\openslide\lowlevel.py",
>line 260, in read_region
>> buf = (w * h * float(c_uint32))()
>> TypeError: float() argument must be a string or a number, not
>'_ctypes.PyCSimpleType'
>>
>> The fact is that, in the last row, w and h are float (I printed them
>for
>> debugging), but c_uint32 is not and I am getting that error. What
>should
>> I do about it?
>
>Hi Francesco,
>
>Are you using a modified version of OpenSlide Python? Upstream
>OpenSlide
>Python 1.1.1 doesn't have that float conversion:
>
>https://github.com/openslide/openslide-python/blob/v1.1.1/openslide/lowlevel.py#L258
>
>Note that w and h must be int, not float.
>
>--Benjamin Gilbert
More information about the openslide-users
mailing list