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

G

Grant Edwards

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?
 
C

Christopher T King

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?

The best way is to tell Python to silence the warning:
-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.
 
M

Michael Hudson

Grant Edwards said:
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?

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

Cheers,
mwh
 
G

Grant Edwards

The best way is to tell Python to silence the warning:

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top