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: time_hash() reads the wrong bytes to get microseconds
Type: Stage:
Components: Library (Lib) Versions: Python 3.7, Python 3.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: belopolsky, python-dev, vstinner
Priority: normal Keywords: 3.6regression, patch

Created on 2017-01-03 13:57 by vstinner, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
time_hash.patch vstinner, 2017-01-03 13:57 review
check.patch vstinner, 2017-01-03 22:45
Messages (4)
msg284561 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2017-01-03 13:57
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.
msg284596 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2017-01-03 22:45
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.
msg284597 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2017-01-03 22:48
New changeset 72e48ff7b169 by Victor Stinner in branch '3.6':
Issue #29140: Fix hash(datetime.time)
https://hg.python.org/cpython/rev/72e48ff7b169
msg284598 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2017-01-03 22:48
Note: I found this bug while working on the issue #29100.
History
Date User Action Args
2022-04-11 14:58:41adminsetgithub: 73326
2017-02-01 17:15:10vstinnersetstatus: open -> closed
resolution: fixed
2017-01-03 22:48:40vstinnersetmessages: + msg284598
2017-01-03 22:48:19python-devsetnosy: + python-dev
messages: + msg284597
2017-01-03 22:45:29vstinnersetfiles: + check.patch

messages: + msg284596
2017-01-03 14:08:16vstinnersetkeywords: + 3.6regression
2017-01-03 13:57:09vstinnercreate