15
15
#include "pycore_time.h" // _PyTime_ObjectToTime_t()
16
16
#include "pycore_unicodeobject.h" // _PyUnicode_Copy()
17
17
#include "pycore_initconfig.h" // _PyStatus_OK()
18
+ #include "pycore_pyatomic_ft_wrappers.h"
18
19
19
20
#include "datetime.h"
20
21
@@ -2540,14 +2541,16 @@ static Py_hash_t
2540
2541
delta_hash (PyObject * op )
2541
2542
{
2542
2543
PyDateTime_Delta * self = PyDelta_CAST (op );
2543
- if (self -> hashcode == -1 ) {
2544
+ Py_hash_t hash = FT_ATOMIC_LOAD_SSIZE_RELAXED (self -> hashcode );
2545
+ if (hash == -1 ) {
2544
2546
PyObject * temp = delta_getstate (self );
2545
2547
if (temp != NULL ) {
2546
- self -> hashcode = PyObject_Hash (temp );
2548
+ hash = PyObject_Hash (temp );
2549
+ FT_ATOMIC_STORE_SSIZE_RELAXED (self -> hashcode , hash );
2547
2550
Py_DECREF (temp );
2548
2551
}
2549
2552
}
2550
- return self -> hashcode ;
2553
+ return hash ;
2551
2554
}
2552
2555
2553
2556
static PyObject *
@@ -3921,12 +3924,14 @@ static Py_hash_t
3921
3924
date_hash (PyObject * op )
3922
3925
{
3923
3926
PyDateTime_Date * self = PyDate_CAST (op );
3924
- if (self -> hashcode == -1 ) {
3925
- self -> hashcode = generic_hash (
3927
+ Py_hash_t hash = FT_ATOMIC_LOAD_SSIZE_RELAXED (self -> hashcode );
3928
+ if (hash == -1 ) {
3929
+ hash = generic_hash (
3926
3930
(unsigned char * )self -> data , _PyDateTime_DATE_DATASIZE );
3931
+ FT_ATOMIC_STORE_SSIZE_RELAXED (self -> hashcode , hash );
3927
3932
}
3928
3933
3929
- return self -> hashcode ;
3934
+ return hash ;
3930
3935
}
3931
3936
3932
3937
static PyObject *
@@ -5043,7 +5048,8 @@ static Py_hash_t
5043
5048
time_hash (PyObject * op )
5044
5049
{
5045
5050
PyDateTime_Time * self = PyTime_CAST (op );
5046
- if (self -> hashcode == -1 ) {
5051
+ Py_hash_t hash = FT_ATOMIC_LOAD_SSIZE_RELAXED (self -> hashcode );
5052
+ if (hash == -1 ) {
5047
5053
PyObject * offset , * self0 ;
5048
5054
if (TIME_GET_FOLD (self )) {
5049
5055
self0 = new_time_ex2 (TIME_GET_HOUR (self ),
@@ -5065,10 +5071,11 @@ time_hash(PyObject *op)
5065
5071
return -1 ;
5066
5072
5067
5073
/* Reduce this to a hash of another object. */
5068
- if (offset == Py_None )
5069
- self -> hashcode = generic_hash (
5074
+ if (offset == Py_None ) {
5075
+ hash = generic_hash (
5070
5076
(unsigned char * )self -> data , _PyDateTime_TIME_DATASIZE );
5071
- else {
5077
+ FT_ATOMIC_STORE_SSIZE_RELAXED (self -> hashcode , hash );
5078
+ } else {
5072
5079
PyObject * temp1 , * temp2 ;
5073
5080
int seconds , microseconds ;
5074
5081
assert (HASTZINFO (self ));
@@ -5087,12 +5094,13 @@ time_hash(PyObject *op)
5087
5094
Py_DECREF (offset );
5088
5095
return -1 ;
5089
5096
}
5090
- self -> hashcode = PyObject_Hash (temp2 );
5097
+ hash = PyObject_Hash (temp2 );
5098
+ FT_ATOMIC_STORE_SSIZE_RELAXED (self -> hashcode , hash );
5091
5099
Py_DECREF (temp2 );
5092
5100
}
5093
5101
Py_DECREF (offset );
5094
5102
}
5095
- return self -> hashcode ;
5103
+ return hash ;
5096
5104
}
5097
5105
5098
5106
/*[clinic input]
@@ -6627,7 +6635,8 @@ static Py_hash_t
6627
6635
datetime_hash (PyObject * op )
6628
6636
{
6629
6637
PyDateTime_DateTime * self = PyDateTime_CAST (op );
6630
- if (self -> hashcode == -1 ) {
6638
+ Py_hash_t hash = FT_ATOMIC_LOAD_SSIZE_RELAXED (self -> hashcode );
6639
+ if (hash == -1 ) {
6631
6640
PyObject * offset , * self0 ;
6632
6641
if (DATE_GET_FOLD (self )) {
6633
6642
self0 = new_datetime_ex2 (GET_YEAR (self ),
@@ -6652,10 +6661,11 @@ datetime_hash(PyObject *op)
6652
6661
return -1 ;
6653
6662
6654
6663
/* Reduce this to a hash of another object. */
6655
- if (offset == Py_None )
6656
- self -> hashcode = generic_hash (
6664
+ if (offset == Py_None ) {
6665
+ hash = generic_hash (
6657
6666
(unsigned char * )self -> data , _PyDateTime_DATETIME_DATASIZE );
6658
- else {
6667
+ FT_ATOMIC_STORE_SSIZE_RELAXED (self -> hashcode , hash );
6668
+ } else {
6659
6669
PyObject * temp1 , * temp2 ;
6660
6670
int days , seconds ;
6661
6671
@@ -6679,12 +6689,13 @@ datetime_hash(PyObject *op)
6679
6689
Py_DECREF (offset );
6680
6690
return -1 ;
6681
6691
}
6682
- self -> hashcode = PyObject_Hash (temp2 );
6692
+ hash = PyObject_Hash (temp2 );
6693
+ FT_ATOMIC_STORE_SSIZE_RELAXED (self -> hashcode , hash );
6683
6694
Py_DECREF (temp2 );
6684
6695
}
6685
6696
Py_DECREF (offset );
6686
6697
}
6687
- return self -> hashcode ;
6698
+ return hash ;
6688
6699
}
6689
6700
6690
6701
/*[clinic input]
0 commit comments