[PyQt] Bug in sip.voidptr?

Phil Thompson phil at riverbankcomputing.com
Sat Dec 11 09:54:29 GMT 2010

On Fri, 10 Dec 2010 15:56:23 -0500, Nathan Weston <nathan at genarts.com>
> I think I've found a bug when constructing sip.voidptr from an integer. 
> This statement:
> sip.voidptr(2**31)
> raises an exception: TypeError: a single integer, Capsule, CObject, None

> or another voidptr is required
> The problem appears to be at voidptr.c:568
> ptr = (void *)PyInt_AsLong(arg)
> Python integers are signed, so 2**31 isn't a valid int (even though it's

> a valid 32-bit pointer), thus the cast fails. Values smaller than 2**31 
> work fine. I was able to fix the problem by changing the cast to this:
> ptr = (void *)PyLong_AsUnsignedLong(arg);
> I'm not sure if this handles all overflows correctly (since a Python 
> long can be larger than 2**32), but it works for me.
> Versions:
> Centos 5  (64-bit)
> Python 2.6.6 (32-bit)
> sip 4.11.1

I've changed it to use PyLong_AsVoidPtr() which (for some reason) I had
thought was Python v3 only.


More information about the PyQt mailing list