Skip to content

Commit a576748

Browse files
committed
Only cache deferred descriptors
1 parent 5c03db0 commit a576748

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

Python/specialize.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,7 @@ _PyCode_Quicken(_Py_CODEUNIT *instructions, Py_ssize_t size, PyObject *consts,
546546
#define SPEC_FAIL_ATTR_BUILTIN_CLASS_METHOD_OBJ 33
547547
#define SPEC_FAIL_ATTR_METACLASS_OVERRIDDEN 34
548548
#define SPEC_FAIL_ATTR_SPLIT_DICT 35
549+
#define SPEC_FAIL_ATTR_DESCR_NOT_DEFERRED 36
549550

550551
/* Binary subscr and store subscr */
551552

@@ -1498,6 +1499,14 @@ specialize_attr_loadclassattr(PyObject *owner, _Py_CODEUNIT *instr,
14981499

14991500
assert(descr != NULL);
15001501
assert((is_method && kind == METHOD) || (!is_method && kind == NON_DESCRIPTOR));
1502+
1503+
#ifdef Py_GIL_DISABLED
1504+
if (!_PyObject_HasDeferredRefcount(descr)) {
1505+
SPECIALIZATION_FAIL(LOAD_ATTR, SPEC_FAIL_ATTR_DESCR_NOT_DEFERRED);
1506+
return 0;
1507+
}
1508+
#endif
1509+
15011510
if (owner_cls->tp_flags & Py_TPFLAGS_INLINE_VALUES) {
15021511
#ifndef Py_GIL_DISABLED
15031512
PyDictKeysObject *keys = ((PyHeapTypeObject *)owner_cls)->ht_cached_keys;

0 commit comments

Comments
 (0)