Skip to content

Commit 98c6edd

Browse files
committed
Put comment back.
1 parent 8422dc7 commit 98c6edd

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

Python/ceval.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4429,7 +4429,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
44294429

44304430
TARGET(LOAD_METHOD_WITH_DICT) {
44314431
/* LOAD_METHOD, with a dict
4432-
Can be either a managed dict, or a tp_dictoffset offset.*/
4432+
Can be either a managed dict, or a tp_dictoffset offset.*/
44334433
assert(cframe.use_tracing == 0);
44344434
PyObject *self = TOP();
44354435
PyTypeObject *self_cls = Py_TYPE(self);

Python/specialize.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,6 +1164,20 @@ _Py_Specialize_LoadMethod(PyObject *owner, _Py_CODEUNIT *instr, PyObject *name,
11641164
*instr = _Py_MAKECODEUNIT(LOAD_METHOD_WITH_DICT, _Py_OPARG(*instr));
11651165
break;
11661166
}
1167+
/* `descr` is borrowed. This is safe for methods (even inherited ones from
1168+
* super classes!) as long as tp_version_tag is validated for two main reasons:
1169+
*
1170+
* 1. The class will always hold a reference to the method so it will
1171+
* usually not be GC-ed. Should it be deleted in Python, e.g.
1172+
* `del obj.meth`, tp_version_tag will be invalidated, because of reason 2.
1173+
*
1174+
* 2. The pre-existing type method cache (MCACHE) uses the same principles
1175+
* of caching a borrowed descriptor. The MCACHE infrastructure does all the
1176+
* heavy lifting for us. E.g. it invalidates tp_version_tag on any MRO
1177+
* modification, on any type object change along said MRO, etc. (see
1178+
* PyType_Modified usages in typeobject.c). The MCACHE has been
1179+
* working since Python 2.6 and it's battle-tested.
1180+
*/
11671181
cache1->tp_version = owner_cls->tp_version_tag;
11681182
cache2->obj = descr;
11691183
// Fall through.

0 commit comments

Comments
 (0)