@@ -4867,6 +4867,12 @@ dict_setdefault_ref_lock_held(PyObject *d, PyObject *key, PyObject *default_valu
48674867
48684868 if (_PyDict_HasSplitTable (mp ) && PyUnicode_CheckExact (key )) {
48694869 ix = insert_split_key (mp -> ma_keys , key , hash );
4870+ #ifdef Py_GIL_DISABLED
4871+ if (!_PyDict_HasSplitTable (mp )) {
4872+ // insert_split_dict re-entered and created a dict
4873+ goto relookup ;
4874+ }
4875+ #endif
48704876 if (ix != DKIX_EMPTY ) {
48714877 PyObject * value = mp -> ma_values -> values [ix ];
48724878 int already_present = value != NULL ;
@@ -4882,6 +4888,9 @@ dict_setdefault_ref_lock_held(PyObject *d, PyObject *key, PyObject *default_valu
48824888 // No space in shared keys. Go to insert_combined_dict() below.
48834889 }
48844890 else {
4891+ #ifdef Py_GIL_DISABLED
4892+ relookup :
4893+ #endif
48854894 ix = _Py_dict_lookup (mp , key , hash , & value );
48864895 if (ix == DKIX_ERROR ) {
48874896 if (result ) {
@@ -7496,27 +7505,15 @@ store_instance_attr_lock_held(PyObject *obj, PyDictValues *values,
74967505
74977506 if (ix == DKIX_EMPTY ) {
74987507#ifdef Py_STATS
7499- if (shared_keys_usable_size (keys ) == SHARED_KEYS_MAX_SIZE ) {
7500- OBJECT_STAT_INC (dict_materialized_too_big );
7501- }
7502- else {
7503- OBJECT_STAT_INC (dict_materialized_new_key );
7504- }
7508+ OBJECT_STAT_INC (dict_materialized_too_big );
75057509#endif
75067510
7507- // Make the dict but don't publish it in the object
7508- // so that no one else will see it.
7509- PyDictObject * dict = make_dict_from_instance_attributes (keys , values );
7510- if (dict == NULL ||
7511+ PyDictObject * dict ;
7512+ if ((dict = _PyObject_MaterializeManagedDict_LockHeld (obj )) == NULL ||
75117513 _PyDict_SetItem_LockHeld (dict , name , value ) < 0 ) {
7512- Py_XDECREF (dict );
75137514 return -1 ;
75147515 }
7515-
7516- FT_ATOMIC_STORE_PTR_RELEASE (_PyObject_ManagedDictPointer (obj )-> dict ,
7517- (PyDictObject * )dict );
75187516 return 0 ;
7519-
75207517 }
75217518
75227519 PyObject * old_value = values -> values [ix ];
0 commit comments