2.3 -> 2.4: long int too large to convert to int

Raymond L. Buvel levub137 at wi.rr.com
Fri Sep 16 07:28:20 EDT 2005


Grant Edwards wrote:
> I give up, how do I make this not fail under 2.4?
> 
>   fcntl.ioctl(self.dev.fileno(),0xc0047a80,struct.pack("HBB",0x1c,0x00,0x00))
> 
> I get an OverflowError: long int too large to convert to int
> 
> ioctl() is expecting a 32-bit integer value, and 0xc0047a80 has
> the high-order bit set.  I'm assuming Python thinks it's a
> signed value.  How do I tell Python that 0xc0047a80 is an
> unsigned 32-bit value?
>   
Everyone seems to be suggesting that the fix for the problem is to
somehow cobble together some way of forcing an unsigned integer into a
signed integer (what you would do with a cast in C).  However, if I
understand the long<->int consolidation this is not consistent with that
effort.

As far as I can tell, the underlying problem is that the C routine
fcntl.ioctl is expecting a signed integer.  These are the kinds of
problems that need to be fixed.  The function should be asking for an
unsigned integer.  This is possible with the C API at least since Python
2.3.  Without these fixes, the long<->int consolidation is going to
continue to produce frustration.  There are many functions in the
standard library that you would expect to take unsigned integers but
actually specify signed integers.



More information about the Python-list mailing list