summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorDonghee Na <donghee.na@python.org>2024-12-19 02:08:17 (GMT)
committerGitHub <noreply@github.com>2024-12-19 02:08:17 (GMT)
commit48c70b8f7dfd00a018abbac50ea987f54fa4db51 (patch)
treecb845fc352998aa71d0a490c346b4c4145b1a6af /Objects
parentf802c8bf872ab882d3056675acc79c950fe5b93c (diff)
downloadcpython-48c70b8f7dfd00a018abbac50ea987f54fa4db51.zip
cpython-48c70b8f7dfd00a018abbac50ea987f54fa4db51.tar.gz
cpython-48c70b8f7dfd00a018abbac50ea987f54fa4db51.tar.bz2
gh-115999: Enable BINARY_SUBSCR_GETITEM for free-threaded build (gh-127737)
Diffstat (limited to 'Objects')
-rw-r--r--Objects/typeobject.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index 2068d6a..7f95b51 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -5679,6 +5679,31 @@ _PyType_CacheInitForSpecialization(PyHeapTypeObject *type, PyObject *init,
return can_cache;
}
+int
+_PyType_CacheGetItemForSpecialization(PyHeapTypeObject *ht, PyObject *descriptor, uint32_t tp_version)
+{
+ if (!descriptor || !tp_version) {
+ return 0;
+ }
+ int can_cache;
+ BEGIN_TYPE_LOCK();
+ can_cache = ((PyTypeObject*)ht)->tp_version_tag == tp_version;
+ // This pointer is invalidated by PyType_Modified (see the comment on
+ // struct _specialization_cache):
+ PyFunctionObject *func = (PyFunctionObject *)descriptor;
+ uint32_t version = _PyFunction_GetVersionForCurrentState(func);
+ can_cache = can_cache && _PyFunction_IsVersionValid(version);
+#ifdef Py_GIL_DISABLED
+ can_cache = can_cache && _PyObject_HasDeferredRefcount(descriptor);
+#endif
+ if (can_cache) {
+ FT_ATOMIC_STORE_PTR_RELEASE(ht->_spec_cache.getitem, descriptor);
+ FT_ATOMIC_STORE_UINT32_RELAXED(ht->_spec_cache.getitem_version, version);
+ }
+ END_TYPE_LOCK();
+ return can_cache;
+}
+
static void
set_flags(PyTypeObject *self, unsigned long mask, unsigned long flags)
{