@@ -1627,6 +1627,10 @@ insert_combined_dict(PyInterpreterState *interp, PyDictObject *mp, |
1627 | 1627 | } |
1628 | 1628 | } |
1629 | 1629 |
|
| 1630 | + uint64_t new_version = _PyDict_NotifyEvent( |
| 1631 | + interp, PyDict_EVENT_ADDED, mp, key, value); |
| 1632 | + mp->ma_keys->dk_version = 0; |
| 1633 | + |
1630 | 1634 | Py_ssize_t hashpos = find_empty_slot(mp->ma_keys, hash); |
1631 | 1635 | dictkeys_set_index(mp->ma_keys, hashpos, mp->ma_keys->dk_nentries); |
1632 | 1636 |
|
@@ -1643,6 +1647,7 @@ insert_combined_dict(PyInterpreterState *interp, PyDictObject *mp, |
1643 | 1647 | STORE_VALUE(ep, value); |
1644 | 1648 | STORE_HASH(ep, hash); |
1645 | 1649 | } |
| 1650 | + mp->ma_version_tag = new_version; |
1646 | 1651 | STORE_KEYS_USABLE(mp->ma_keys, mp->ma_keys->dk_usable - 1); |
1647 | 1652 | STORE_KEYS_NENTRIES(mp->ma_keys, mp->ma_keys->dk_nentries + 1); |
1648 | 1653 | assert(mp->ma_keys->dk_usable >= 0); |
@@ -1746,15 +1751,11 @@ insertdict(PyInterpreterState *interp, PyDictObject *mp, |
1746 | 1751 |
|
1747 | 1752 | if (ix == DKIX_EMPTY) { |
1748 | 1753 | assert(!_PyDict_HasSplitTable(mp)); |
1749 | | - uint64_t new_version = _PyDict_NotifyEvent( |
1750 | | - interp, PyDict_EVENT_ADDED, mp, key, value); |
1751 | 1754 | /* Insert into new slot. */ |
1752 | | - mp->ma_keys->dk_version = 0; |
1753 | 1755 | assert(old_value == NULL); |
1754 | 1756 | if (insert_combined_dict(interp, mp, hash, key, value) < 0) { |
1755 | 1757 | goto Fail; |
1756 | 1758 | } |
1757 | | - mp->ma_version_tag = new_version; |
1758 | 1759 | STORE_USED(mp, mp->ma_used + 1); |
1759 | 1760 | ASSERT_CONSISTENT(mp); |
1760 | 1761 | return 0; |
@@ -1795,9 +1796,6 @@ insert_to_emptydict(PyInterpreterState *interp, PyDictObject *mp, |
1795 | 1796 | assert(mp->ma_keys == Py_EMPTY_KEYS); |
1796 | 1797 | ASSERT_DICT_LOCKED(mp); |
1797 | 1798 |
|
1798 | | - uint64_t new_version = _PyDict_NotifyEvent( |
1799 | | - interp, PyDict_EVENT_ADDED, mp, key, value); |
1800 | | - |
1801 | 1799 | int unicode = PyUnicode_CheckExact(key); |
1802 | 1800 | PyDictKeysObject *newkeys = new_keys_object( |
1803 | 1801 | interp, PyDict_LOG_MINSIZE, unicode); |
@@ -1806,6 +1804,9 @@ insert_to_emptydict(PyInterpreterState *interp, PyDictObject *mp, |
1806 | 1804 | Py_DECREF(value); |
1807 | 1805 | return -1; |
1808 | 1806 | } |
| 1807 | + uint64_t new_version = _PyDict_NotifyEvent( |
| 1808 | + interp, PyDict_EVENT_ADDED, mp, key, value); |
| 1809 | + |
1809 | 1810 | /* We don't decref Py_EMPTY_KEYS here because it is immortal. */ |
1810 | 1811 | assert(mp->ma_values == NULL); |
1811 | 1812 |
|
@@ -4199,9 +4200,6 @@ dict_setdefault_ref_lock_held(PyObject *d, PyObject *key, PyObject *default_valu |
4199 | 4200 |
|
4200 | 4201 | if (ix == DKIX_EMPTY) { |
4201 | 4202 | assert(!_PyDict_HasSplitTable(mp)); |
4202 | | - uint64_t new_version = _PyDict_NotifyEvent( |
4203 | | - interp, PyDict_EVENT_ADDED, mp, key, default_value); |
4204 | | - mp->ma_keys->dk_version = 0; |
4205 | 4203 | value = default_value; |
4206 | 4204 |
|
4207 | 4205 | if (insert_combined_dict(interp, mp, hash, Py_NewRef(key), Py_NewRef(value)) < 0) { |
@@ -4214,7 +4212,6 @@ dict_setdefault_ref_lock_held(PyObject *d, PyObject *key, PyObject *default_valu |
4214 | 4212 |
|
4215 | 4213 | MAINTAIN_TRACKING(mp, key, value); |
4216 | 4214 | STORE_USED(mp, mp->ma_used + 1); |
4217 | | - mp->ma_version_tag = new_version; |
4218 | 4215 | assert(mp->ma_keys->dk_usable >= 0); |
4219 | 4216 | ASSERT_CONSISTENT(mp); |
4220 | 4217 | if (result) { |
|