diff options
author | Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com> | 2021-09-17 10:47:36 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-17 10:47:36 (GMT) |
commit | 70bed6f9936c811472b376edd93c37bcf8f06f35 (patch) | |
tree | 7d44f3cd6bbca61a4b827918fdad66e2bc9c5509 /Python/specialize.c | |
parent | b0a6ede3d0bd6fa4ffe413ab4dfc1059201df25b (diff) | |
download | cpython-70bed6f9936c811472b376edd93c37bcf8f06f35.zip cpython-70bed6f9936c811472b376edd93c37bcf8f06f35.tar.gz cpython-70bed6f9936c811472b376edd93c37bcf8f06f35.tar.bz2 |
bpo-45107: Make LOAD_METHOD_CLASS safer and faster, clean up comments (GH-28177)
* Improve comments
* Check cls is a type, remove dict calculation
Diffstat (limited to 'Python/specialize.c')
-rw-r--r-- | Python/specialize.c | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/Python/specialize.c b/Python/specialize.c index 8e04c83..398524c 100644 --- a/Python/specialize.c +++ b/Python/specialize.c @@ -974,20 +974,19 @@ _Py_Specialize_LoadMethod(PyObject *owner, _Py_CODEUNIT *instr, PyObject *name, // Fall through. } // Else owner is maybe a builtin with no dict, or __slots__. Doesn't matter. - /* `descr` is borrowed. Just check tp_version_tag before accessing in case - * it's deleted. This is safe for methods (even inherited ones from super - * classes!) as long as tp_version_tag is validated for two main reasons: + /* `descr` is borrowed. This is safe for methods (even inherited ones from + * super classes!) as long as tp_version_tag is validated for two main reasons: * * 1. The class will always hold a reference to the method so it will * usually not be GC-ed. Should it be deleted in Python, e.g. * `del obj.meth`, tp_version_tag will be invalidated, because of reason 2. * * 2. The pre-existing type method cache (MCACHE) uses the same principles - * of caching a borrowed descriptor. It does all the heavy lifting for us. - * E.g. it invalidates on any MRO modification, on any type object - * change along said MRO, etc. (see PyType_Modified usages in typeobject.c). - * The type method cache has been working since Python 2.6 and it's - * battle-tested. + * of caching a borrowed descriptor. The MCACHE infrastructure does all the + * heavy lifting for us. E.g. it invalidates tp_version_tag on any MRO + * modification, on any type object change along said MRO, etc. (see + * PyType_Modified usages in typeobject.c). The MCACHE has been + * working since Python 2.6 and it's battle-tested. */ cache2->obj = descr; cache1->dk_version_or_hint = keys_version; |