[Python-checkins] python/dist/src/Lib/test test_socket.py,1.55,1.56

Guido van Rossum guido@python.org
Mon, 12 Aug 2002 20:24:59 -0400


>   GvR> Modified Files:
>   GvR> 	test_socket.py
>   GvR> Log Message: Don't use hex constants representing negative
>   GvR> numbers.
> 
> The test in question won't work quite the same anymore.

On 32-bit platforms it will: 0xffff0000 is the same value as ~0xffff
there.

There were no comments in the code indicating whether the test was
ever tried on a 64-bit platform.

> I can't really tell if that matters, but it will now test something
> different on platforms with 64-bit ints, right?

Yes; on a 64-bit platform, it would check whether 4294901760 would be
converted into itself (this is hex 0xffff0000 seen as an unsigned).

> The C functions being wrapped by the socket module takes 32-bit
> unsigned ints.  I wanted to pass the bits that would represent the
> unsigned long with the upper half of the bits set.

Does the test have to test for a number with the high bit set?  You
can portably test what it does for e.g. 0x7fff0000.

Also, perhaps the function could be defined better?  On a 32-bit
platform it can now return a negative value, but on a 64-bit platform
it cannot.  Maybe it should return a positive Python long on a 32-bit
platform when the high bit of the result is set?

--Guido van Rossum (home page: http://www.python.org/~guido/)