Skip to content

gh-134043: use stackrefs 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

Merged
merged 12 commits into from
Jul 28, 2025
27 changes: 19 additions & 8 deletions Objects/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -1753,16 +1753,27 @@ _PyObject_GetMethodStackRef(PyThreadState *ts, PyObject *obj,
}
}
if (dict != NULL) {
// TODO: use _Py_dict_lookup_threadsafe_stackref
assert(PyUnicode_CheckExact(name));
Py_hash_t hash = _PyObject_HashFast(name);
// cannot fail for exact unicode
assert(hash != -1);
Py_INCREF(dict);
PyObject *value;
if (PyDict_GetItemRef(dict, name, &value) != 0) {
// found or error
Py_DECREF(dict);
// ref is not visible to gc so there should be
// no escaping calls before assigning it to method
_PyStackRef ref;
Py_ssize_t ix = _Py_dict_lookup_threadsafe_stackref((PyDictObject *)dict,
name, hash, &ref);
if (ix == DKIX_ERROR) {
// error
PyStackRef_CLEAR(*method);
if (value != NULL) {
*method = PyStackRef_FromPyObjectSteal(value);
}
Py_DECREF(dict);
return -1;
} else if (!PyStackRef_IsNull(ref)) {
// found
_PyStackRef tmp = *method;
*method = ref;
PyStackRef_XCLOSE(tmp);
Py_DECREF(dict);
return 0;
}
// not found
Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy