Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

binascii.crc32() - document signed vs unsigned results #49153

Closed
beazley mannequin opened this issue Jan 10, 2009 · 10 comments
Closed

binascii.crc32() - document signed vs unsigned results #49153

beazley mannequin opened this issue Jan 10, 2009 · 10 comments
Assignees
Labels
docs Documentation in the Doc dir stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@beazley
Copy link
Mannequin

beazley mannequin commented Jan 10, 2009

BPO 4903
Nosy @loewis, @gpshead
Dependencies
  • bpo-1202: zlib.crc32() and adler32() return value
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/gpshead'
    closed_at = <Date 2009-02-01.00:31:24.594>
    created_at = <Date 2009-01-10.02:57:57.000>
    labels = ['type-bug', 'library', 'docs']
    title = 'binascii.crc32() - document signed vs unsigned results'
    updated_at = <Date 2009-02-01.00:31:24.592>
    user = 'https://bugs.python.org/beazley'

    bugs.python.org fields:

    activity = <Date 2009-02-01.00:31:24.592>
    actor = 'gregory.p.smith'
    assignee = 'gregory.p.smith'
    closed = True
    closed_date = <Date 2009-02-01.00:31:24.594>
    closer = 'gregory.p.smith'
    components = ['Documentation', 'Library (Lib)']
    creation = <Date 2009-01-10.02:57:57.000>
    creator = 'beazley'
    dependencies = ['1202']
    files = []
    hgrepos = []
    issue_num = 4903
    keywords = []
    message_count = 10.0
    messages = ['79524', '79526', '79529', '79534', '79542', '79591', '79606', '79715', '80893', '80894']
    nosy_count = 4.0
    nosy_names = ['loewis', 'beazley', 'gregory.p.smith', 'ggenellina']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = None
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue4903'
    versions = ['Python 2.6', 'Python 3.0', 'Python 3.1', 'Python 2.7']

    @beazley
    Copy link
    Mannequin Author

    beazley mannequin commented Jan 10, 2009

    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

    @beazley beazley mannequin added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Jan 10, 2009
    @gpshead
    Copy link
    Member

    gpshead commented Jan 10, 2009

    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.

    @gpshead gpshead closed this as completed Jan 10, 2009
    @beazley
    Copy link
    Mannequin Author

    beazley mannequin commented Jan 10, 2009

    Can someone PLEASE make sure this gets documented someplace.

    @loewis
    Copy link
    Mannequin

    loewis mannequin commented Jan 10, 2009

    What is "this" that you want to get documented? Can you propose a
    specific wording?

    @beazley
    Copy link
    Mannequin Author

    beazley mannequin commented Jan 10, 2009

    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.

    @gpshead
    Copy link
    Member

    gpshead commented Jan 11, 2009

    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.

    @gpshead gpshead added the docs Documentation in the Doc dir label Jan 11, 2009
    @gpshead gpshead reopened this Jan 11, 2009
    @gpshead gpshead changed the title binascii.crc32() binascii.crc32() - document signed vs unsigned results Jan 11, 2009
    @gpshead gpshead self-assigned this Jan 11, 2009
    @gpshead
    Copy link
    Member

    gpshead commented Jan 11, 2009

    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

    @ggenellina
    Copy link
    Mannequin

    ggenellina mannequin commented Jan 13, 2009

    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.

    @gpshead
    Copy link
    Member

    gpshead commented Feb 1, 2009

    wording updated in r69159, thanks.

    @gpshead
    Copy link
    Member

    gpshead commented Feb 1, 2009

    and r69161, r69160, r69162, r69163, r69164.

    @gpshead gpshead closed this as completed Feb 1, 2009
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    docs Documentation in the Doc dir stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant