-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
bpo-33930: Fix segfault with deep recursion when cleaning method objects #27678
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. But I have a few minor comments.
…ng method objects
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
@@ -160,7 +160,10 @@ PyCMethod_GetClass(PyObject *op) | |||
static void | |||
meth_dealloc(PyCFunctionObject *m) | |||
{ | |||
_PyObject_GC_UNTRACK(m); | |||
// The Py_TRASHCAN mechanism requires that we be able to | |||
// call PyObject_GC_UnTrack twice on an object. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand that, but thanks for the comment!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tim-one added this comment in 803526b but the original change is by @nascheme, committed by @gvanrossum in ff413af with the following description:
This is Neil's fix for SF bug 535905 (Evil Trashcan and GC interaction).
The fix makes it possible to call PyObject_GC_UnTrack() more than once
on the same object, and then move the PyObject_GC_UnTrack() call to
*before* the trashcan code is invoked.
The "SF bug" is also available on BPO: https://bugs.python.org/issue535905
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the comment is unclear, maybe we should try to improve it. I believe the main point is that, since the object uses the trashcan, the function version of untrack is used rather than the macro version. The macro is not safe to call twice because it assumes the object is a part of the GC double linked list. At least, that's my memory of it.
Why the trashcan calls untrack more than once is obscure and I don't recall why it does so. I would need to study the code. My guess would be because it (ab)uses the GC head pointers to store the object in a special trashcan linked list.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it would be more clear if you would say that the code before Py_TRASHCAN_BEGIN
can be executed more than once. Calling the macro version of untrack twice is not safe while the function version is safe.
Misc/NEWS.d/next/Core and Builtins/2021-08-09-14-29-52.bpo-33930.--5LQ-.rst
Outdated
Show resolved
Hide resolved
…30.--5LQ-.rst Co-authored-by: Łukasz Langa <lukasz@langa.pl>
Thanks @pablogsal for the PR 🌮🎉.. I'm working now to backport this PR to: 3.8. |
Thanks @pablogsal for the PR 🌮🎉.. I'm working now to backport this PR to: 3.9. |
Thanks @pablogsal for the PR 🌮🎉.. I'm working now to backport this PR to: 3.10. |
Sorry, @pablogsal, I could not cleanly backport this to |
Sorry @pablogsal, I had trouble checking out the |
GH-27719 is a backport of this pull request to the 3.10 branch. |
…cts (pythonGH-27678) (cherry picked from commit bfc2d5a) Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
Thanks @pablogsal for the PR 🌮🎉.. I'm working now to backport this PR to: 3.9. |
GH-27720 is a backport of this pull request to the 3.9 branch. |
…cts (pythonGH-27678) (cherry picked from commit bfc2d5a) Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
@ambv do you want to backport this to 3.8? |
…d objects (pythonGH-27678). (cherry picked from commit bfc2d5a) Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
GH-27721 is a backport of this pull request to the 3.8 branch. |
…d objects (pythonGH-27678) (pythonGH-27721) (cherry picked from commit bfc2d5a) Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
https://bugs.python.org/issue33930
Co-authored by Augusto Goulart