python / cpython

The Python programming language
https://www.python.org/
Other
60k stars 29.04k forks source link

fix hashing #32427

Closed bdaf8532-ded6-4d4c-9bb3-51fd76040dc1 closed 23 years ago

bdaf8532-ded6-4d4c-9bb3-51fd76040dc1 commented 23 years ago
BPO 400503
Nosy @gvanrossum, @tim-one, @freddrake
Files
  • None: None
  • 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: ```python assignee = 'https://github.com/freddrake' closed_at = created_at = labels = [] title = 'fix hashing' updated_at = user = 'https://bugs.python.org/tmick' ``` bugs.python.org fields: ```python activity = actor = 'fdrake' assignee = 'fdrake' closed = True closed_date = None closer = None components = ['None'] creation = creator = 'tmick' dependencies = [] files = ['2435'] hgrepos = [] issue_num = 400503 keywords = ['patch'] message_count = 8.0 messages = ['32676', '32677', '32678', '32679', '32680', '32681', '32682', '32683'] nosy_count = 4.0 nosy_names = ['gvanrossum', 'tim.peters', 'fdrake', 'tmick'] pr_nums = [] priority = 'normal' resolution = None stage = None status = 'closed' superseder = None type = None url = 'https://bugs.python.org/issue400503' versions = [] ```

    bdaf8532-ded6-4d4c-9bb3-51fd76040dc1 commented 23 years ago
    freddrake commented 23 years ago

    Applied verbatim; patch to PC/winreg.c applied to PC/_winreg.c due to name change.

    gvanrossum commented 23 years ago

    just testing the SF patch manager

    gvanrossum commented 23 years ago

    Tim, please review! Then assign to Trent if it's OK to commit.

    tim-one commented 23 years ago

    Changed to Accepted, assigned back to Trent for commit.

    Looks good, Trent! My only gripe is about the hash function for complex numbers (because it's symmetric), but that problem existed before and you haven't made it any worse. Ship it (I'll improve the complex hash later).

    tim-one commented 23 years ago

    Changed to Accepted, assigned back to Trent for commit.

    Looks good, Trent! My only gripe is about the hash function for complex numbers (because it's symmetric), but that problem existed before and you haven't made it any worse. Ship it (I'll improve the complex hash later).

    bdaf8532-ded6-4d4c-9bb3-51fd76040dc1 commented 23 years ago

    This patch addresses two main issues: (1) There exist some non-fatal errors in some of the hash algorithms. For exmaple, in float_hash and complex_hash a certain part of the value is not included in the hash calculation. See Tim's, Guido's, and my discussion of this on python-dev in May under the title "fix float_hash and complex_hash for 64-bit *nix"

    (2) The hash algorithms that use pointers (e.g. func_hash, code_hash) are universally not correct on Win64 (they assume that sizeof(long) == sizeof(void*))

    As well, this patch significantly cleans up the hash code. It adds the two function _Py_HashDouble and _PyHash_VoidPtr that the various hashing routine are changed to use.

    These help maintain the hash function invariant: (a==b) => (hash(a)==hash(b))) I have added Lib/test/test_hash.py and Lib/test/output/test_hash to test this for some cases.

    bdaf8532-ded6-4d4c-9bb3-51fd76040dc1 commented 23 years ago

    I confirm that, to the best of my knowledge and belief, this contribution is free of any claims of third parties under copyright, patent or other rights or interests ("claims"). To the extent that I have any such claims, I hereby grant to CNRI a nonexclusive, irrevocable, royalty-free, worldwide license to reproduce, distribute, perform and/or display publicly, prepare derivative versions, and otherwise use this contribution as part of the Python software and its related documentation, or any derivative versions thereof, at no cost to CNRI or its licensed users, and to authorize others to do so.

    I acknowledge that CNRI may, at its sole discretion, decide whether or not to incorporate this contribution in the Python software and its related documentation. I further grant CNRI permission to use my name and other identifying information provided to CNRI by me for use in connection with the Python software and its related documentation.