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

time_hash() reads the wrong bytes to get microseconds #73326

Closed
vstinner opened this issue Jan 3, 2017 · 4 comments
Closed

time_hash() reads the wrong bytes to get microseconds #73326

vstinner opened this issue Jan 3, 2017 · 4 comments
Labels
3.7 (EOL) end of life stdlib Python modules in the Lib dir

Comments

@vstinner
Copy link
Member

vstinner commented Jan 3, 2017

BPO 29140
Nosy @abalkin, @vstinner
Files
  • time_hash.patch
  • check.patch
  • 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 = None
    closed_at = <Date 2017-02-01.17:15:10.446>
    created_at = <Date 2017-01-03.13:57:09.547>
    labels = ['3.7', 'library']
    title = 'time_hash() reads the wrong bytes to get microseconds'
    updated_at = <Date 2017-02-01.17:15:10.445>
    user = 'https://github.com/vstinner'

    bugs.python.org fields:

    activity = <Date 2017-02-01.17:15:10.445>
    actor = 'vstinner'
    assignee = 'none'
    closed = True
    closed_date = <Date 2017-02-01.17:15:10.446>
    closer = 'vstinner'
    components = ['Library (Lib)']
    creation = <Date 2017-01-03.13:57:09.547>
    creator = 'vstinner'
    dependencies = []
    files = ['46123', '46130']
    hgrepos = []
    issue_num = 29140
    keywords = ['patch', '3.6regression']
    message_count = 4.0
    messages = ['284561', '284596', '284597', '284598']
    nosy_count = 3.0
    nosy_names = ['belopolsky', 'vstinner', 'python-dev']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = None
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue29140'
    versions = ['Python 3.6', 'Python 3.7']

    @vstinner
    Copy link
    Member Author

    vstinner commented Jan 3, 2017

    When the time is folded, time_hash() uses DATE_xxx() macros, instead of TIME_xxx() macros, and so reads microseconds from the wrong bytes.

    Bug introduced by the implementation of the PEP-495 (Local Time Disambiguation).

    #define PyDateTime_DATE_GET_MICROSECOND(o)              \
        ((((PyDateTime_DateTime*)o)->data[7] << 16) |       \
         (((PyDateTime_DateTime*)o)->data[8] << 8)  |       \
          ((PyDateTime_DateTime*)o)->data[9])
    
    #define PyDateTime_TIME_GET_MICROSECOND(o)              \
        ((((PyDateTime_Time*)o)->data[3] << 16) |           \
         (((PyDateTime_Time*)o)->data[4] << 8)  |           \
          ((PyDateTime_Time*)o)->data[5])

    Attached patch fixes time_hash().

    I guess that it's a dummy copy-paste issue.

    @vstinner vstinner added 3.7 (EOL) end of life stdlib Python modules in the Lib dir labels Jan 3, 2017
    @vstinner
    Copy link
    Member Author

    vstinner commented Jan 3, 2017

    I used attached check.patch to check if macros are misused in other functions. Hopefully, only time_hash() has bugs.

    I don't think that it's worth it to apply check.patch, I dislike such complex macro.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Jan 3, 2017

    New changeset 72e48ff7b169 by Victor Stinner in branch '3.6':
    Issue bpo-29140: Fix hash(datetime.time)
    https://hg.python.org/cpython/rev/72e48ff7b169

    @vstinner
    Copy link
    Member Author

    vstinner commented Jan 3, 2017

    Note: I found this bug while working on the issue bpo-29100.

    @vstinner vstinner closed this as completed Feb 1, 2017
    @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
    3.7 (EOL) end of life stdlib Python modules in the Lib dir
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant