mirror of
https://github.com/python/cpython.git
synced 2025-12-07 13:50:06 +00:00
gh-142218: Fix split table dictionary crash (gh-142229)
This fixes a regression introduced in gh-140558. The interpreter would crash if we inserted a non `str` key into a split table that matches an existing key.
This commit is contained in:
parent
618dc36714
commit
547d8daf78
3 changed files with 17 additions and 3 deletions
|
|
@ -1621,6 +1621,14 @@ def __eq__(self, other):
|
||||||
|
|
||||||
self.assertEqual(len(d), 1)
|
self.assertEqual(len(d), 1)
|
||||||
|
|
||||||
|
def test_split_table_update_with_str_subclass(self):
|
||||||
|
class MyStr(str): pass
|
||||||
|
class MyClass: pass
|
||||||
|
obj = MyClass()
|
||||||
|
obj.attr = 1
|
||||||
|
obj.__dict__[MyStr('attr')] = 2
|
||||||
|
self.assertEqual(obj.attr, 2)
|
||||||
|
|
||||||
|
|
||||||
class CAPITest(unittest.TestCase):
|
class CAPITest(unittest.TestCase):
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,2 @@
|
||||||
|
Fix crash when inserting into a split table dictionary with a non
|
||||||
|
:class:`str` key that matches an existing key.
|
||||||
|
|
@ -1914,10 +1914,14 @@ insertdict(PyInterpreterState *interp, PyDictObject *mp,
|
||||||
if (old_value != value) {
|
if (old_value != value) {
|
||||||
_PyDict_NotifyEvent(interp, PyDict_EVENT_MODIFIED, mp, key, value);
|
_PyDict_NotifyEvent(interp, PyDict_EVENT_MODIFIED, mp, key, value);
|
||||||
assert(old_value != NULL);
|
assert(old_value != NULL);
|
||||||
assert(!_PyDict_HasSplitTable(mp));
|
|
||||||
if (DK_IS_UNICODE(mp->ma_keys)) {
|
if (DK_IS_UNICODE(mp->ma_keys)) {
|
||||||
PyDictUnicodeEntry *ep = &DK_UNICODE_ENTRIES(mp->ma_keys)[ix];
|
if (_PyDict_HasSplitTable(mp)) {
|
||||||
STORE_VALUE(ep, value);
|
STORE_SPLIT_VALUE(mp, ix, value);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
PyDictUnicodeEntry *ep = &DK_UNICODE_ENTRIES(mp->ma_keys)[ix];
|
||||||
|
STORE_VALUE(ep, value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
PyDictKeyEntry *ep = &DK_ENTRIES(mp->ma_keys)[ix];
|
PyDictKeyEntry *ep = &DK_ENTRIES(mp->ma_keys)[ix];
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue