Skip to content

gh-134043: use _Py_dict_lookup_unicode_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 9 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
avoid incref/decref for unicode keys dict
  • Loading branch information
kumaraditya303 committed Jul 9, 2025
commit e4c36a8c23733bb9d461bfc3a8c5b64a3d5c3db2
17 changes: 10 additions & 7 deletions Objects/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -1757,27 +1757,30 @@
Py_hash_t hash = _PyObject_HashFast(name);
// cannot fail for exact unicode
assert(hash != -1);
Py_INCREF(dict);
// ref is not visible to gc so there should be
// no escaping calls before assigning it to method
PyDictObject *mp = (PyDictObject *)dict;
bool unicode_keys = DK_IS_UNICODE(FT_ATOMIC_LOAD_PTR_ACQUIRE(mp->ma_keys));

Check failure on line 1763 in Objects/object.c

View workflow job for this annotation

GitHub Actions / Windows (free-threading) / Build and test (x64)

left of '->dk_kind' must point to struct/union [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]
_PyStackRef ref;
Py_ssize_t ix = _Py_dict_lookup_threadsafe_stackref((PyDictObject *)dict,
name, hash, &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);
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
Py_DECREF(dict);
}

if (meth_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