@@ -250,6 +250,14 @@ load_keys_nentries(PyDictObject *mp)
250
250
251
251
#endif
252
252
253
+ #define STORE_KEY (ep , key ) FT_ATOMIC_STORE_PTR_RELEASE(ep->me_key, key)
254
+ #define STORE_VALUE (ep , value ) FT_ATOMIC_STORE_PTR_RELEASE(ep->me_value, value)
255
+ #define STORE_SPLIT_VALUE (mp , idx , value ) FT_ATOMIC_STORE_PTR_RELEASE(mp->ma_values->values[idx], value)
256
+ #define STORE_HASH (ep , hash ) FT_ATOMIC_STORE_SSIZE_RELAXED(ep->me_hash, hash)
257
+ #define STORE_KEYS_USABLE (keys , usable ) FT_ATOMIC_STORE_SSIZE_RELAXED(keys->dk_usable, usable)
258
+ #define STORE_KEYS_NENTRIES (keys , nentries ) FT_ATOMIC_STORE_SSIZE_RELAXED(keys->dk_nentries, nentries)
259
+ #define STORE_USED (mp , used ) FT_ATOMIC_STORE_SSIZE_RELAXED(mp->ma_used, used)
260
+
253
261
#define PERTURB_SHIFT 5
254
262
255
263
/*
@@ -1621,7 +1629,6 @@ insert_into_splitdictkeys(PyDictKeysObject *keys, PyObject *name)
1621
1629
return ix ;
1622
1630
}
1623
1631
1624
-
1625
1632
static inline int
1626
1633
insert_combined_dict (PyInterpreterState * interp , PyDictObject * mp ,
1627
1634
Py_hash_t hash , PyObject * key , PyObject * value )
@@ -1639,18 +1646,18 @@ insert_combined_dict(PyInterpreterState *interp, PyDictObject *mp,
1639
1646
if (DK_IS_UNICODE (mp -> ma_keys )) {
1640
1647
PyDictUnicodeEntry * ep ;
1641
1648
ep = & DK_UNICODE_ENTRIES (mp -> ma_keys )[mp -> ma_keys -> dk_nentries ];
1642
- ep -> me_key = key ;
1643
- ep -> me_value = value ;
1649
+ STORE_KEY ( ep , key ) ;
1650
+ STORE_VALUE ( ep , value ) ;
1644
1651
}
1645
1652
else {
1646
1653
PyDictKeyEntry * ep ;
1647
1654
ep = & DK_ENTRIES (mp -> ma_keys )[mp -> ma_keys -> dk_nentries ];
1648
- ep -> me_key = key ;
1649
- ep -> me_hash = hash ;
1650
- ep -> me_value = value ;
1655
+ STORE_KEY ( ep , key ) ;
1656
+ STORE_VALUE ( ep , value ) ;
1657
+ STORE_HASH ( ep , hash ) ;
1651
1658
}
1652
- mp -> ma_keys -> dk_usable -- ;
1653
- mp -> ma_keys -> dk_nentries ++ ;
1659
+ STORE_KEYS_USABLE ( mp -> ma_keys , mp -> ma_keys -> dk_usable - 1 ) ;
1660
+ STORE_KEYS_NENTRIES ( mp -> ma_keys , mp -> ma_keys -> dk_nentries + 1 ) ;
1654
1661
assert (mp -> ma_keys -> dk_usable >= 0 );
1655
1662
return 0 ;
1656
1663
}
@@ -1682,7 +1689,7 @@ insert_split_dict(PyInterpreterState *interp, PyDictObject *mp,
1682
1689
Py_ssize_t index = keys -> dk_nentries ;
1683
1690
_PyDictValues_AddToInsertionOrder (mp -> ma_values , index );
1684
1691
assert (mp -> ma_values -> values [index ] == NULL );
1685
- mp -> ma_values -> values [ index ] = value ;
1692
+ STORE_SPLIT_VALUE ( mp , index , value ) ;
1686
1693
1687
1694
split_keys_entry_added (keys );
1688
1695
assert (keys -> dk_usable >= 0 );
@@ -2013,8 +2020,8 @@ dictresize(PyInterpreterState *interp, PyDictObject *mp,
2013
2020
}
2014
2021
}
2015
2022
2016
- mp -> ma_keys -> dk_usable -= numentries ;
2017
- mp -> ma_keys -> dk_nentries = numentries ;
2023
+ STORE_KEYS_USABLE ( mp -> ma_keys , mp -> ma_keys -> dk_usable - numentries ) ;
2024
+ STORE_KEYS_NENTRIES ( mp -> ma_keys , numentries ) ;
2018
2025
ASSERT_CONSISTENT (mp );
2019
2026
return 0 ;
2020
2027
}
@@ -2507,15 +2514,15 @@ delitem_common(PyDictObject *mp, Py_hash_t hash, Py_ssize_t ix,
2507
2514
if (DK_IS_UNICODE (mp -> ma_keys )) {
2508
2515
PyDictUnicodeEntry * ep = & DK_UNICODE_ENTRIES (mp -> ma_keys )[ix ];
2509
2516
old_key = ep -> me_key ;
2510
- ep -> me_key = NULL ;
2511
- ep -> me_value = NULL ;
2517
+ STORE_KEY ( ep , NULL ) ;
2518
+ STORE_VALUE ( ep , NULL ) ;
2512
2519
}
2513
2520
else {
2514
2521
PyDictKeyEntry * ep = & DK_ENTRIES (mp -> ma_keys )[ix ];
2515
2522
old_key = ep -> me_key ;
2516
- ep -> me_key = NULL ;
2517
- ep -> me_value = NULL ;
2518
- ep -> me_hash = 0 ;
2523
+ STORE_KEY ( ep , NULL ) ;
2524
+ STORE_VALUE ( ep , NULL ) ;
2525
+ STORE_HASH ( ep , 0 ) ;
2519
2526
}
2520
2527
Py_DECREF (old_key );
2521
2528
}
@@ -4393,8 +4400,8 @@ dict_popitem_impl(PyDictObject *self)
4393
4400
PyTuple_SET_ITEM (res , 0 , key );
4394
4401
PyTuple_SET_ITEM (res , 1 , value );
4395
4402
/* We can't dk_usable++ since there is DKIX_DUMMY in indices */
4396
- self -> ma_keys -> dk_nentries = i ;
4397
- self -> ma_used -- ;
4403
+ STORE_KEYS_NENTRIES ( self -> ma_keys , i ) ;
4404
+ STORE_USED ( self , self -> ma_used - 1 ) ;
4398
4405
self -> ma_version_tag = new_version ;
4399
4406
ASSERT_CONSISTENT (self );
4400
4407
return res ;
0 commit comments