gh-132617: Fix dict.update() mutation check#134815
Conversation
Use `ma_used` instead of `ma_keys->dk_nentries` for modification check so that we only check if the dictionary is modified, not if new keys are added to a different dictionary that shared the same keys object.
dict.update() mutation checkdict.update() mutation check
| } | ||
|
|
||
| Py_ssize_t orig_size = other->ma_keys->dk_nentries; | ||
| Py_ssize_t orig_size = other->ma_used; |
There was a problem hiding this comment.
ma_used is too weak. It cannot detect del d["a"]; d["b"] = None.
For better check:
- For all table, check
other->ma_keysis not changed. - For combined table, check
other->ma_keys->dk_nentriesis not changed. - For split table, check
other->ma_values->sizeis not changed.
There was a problem hiding this comment.
It's the same condition we use in iterators and elsewhere. I don't think we should strengthen any of the checks. These are heuristic checks, they're not going to be perfect, but if we decide to do so, I think we should do that in a subsequent PR and not backport that change.
Lines 5169 to 5174 in 469a564
|
Thanks @colesbury for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14. |
Use `ma_used` instead of `ma_keys->dk_nentries` for modification check so that we only check if the dictionary is modified, not if new keys are added to a different dictionary that shared the same keys object. (cherry picked from commit d8994b0) Co-authored-by: Sam Gross <colesbury@gmail.com>
|
Sorry, @colesbury, I could not cleanly backport this to |
|
GH-135581 is a backport of this pull request to the 3.14 branch. |
|
GH-135582 is a backport of this pull request to the 3.13 branch. |
…134815) Use `ma_used` instead of `ma_keys->dk_nentries` for modification check so that we only check if the dictionary is modified, not if new keys are added to a different dictionary that shared the same keys object. (cherry picked from commit d8994b0) Co-authored-by: Sam Gross <colesbury@gmail.com>
…135581) Use `ma_used` instead of `ma_keys->dk_nentries` for modification check so that we only check if the dictionary is modified, not if new keys are added to a different dictionary that shared the same keys object. (cherry picked from commit d8994b0) Co-authored-by: Sam Gross <colesbury@gmail.com>
Use `ma_used` instead of `ma_keys->dk_nentries` for modification check so that we only check if the dictionary is modified, not if new keys are added to a different dictionary that shared the same keys object.
Use `ma_used` instead of `ma_keys->dk_nentries` for modification check so that we only check if the dictionary is modified, not if new keys are added to a different dictionary that shared the same keys object.
Use `ma_used` instead of `ma_keys->dk_nentries` for modification check so that we only check if the dictionary is modified, not if new keys are added to a different dictionary that shared the same keys object.
Use `ma_used` instead of `ma_keys->dk_nentries` for modification check so that we only check if the dictionary is modified, not if new keys are added to a different dictionary that shared the same keys object.
Use
ma_usedinstead ofma_keys->dk_nentriesfor modification check so that we only check if the dictionary is modified, not if new keys are added to a different dictionary that shared the same keys object.dict.update()mutation check too broad #132617