Skip to content

Commit b0b8102

Browse files
committed
Lock dict in instance_has_key
1 parent d29b3aa commit b0b8102

File tree

1 file changed

+6
-17
lines changed

1 file changed

+6
-17
lines changed

Python/specialize.c

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,17 +1072,6 @@ specialize_attr_loadclassattr(PyObject *owner, _Py_CODEUNIT *instr,
10721072
static int specialize_class_load_attr(PyObject* owner, _Py_CODEUNIT* instr, PyObject* name);
10731073
#endif
10741074

1075-
static PyDictObject *
1076-
get_managed_dict_ref(PyObject *obj)
1077-
{
1078-
PyDictObject *dict;
1079-
Py_BEGIN_CRITICAL_SECTION(obj);
1080-
dict = _PyObject_GetManagedDict(obj);
1081-
Py_XINCREF(dict);
1082-
Py_END_CRITICAL_SECTION();
1083-
return dict;
1084-
}
1085-
10861075
/* Returns true if instances of obj's class are
10871076
* likely to have `name` in their __dict__.
10881077
* For objects with inline values, we check in the shared keys.
@@ -1101,17 +1090,17 @@ instance_has_key(PyObject *obj, PyObject *name, uint32_t *shared_keys_version)
11011090
_PyDictKeys_StringLookupAndVersion(keys, name, shared_keys_version);
11021091
return index >= 0;
11031092
}
1104-
PyDictObject *dict = get_managed_dict_ref(obj);
1093+
PyDictObject *dict = _PyObject_GetManagedDict(obj);
11051094
if (dict == NULL || !PyDict_CheckExact(dict)) {
1106-
Py_XDECREF(dict);
11071095
return false;
11081096
}
1109-
if (dict->ma_values) {
1110-
Py_DECREF(dict);
1097+
if (FT_ATOMIC_LOAD_PTR(dict->ma_values)) {
11111098
return false;
11121099
}
1113-
Py_ssize_t index = _PyDict_LookupIndex(dict, name);
1114-
Py_DECREF(dict);
1100+
Py_ssize_t index;
1101+
Py_BEGIN_CRITICAL_SECTION(dict);
1102+
index = _PyDict_LookupIndex(dict, name);
1103+
Py_END_CRITICAL_SECTION();
11151104
if (index < 0) {
11161105
return false;
11171106
}

0 commit comments

Comments
 (0)