How to get rid of "hex/oct constants > sys.maxint" warning?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Grant Edwards

    How to get rid of "hex/oct constants > sys.maxint" warning?

    I'm getting tired of seeing meaningless warnings from my code,
    but I can't figure out how to get rid of them:

    For example:

    fcntl.ioctl(fd, 0xc0047a80,s) causes

    FutureWarning: hex/oct constants > sys.maxint will return
    positive values in Python 2.4 and up

    Firstly, I have no idea what that error means in this context.
    0xc0047a80 isn't intended to be an integer (either positive or
    negative): it's just a chunk of 32 bits.

    Googling the newsgroup came up with the suggestion that putting
    an "L" on the end of the constant would eliminate the warning,
    but it causes an error:

    fcntl.ioctl(fd, 0xc0047a80L,s) causes

    OverflowError: long int too large to convert to int

    So, that doesn't work.

    How _do_ I get rid of the warning? Is there a way to tell
    Python that the constant isn't an integer, it's just a bit
    pattern?

    --
    Grant Edwards grante Yow! Mr and Mrs PED, can
    at I borrow 26.7
    visi.com
  • Christopher T King

    #2
    Re: How to get rid of "hex/oct constants > sys.maxint&quot ; warning?

    On 11 Aug 2004, Grant Edwards wrote:
    [color=blue]
    > How _do_ I get rid of the warning? Is there a way to tell
    > Python that the constant isn't an integer, it's just a bit
    > pattern?[/color]

    The best way is to tell Python to silence the warning:
    [color=blue][color=green][color=darkred]
    >>> 0xc0047a80[/color][/color][/color]
    FutureWarning[color=blue][color=green][color=darkred]
    >>> import warnings
    >>> warnings.simple filter('ignore' ,FutureWarning)
    >>> 0xc0047a80[/color][/color][/color]
    -1073448320

    fcntl() doesn't really care what it gets, so long as it can convert it to
    a 32-bit value, something it can't do with a long integer. In 2.3,
    0xc0047a80 returns a negative integer, which is acceptable to fcntl(). In
    2.4, it's going to return a long integer -- presumably fcntl() will also
    be able to accept long integers.

    Comment

    • Michael Hudson

      #3
      Re: How to get rid of "hex/oct constants > sys.maxint&quot ; warning?

      Grant Edwards <grante@visi.co m> writes:
      [color=blue]
      > I'm getting tired of seeing meaningless warnings from my code,
      > but I can't figure out how to get rid of them:
      >
      > For example:
      >
      > fcntl.ioctl(fd, 0xc0047a80,s) causes
      >
      > FutureWarning: hex/oct constants > sys.maxint will return
      > positive values in Python 2.4 and up
      >
      > Firstly, I have no idea what that error means in this context.
      > 0xc0047a80 isn't intended to be an integer (either positive or
      > negative): it's just a chunk of 32 bits.
      >
      > Googling the newsgroup came up with the suggestion that putting
      > an "L" on the end of the constant would eliminate the warning,
      > but it causes an error:
      >
      > fcntl.ioctl(fd, 0xc0047a80L,s) causes
      >
      > OverflowError: long int too large to convert to int
      >
      > So, that doesn't work.
      >
      > How _do_ I get rid of the warning? Is there a way to tell
      > Python that the constant isn't an integer, it's just a bit
      > pattern?[/color]

      It's horrible, but ~int(~0xc0047a8 0L&0xFFFFFFFFL ) will work.

      Cheers,
      mwh

      --
      I love the way Microsoft follows standards. In much the same
      manner that fish follow migrating caribou. -- Paul Tomblin
      -- http://home.xnet.com/~raven/Sysadmin/ASR.Quotes.html

      Comment

      • Grant Edwards

        #4
        Re: How to get rid of &quot;hex/oct constants &gt; sys.maxint&quot ; warning?

        On 2004-08-11, Christopher T King <squirrel@WPI.E DU> wrote:
        [color=blue][color=green]
        >> How _do_ I get rid of the warning? Is there a way to tell
        >> Python that the constant isn't an integer, it's just a bit
        >> pattern?[/color]
        >
        > The best way is to tell Python to silence the warning:
        >[color=green][color=darkred]
        >>>> 0xc0047a80[/color][/color]
        > FutureWarning[color=green][color=darkred]
        >>>> import warnings
        >>>> warnings.simple filter('ignore' ,FutureWarning)[/color][/color][/color]

        Yup, that's what I was looking for. Now that I know how it's
        spelled, Google find's plenty of examples. :)


        --
        Grant Edwards grante Yow! Yow! Am I cleansed
        at yet?!
        visi.com

        Comment

        Working...