@@ -677,6 +677,10 @@ specialize_dict_access_hint(
677677 SPECIALIZATION_FAIL (base_op , SPEC_FAIL_ATTR_SPLIT_DICT );
678678 return 0 ;
679679 }
680+ if (dict -> ma_keys -> dk_kind != DICT_KEYS_UNICODE ) {
681+ SPECIALIZATION_FAIL (base_op , SPEC_FAIL_ATTR_NON_STRING );
682+ return 0 ;
683+ }
680684 Py_ssize_t index = _PyDict_LookupIndex (dict , name );
681685 if (index != (uint16_t )index ) {
682686 SPECIALIZATION_FAIL (base_op ,
@@ -750,10 +754,9 @@ specialize_attr_loadclassattr(PyObject *owner, _Py_CODEUNIT *instr,
750754 uint32_t shared_keys_version );
751755static int specialize_class_load_attr (PyObject * owner , _Py_CODEUNIT * instr , PyObject * name );
752756
753- /* Returns true if instances of obj's class are
754- * likely to have `name` in their __dict__.
755- * For objects with inline values, we check in the shared keys.
756- * For other objects, we check their actual dictionary.
757+ /* Returns true if obj is likely to have `name` in its __dict__.
758+ * For objects with valid inline values, we check in the shared keys.
759+ * Otherwise, we check their actual dictionary.
757760 */
758761static bool
759762instance_has_key (PyObject * obj , PyObject * name , uint32_t * shared_keys_version )
@@ -762,7 +765,8 @@ instance_has_key(PyObject *obj, PyObject *name, uint32_t *shared_keys_version)
762765 if ((cls -> tp_flags & Py_TPFLAGS_MANAGED_DICT ) == 0 ) {
763766 return false;
764767 }
765- if (cls -> tp_flags & Py_TPFLAGS_INLINE_VALUES ) {
768+ if ((cls -> tp_flags & Py_TPFLAGS_INLINE_VALUES ) &&
769+ FT_ATOMIC_LOAD_UINT8 (_PyObject_InlineValues (obj )-> valid )) {
766770 PyDictKeysObject * keys = ((PyHeapTypeObject * )cls )-> ht_cached_keys ;
767771 Py_ssize_t index =
768772 _PyDictKeys_StringLookupAndVersion (keys , name , shared_keys_version );
@@ -1281,14 +1285,14 @@ specialize_attr_loadclassattr(PyObject *owner, _Py_CODEUNIT *instr,
12811285
12821286 unsigned long tp_flags = PyType_GetFlags (owner_cls );
12831287 if (tp_flags & Py_TPFLAGS_INLINE_VALUES ) {
1284- #ifndef Py_GIL_DISABLED
1285- assert (_PyDictKeys_StringLookup (
1286- ((PyHeapTypeObject * )owner_cls )-> ht_cached_keys , name ) < 0 );
1287- #endif
12881288 if (shared_keys_version == 0 ) {
12891289 SPECIALIZATION_FAIL (LOAD_ATTR , SPEC_FAIL_OUT_OF_VERSIONS );
12901290 return 0 ;
12911291 }
1292+ #ifndef Py_GIL_DISABLED
1293+ assert (_PyDictKeys_StringLookup (
1294+ ((PyHeapTypeObject * )owner_cls )-> ht_cached_keys , name ) < 0 );
1295+ #endif
12921296 specialize (instr , is_method ? LOAD_ATTR_METHOD_WITH_VALUES : LOAD_ATTR_NONDESCRIPTOR_WITH_VALUES );
12931297 }
12941298 else {
0 commit comments