Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34k
gh-116946: fully implement GC protocol for _tkinter.Tk{app,tt}Object#138331
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
picnixz merged 11 commits into python:main from picnixz:fix/gc/tkinter-heap-types-116946Sep 11, 2025
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
11 commits Select commit Hold shift + click to select a range
84f832f fully implement GC protocol for `_tkinter` objects
picnixz a9c01ef make _tkinter.Tcl_Obj immutable instead of supporting full GC
picnixz dbb343f revert changes to `_tkinter.Tcl_Obj`; they will be made later
picnixz 9eb9f47 Merge branch 'main' into fix/gc/tkinter-heap-types-116946
picnixz 8e80641 add tp_clear for visited objects
picnixz 833a85e use the correct slot...
picnixz 022d71e revert the revert
picnixz 168fe43 keep the necessary bits
picnixz 5e5f698 remove warnings
picnixz 35915b0 reduce the diff a bit
picnixz ba9c809 Merge remote-tracking branch 'upstream/main' into fix/gc/tkinter-heap…
picnixz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -589,10 +589,11 @@ Tkapp_New(const char *screenName, const char *className, | ||
| int interactive, int wantobjects, int wantTk, int sync, | ||
| const char *use) | ||
| { | ||
| PyTypeObject *type = (PyTypeObject *)Tkapp_Type; | ||
| TkappObject *v; | ||
| char *argv0; | ||
| v = PyObject_New(TkappObject, (PyTypeObject *) Tkapp_Type); | ||
| v = (TkappObject *)type->tp_alloc(type, 0); | ||
| if (v == NULL) | ||
| return NULL; | ||
| @@ -2745,9 +2746,10 @@ _tkinter_tktimertoken_deletetimerhandler_impl(TkttObject *self) | ||
| static TkttObject * | ||
| Tktt_New(PyObject *func) | ||
| { | ||
| PyTypeObject *type = (PyTypeObject *)Tktt_Type; | ||
| TkttObject *v; | ||
| v = PyObject_New(TkttObject, (PyTypeObject *) Tktt_Type); | ||
| v = (TkttObject *)type->tp_alloc(type, 0); | ||
| if (v == NULL) | ||
| return NULL; | ||
| @@ -2758,19 +2760,33 @@ Tktt_New(PyObject *func) | ||
| return (TkttObject*)Py_NewRef(v); | ||
| } | ||
| static void | ||
| Tktt_Dealloc(PyObject *self) | ||
| static int | ||
| Tktt_Clear(PyObject *op) | ||
| { | ||
| TkttObject *v = TkttObject_CAST(self); | ||
| PyObject *func = v->func; | ||
| PyObject *tp = (PyObject *) Py_TYPE(self); | ||
| Py_XDECREF(func); | ||
| TkttObject *self = TkttObject_CAST(op); | ||
| Py_CLEAR(self->func); | ||
| return 0; | ||
| } | ||
| PyObject_Free(self); | ||
| static void | ||
| Tktt_Dealloc(PyObject *op) | ||
| { | ||
| PyTypeObject *tp = Py_TYPE(op); | ||
| PyObject_GC_UnTrack(op); | ||
| (void)Tktt_Clear(op); | ||
| tp->tp_free(op); | ||
| Py_DECREF(tp); | ||
| } | ||
| static int | ||
| Tktt_Traverse(PyObject *op, visitproc visit, void *arg) | ||
| { | ||
| TkttObject *self = TkttObject_CAST(op); | ||
| Py_VISIT(Py_TYPE(op)); | ||
| Py_VISIT(self->func); | ||
| return 0; | ||
| } | ||
| static PyObject * | ||
| Tktt_Repr(PyObject *self) | ||
| { | ||
| @@ -3061,21 +3077,38 @@ _tkinter_tkapp_willdispatch_impl(TkappObject *self) | ||
| /**** Tkapp Type Methods ****/ | ||
| static int | ||
| Tkapp_Clear(PyObject *op) | ||
| { | ||
| TkappObject *self = TkappObject_CAST(op); | ||
| Py_CLEAR(self->trace); | ||
| return 0; | ||
| } | ||
| static void | ||
| Tkapp_Dealloc(PyObject *op) | ||
| { | ||
| PyTypeObject *tp = Py_TYPE(op); | ||
| PyObject_GC_UnTrack(op); | ||
| TkappObject *self = TkappObject_CAST(op); | ||
| PyTypeObject *tp = Py_TYPE(self); | ||
| /*CHECK_TCL_APPARTMENT;*/ | ||
| ENTER_TCL | ||
| Tcl_DeleteInterp(Tkapp_Interp(self)); | ||
| LEAVE_TCL | ||
| Py_XDECREF(self->trace); | ||
| PyObject_Free(self); | ||
| (void)Tkapp_Clear(op); | ||
| tp->tp_free(self); | ||
picnixz marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading. Please reload this page. | ||
| Py_DECREF(tp); | ||
| DisableEventHook(); | ||
| } | ||
| static int | ||
| Tkapp_Traverse(PyObject *op, visitproc visit, void *arg) | ||
| { | ||
| TkappObject *self = TkappObject_CAST(op); | ||
| Py_VISIT(Py_TYPE(op)); | ||
| Py_VISIT(self->trace); | ||
| return 0; | ||
| } | ||
| /**** Tkinter Module ****/ | ||
| @@ -3263,7 +3296,9 @@ static PyMethodDef Tktt_methods[] = | ||
| }; | ||
| static PyType_Slot Tktt_Type_slots[] ={ | ||
| {Py_tp_clear, Tktt_Clear}, | ||
| {Py_tp_dealloc, Tktt_Dealloc}, | ||
| {Py_tp_traverse, Tktt_Traverse}, | ||
| {Py_tp_repr, Tktt_Repr}, | ||
| {Py_tp_methods, Tktt_methods}, | ||
| {0, 0} | ||
| @@ -3276,6 +3311,7 @@ static PyType_Spec Tktt_Type_spec ={ | ||
| Py_TPFLAGS_DEFAULT | ||
| | Py_TPFLAGS_DISALLOW_INSTANTIATION | ||
| | Py_TPFLAGS_IMMUTABLETYPE | ||
| | Py_TPFLAGS_HAVE_GC | ||
| ), | ||
| .slots = Tktt_Type_slots, | ||
| }; | ||
| @@ -3322,7 +3358,9 @@ static PyMethodDef Tkapp_methods[] = | ||
| }; | ||
| static PyType_Slot Tkapp_Type_slots[] ={ | ||
| {Py_tp_clear, Tkapp_Clear}, | ||
| {Py_tp_dealloc, Tkapp_Dealloc}, | ||
| {Py_tp_traverse, Tkapp_Traverse}, | ||
| {Py_tp_methods, Tkapp_methods}, | ||
| {0, 0} | ||
| }; | ||
| @@ -3335,6 +3373,7 @@ static PyType_Spec Tkapp_Type_spec ={ | ||
| Py_TPFLAGS_DEFAULT | ||
| | Py_TPFLAGS_DISALLOW_INSTANTIATION | ||
| | Py_TPFLAGS_IMMUTABLETYPE | ||
| | Py_TPFLAGS_HAVE_GC | ||
| ), | ||
| .slots = Tkapp_Type_slots, | ||
| }; | ||
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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.
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.
Unfortunately, this temporary variable is needed as we need
Py_DECREF(Py_TYPE(op))otherwise. The rest of the code base also does this.