@@ -1882,13 +1882,7 @@ insertdict(PyInterpreterState *interp, PyDictObject *mp,
18821882
18831883 ASSERT_DICT_LOCKED (mp );
18841884
1885- if (DK_IS_UNICODE (mp -> ma_keys ) && !PyUnicode_CheckExact (key )) {
1886- if (insertion_resize (mp , 0 ) < 0 )
1887- goto Fail ;
1888- assert (mp -> ma_keys -> dk_kind == DICT_KEYS_GENERAL );
1889- }
1890-
1891- if (_PyDict_HasSplitTable (mp )) {
1885+ if (_PyDict_HasSplitTable (mp ) && PyUnicode_CheckExact (key )) {
18921886 Py_ssize_t ix = insert_split_key (mp -> ma_keys , key , hash );
18931887 if (ix != DKIX_EMPTY ) {
18941888 insert_split_value (interp , mp , key , value , ix );
@@ -1908,9 +1902,10 @@ insertdict(PyInterpreterState *interp, PyDictObject *mp,
19081902 goto Fail ;
19091903
19101904 if (ix == DKIX_EMPTY ) {
1911- assert (!_PyDict_HasSplitTable (mp ));
1912- /* Insert into new slot. */
1913- assert (old_value == NULL );
1905+ // insert_combined_dict() will convert from non DICT_KEYS_GENERAL table
1906+ // into DICT_KEYS_GENERAL table if key is not Unicode.
1907+ // We don't convert it before _Py_dict_lookup because non-Unicode key
1908+ // may change generic table into Unicode/split table.
19141909 if (insert_combined_dict (interp , mp , hash , key , value ) < 0 ) {
19151910 goto Fail ;
19161911 }
@@ -4417,16 +4412,7 @@ dict_setdefault_ref_lock_held(PyObject *d, PyObject *key, PyObject *default_valu
44174412 return 0 ;
44184413 }
44194414
4420- if (!PyUnicode_CheckExact (key ) && DK_IS_UNICODE (mp -> ma_keys )) {
4421- if (insertion_resize (mp , 0 ) < 0 ) {
4422- if (result ) {
4423- * result = NULL ;
4424- }
4425- return -1 ;
4426- }
4427- }
4428-
4429- if (_PyDict_HasSplitTable (mp )) {
4415+ if (_PyDict_HasSplitTable (mp ) && PyUnicode_CheckExact (key )) {
44304416 Py_ssize_t ix = insert_split_key (mp -> ma_keys , key , hash );
44314417 if (ix != DKIX_EMPTY ) {
44324418 PyObject * value = mp -> ma_values -> values [ix ];
@@ -4447,8 +4433,6 @@ dict_setdefault_ref_lock_held(PyObject *d, PyObject *key, PyObject *default_valu
44474433 }
44484434 }
44494435
4450- assert (!_PyDict_HasSplitTable (mp ));
4451-
44524436 Py_ssize_t ix = _Py_dict_lookup (mp , key , hash , & value );
44534437 if (ix == DKIX_ERROR ) {
44544438 if (result ) {
@@ -4458,7 +4442,6 @@ dict_setdefault_ref_lock_held(PyObject *d, PyObject *key, PyObject *default_valu
44584442 }
44594443
44604444 if (ix == DKIX_EMPTY ) {
4461- assert (!_PyDict_HasSplitTable (mp ));
44624445 value = default_value ;
44634446
44644447 if (insert_combined_dict (interp , mp , hash , Py_NewRef (key ), Py_NewRef (value )) < 0 ) {
0 commit comments