[Python-Dev] test_gzip/test_tarfile failure om AMD64
Bob Ippolito
bob at redivi.com
Tue May 30 19:15:48 CEST 2006
On May 30, 2006, at 2:41 AM, Nick Coghlan wrote:
> Bob Ippolito wrote:
>> On May 29, 2006, at 8:00 PM, Tim Peters wrote:
>>> We certainly don't want to see two deprecation warnings for a single
>>> deprecated behavior. I suggest eliminating the "struct integer
>>> wrapping" warning, mostly because I had no idea what it _meant_
>>> before reading the comments in _struct.c ("wrapping" is used most
>>> often in a proxy or delegation context in Python these days). "'B'
>>> format requires 0 <= number <= 255" is perfectly clear all by
>>> itself.
>> What should it be called instead of wrapping? When it says it's
>> wrapping, it means that it's doing x &= (2 ^ (8 * n)) - 1 to force
>> a number into meeting the expected range.
>
> "integer overflow masking" perhaps?
Sounds good enough, I'll go ahead and change the wording to that.
>> Reducing it to one warning instead of two is kinda difficult. Is
>> it worth the trouble?
>
> If there are cases where only one warning or the other triggers, it
> doesn't seem worth the effort to try and suppress one of them when
> they both trigger.
It works kinda like this:
def get_ulong(x):
ulong_mask = (sys.maxint << 1L) | 1
if is_unsigned and ((unsigned)x) > ulong_mask:
x &= ulong_mask
warning('integer overflow masking is deprecated')
return x
def pack_ubyte(x):
x = get_ulong(x)
if not (0 <= x <= 255):
warning("'B' format requires 0 <= number <= 255")
x &= 0xff
return chr(x)
Given the implementation, it will warn twice if sizeof(format) <
sizeof(long) AND one of the following:
1. Negative numbers are given for an unsigned format
2. Input value is greater than ((sys.maxint << 1) | 1) for an
unsigned format
3. Input value is not ((-sys.maxint - 1) <= x <= sys.maxint) for a
signed format
-bob
More information about the Python-Dev
mailing list