longs where the top bit is set. First, change the masks so that they
are `L' longs, otherwise the sign bits will get propagated to the
result. Next, do not coerce to int before sending to pack_uint()
otherwise Python will generate an OverflowError. Here is a test
program that fails without the patch, but now succeeds:
import xdrlib
addr = (132, 151, 1, 71)
uint = 0L
for a in addr:
uint = (uint << 8) | a
ulong64 = uint << 32
p = xdrlib.Packer()
p.pack_uhyper(ulong64)
buf = p.get_buffer()
u = xdrlib.Unpacker(buf)
ulong64prime = u.unpack_uhyper()
if ulong64 == ulong64prime:
print 'okay'
else:
print 'bogus'
print ulong64, ulong64prime
data formats. The _xdr module is no longer used, since struct
supports the required IEEE floats and doubles.
(I have one doubt about not using _xdr. The struct module doesn't
handle Inf, NaN and gradual underflow correctly. If the _xdr module
does these things better, it may still have a (small) competitive
advantage. On the other hand, since not all platforms support IEEE
floating point, it's not clear that it would be a good idea to ever
transfer Inf or NaNs. Gradual underflow can be fixed in the struct
module.