-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
bpo-41984: GC track all user classes #22701
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
Merged
brandtbucher
merged 9 commits into
python:master
from
brandtbucher:track-all-heap-types
Oct 15, 2020
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
780750e
Track all heap types
brandtbucher 26d8109
Fix failing tests
brandtbucher 1d6f62f
Clean up type flagging.
brandtbucher 63d8d25
Catch up with master.
brandtbucher ef2d84d
Add without_gc decorator to _testcapi.
brandtbucher 65ca804
Fix GC tracking in test_finalization.
brandtbucher f8cc619
Add NEWS entry.
brandtbucher 20fb956
Fix non-CPython finalization tests.
brandtbucher 8f3d1b7
Minor cleanup.
brandtbucher File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
Misc/NEWS.d/next/Core and Builtins/2020-10-14-16-19-43.bpo-41984.SEtKMr.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
The garbage collector now tracks all user-defined classes. Patch by Brandt | ||
Bucher. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3888,6 +3888,25 @@ with_tp_del(PyObject *self, PyObject *args) | |
return obj; | ||
} | ||
|
||
static PyObject * | ||
without_gc(PyObject *Py_UNUSED(self), PyObject *obj) | ||
{ | ||
PyTypeObject *tp = (PyTypeObject*)obj; | ||
if (!PyType_Check(obj) || !PyType_HasFeature(tp, Py_TPFLAGS_HEAPTYPE)) { | ||
return PyErr_Format(PyExc_TypeError, "heap type expected, got %R", obj); | ||
} | ||
if (PyType_IS_GC(tp)) { | ||
// Don't try this at home, kids: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. :) |
||
tp->tp_flags -= Py_TPFLAGS_HAVE_GC; | ||
tp->tp_free = PyObject_Del; | ||
brandtbucher marked this conversation as resolved.
Show resolved
Hide resolved
|
||
tp->tp_traverse = NULL; | ||
tp->tp_clear = NULL; | ||
} | ||
assert(!PyType_IS_GC(tp)); | ||
Py_INCREF(obj); | ||
return obj; | ||
} | ||
|
||
static PyMethodDef ml; | ||
|
||
static PyObject * | ||
|
@@ -5805,6 +5824,7 @@ static PyMethodDef TestMethods[] = { | |
{"meth_fastcall", (PyCFunction)(void(*)(void))meth_fastcall, METH_FASTCALL}, | ||
{"meth_fastcall_keywords", (PyCFunction)(void(*)(void))meth_fastcall_keywords, METH_FASTCALL|METH_KEYWORDS}, | ||
{"pynumber_tobase", pynumber_tobase, METH_VARARGS}, | ||
{"without_gc", without_gc, METH_O}, | ||
{NULL, NULL} /* sentinel */ | ||
}; | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 doubt that people are relying on the past behaviour (but I have been surprised in the past) so I am questioning if we should include a small sentence in the What's new of 3.10 in the "porting" section. What do you think?
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? I don't really feel the need to, though, since the behavior wasn't documented before and we don't provide any "fixes" to actually port old code.