Skip to content

Commit

Permalink
Make it easier to reason about thread-safety of instance_has_key
Browse files Browse the repository at this point in the history
  • Loading branch information
mpage committed Jan 2, 2025
1 parent 1870885 commit f1fdcc6
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions Python/specialize.c
Original file line number Diff line number Diff line change
Expand Up @@ -1105,17 +1105,16 @@ instance_has_key(PyObject *obj, PyObject *name, uint32_t *shared_keys_version)
if (dict == NULL || !PyDict_CheckExact(dict)) {
return false;
}
if (FT_ATOMIC_LOAD_PTR(dict->ma_values)) {
return false;
}
Py_ssize_t index;
bool result;
Py_BEGIN_CRITICAL_SECTION(dict);
index = _PyDict_LookupIndex(dict, name);
Py_END_CRITICAL_SECTION();
if (index < 0) {
return false;
if (dict->ma_values) {
result = false;
}
return true;
else {
result = (_PyDict_LookupIndex(dict, name) >= 0);
}
Py_END_CRITICAL_SECTION();
return result;
}

static int
Expand Down

0 comments on commit f1fdcc6

Please sign in to comment.