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



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.
.



Relevant Pages

  • Re: 2.3 -> 2.4: long int too large to convert to int
    ... long int too large to convert to int ... How do I tell Python that 0xc0047a80 is an ... > routine fcntl.ioctl is expecting a signed integer. ...
    (comp.lang.python)
  • Re: 2.3 -> 2.4: long int too large to convert to int
    ... long int too large to convert to int ... How do I tell Python that 0xc0047a80 is an ... This is fixed in the 2.5 CVS branch, where the ioctl() Python C wrapper ... expects an unsigned integer instead of a signed one. ...
    (comp.lang.python)
  • Re: a question regarding
    ... On 32-bit platforms (i386, powerpc), int is a 32-bit signed integer ... integer while size_t is a 64-bit unsigned integer. ... changing this structure member from int to size_t will ...
    (freebsd-hackers)
  • Re: Better use of random number genator bits?
    ... This on average is a total of about 2880 bits to shuffle a deck (of course ... Let's choose a random 32-bit unsigned integer and check if it is ... int i, j, n; ... randnum_UL = KISS; ...
    (sci.math)
  • Re: data types
    ... sizeof tells me there are 4 bytes to an int. ... Depending on what you are doing, you might want to consider as an alternative what is generally used where I used to work and generally called with "wrap angles" or BAMs. ... Unsigned integer types are guaranteed by the C standard to wrap. ... There are also various IDEs using gcc. ...
    (comp.lang.c)