10000 gh-134043: use `_Py_dict_lookup_threadsafe_stackref` for dict lookup in `_PyObject_GetMethodStackRef` by kumaraditya303 · Pull Request #136412 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-134043: use _Py_dict_lookup_threadsafe_stackref for dict lookup in _PyObject_GetMethodStackRef #136412

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 27 additions & 11 deletions Objects/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -1753,20 +1753,36 @@ _PyObject_GetMethodStackRef(PyThreadState *ts, PyObject *obj,
}
}
if (dict != NULL) {
// TODO: use _Py_dict_lookup_threadsafe_stackref
Py_INCREF(dict);
PyObject *value;
if (PyDict_GetItemRef(dict, name, &value) != 0) {
// found or error
Py_DECREF(dict);
assert(PyUnicode_CheckExact(name));
Py_hash_t hash = _PyObject_HashFast(name);
// cannot fail for exact unicode
assert(hash != -1);
// ref is not visible to gc so there should be
// no escaping calls before assigning it to method
PyDictObject *mp = (PyDictObject *)dict;
PyDictKeysObject *keys = FT_ATOMIC_LOAD_PTR_ACQUIRE(mp->ma_keys);
bool unicode_keys = DK_IS_UNICODE(keys);
_PyStackRef ref;
if (!unicode_keys) {
Py_INCREF(mp);
}
Py_ssize_t ix = _Py_dict_lookup_threadsafe_stackref(mp, name,
hash, &ref);
if (!unicode_keys) {
Py_DECREF(mp);
}
if (ix == DKIX_ERROR) {
// error
PyStackRef_CLEAR(*method);
if (value != NULL) {
*method = PyStackRef_FromPyObjectSteal(value);
}
return -1;
}
else if (!PyStackRef_IsNull(ref)) {
// found
_PyStackRef tmp = *method;
*method = ref;
PyStackRef_XCLOSE(tmp);
return 0;
}
// not found
Py_DECREF(dict);
}

if (meth_found) {
Expand Down
Loading
0