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

chrisperkins99 at gmail.com chrisperkins99 at gmail.com
Fri Sep 16 01:11:40 CEST 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?
>

You could sort-of fake it like this,

def unsigned(val):
    return struct.unpack('i', struct.pack('I', val))[0]

fcntl.ioctl(self.dev.fileno(), unsigned(0xc0047a80), ...)

but good luck writing a docstring explaining why a function called
"unsigned" takes a positive long and returns a negative int... ;)


Chris Perkins




More information about the Python-list mailing list