Skip to content

Commit f1fdcc6

Browse files
committed
Make it easier to reason about thread-safety of instance_has_key
1 parent 1870885 commit f1fdcc6

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

Python/specialize.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,17 +1105,16 @@ instance_has_key(PyObject *obj, PyObject *name, uint32_t *shared_keys_version)
11051105
if (dict == NULL || !PyDict_CheckExact(dict)) {
11061106
return false;
11071107
}
1108-
if (FT_ATOMIC_LOAD_PTR(dict->ma_values)) {
1109-
return false;
1110-
}
1111-
Py_ssize_t index;
1108+
bool result;
11121109
Py_BEGIN_CRITICAL_SECTION(dict);
1113-
index = _PyDict_LookupIndex(dict, name);
1114-
Py_END_CRITICAL_SECTION();
1115-
if (index < 0) {
1116-
return false;
1110+
if (dict->ma_values) {
1111+
result = false;
11171112
}
1118-
return true;
1113+
else {
1114+
result = (_PyDict_LookupIndex(dict, name) >= 0);
1115+
}
1116+
Py_END_CRITICAL_SECTION();
1117+
return result;
11191118
}
11201119

11211120
static int

0 commit comments

Comments
 (0)