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, haypo, python-dev
Priority: normal Keywords: 3.6regression, patch

Created on 2017-01-03 13:57 by haypo, last changed 2017-02-01 17:15 by haypo. This issue is now closed.

Files
File name Uploaded Description Edit
time_hash.patch haypo, 2017-01-03 13:57 review
check.patch haypo, 2017-01-03 22:45
Messages (4)
msg284561 - (view) Author: STINNER Victor (haypo) * (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 (haypo) * (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) 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 (haypo) * (Python committer) Date: 2017-01-03 22:48
Note: I found this bug while working on the issue #29100.
History
Date User Action Args
2017-02-01 17:15:10hayposetstatus: open -> closed
resolution: fixed
2017-01-03 22:48:40hayposetmessages: + msg284598
2017-01-03 22:48:19python-devsetnosy: + python-dev
messages: + msg284597
2017-01-03 22:45:29hayposetfiles: + check.patch

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