This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: binascii.crc32() - document signed vs unsigned results
Type: behavior Stage:
Components: Documentation, Library (Lib) Versions: Python 3.0, Python 3.1, Python 2.7, Python 2.6
process
Status: closed Resolution: fixed
Dependencies: 1202 Superseder:
Assigned To: gregory.p.smith Nosy List: beazley, ggenellina, gregory.p.smith, loewis
Priority: normal Keywords:

Created on 2009-01-10 02:57 by beazley, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (10)
msg79524 - (view) Author: David M. Beazley (beazley) Date: 2009-01-10 02:57
The result of binascii.crc32() is different on the same input in Python 
2.6/3.0.  For example:

Python 2.6:

>>> binascii.crc32('Hello')
-137262718

Python 3.0:

>>> binascii.crc32(b'Hello')
4157704578
msg79526 - (view) Author: Gregory P. Smith (gregory.p.smith) * (Python committer) Date: 2009-01-10 03:06
When treated as an unsigned 32bit value those are identical.

Guido prefers to keep Python 2.x always having signed values for the 
scattered crc functions.  We changed it for 3.0 because it makes more 
sense given that python these days no real fixed-bits numeric type.

See also

http://bugs.python.org/issue1202

I posted a workaround in there.  Always & the crc32() or adler32() 
return value with 0xFFFFFFFF.
msg79529 - (view) Author: David M. Beazley (beazley) Date: 2009-01-10 03:16
Can someone PLEASE make sure this gets documented someplace.
msg79534 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2009-01-10 09:24
What is "this" that you want to get documented? Can you propose a
specific wording?
msg79542 - (view) Author: David M. Beazley (beazley) Date: 2009-01-10 12:12
Placing a note in the standard library documentation would be a start.   
Just say in Python 3.0 it always returns the result as an unsigned 
integer whereas in Python 2.6 a 32-bit signed integer is returned. 
Although the numerical value may differ between versions, the underlying 
bits are the same.  Use crc32() & 0xffffffff to get a consistent value 
(already noted).

Note: Not everyone uses checksums in only a packed-binary format.  
Having the integer value just change across Python  versions like that 
is a real subtle compatibility problem to point out.
msg79591 - (view) Author: Gregory P. Smith (gregory.p.smith) * (Python committer) Date: 2009-01-11 07:22
Agreed, we failed to mention the behavior change in the docs.  I'll take 
care of that.  (if its mentioned at all, its mentioned in a note buried 
in the Misc/NEWS file somewhere)

2to3 could presumably be made to notice crc32 and adler32 calls and warn 
about this problem.  I wouldn't have 2to3 add code to re-sign the return 
value by default as not everything needs that but it is worthy of a 
warning.
msg79606 - (view) Author: Gregory P. Smith (gregory.p.smith) * (Python committer) Date: 2009-01-11 18:00
binascii and zlib documentation updated in trunk r68535.  I'll close the 
issue after I've merged it into release26-maint, release30-maint and 
py3k.

Any objections to the wording?

http://svn.python.org/view/python/trunk/Doc/library/binascii.rst?
rev=68535&view=diff&r1=68535&r2=68534&p1=python/trunk/Doc/library/binasc
ii.rst&p2=/python/trunk/Doc/library/binascii.rst
msg79715 - (view) Author: Gabriel Genellina (ggenellina) Date: 2009-01-13 02:21
Just a small note on the wording: "will have" and "will always be" look 
too strong to me. I'd just use is, are. Present tense seems to be --in 
general-- the preferred style in the documentation.
msg80893 - (view) Author: Gregory P. Smith (gregory.p.smith) * (Python committer) Date: 2009-02-01 00:16
wording updated in r69159, thanks.
msg80894 - (view) Author: Gregory P. Smith (gregory.p.smith) * (Python committer) Date: 2009-02-01 00:31
and r69161, r69160, r69162, r69163, r69164.
History
Date User Action Args
2022-04-11 14:56:44adminsetgithub: 49153
2009-02-01 00:31:24gregory.p.smithsetstatus: open -> closed
resolution: fixed
messages: + msg80894
versions: + Python 3.1, Python 2.7
2009-02-01 00:16:22gregory.p.smithsetmessages: + msg80893
2009-01-13 02:21:27ggenellinasetnosy: + ggenellina
messages: + msg79715
2009-01-11 18:00:22gregory.p.smithsetmessages: + msg79606
2009-01-11 07:22:48gregory.p.smithsetstatus: closed -> open
title: binascii.crc32() -> binascii.crc32() - document signed vs unsigned results
messages: + msg79591
priority: normal
assignee: gregory.p.smith
components: + Documentation
resolution: duplicate -> (no value)
2009-01-10 12:12:02beazleysetmessages: + msg79542
2009-01-10 09:24:27loewissetnosy: + loewis
messages: + msg79534
2009-01-10 03:16:22beazleysetmessages: + msg79529
2009-01-10 03:06:59gregory.p.smithsetstatus: open -> closed
resolution: duplicate
dependencies: + zlib.crc32() and adler32() return value
messages: + msg79526
nosy: + gregory.p.smith
2009-01-10 02:57:57beazleycreate