Skip to content

Commit 8e80641

Browse files
committed
add tp_clear for visited objects
1 parent 9eb9f47 commit 8e80641

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

Modules/_tkinter.c

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2759,14 +2759,21 @@ Tktt_New(PyObject *func)
27592759
return (TkttObject*)Py_NewRef(v);
27602760
}
27612761

2762+
static int
2763+
Tktt_Clear(PyObject *op)
2764+
{
2765+
TkttObject *self = TkttObject_CAST(op);
2766+
Py_CLEAR(self->func);
2767+
return 0;
2768+
}
2769+
27622770
static void
27632771
Tktt_Dealloc(PyObject *op)
27642772
{
27652773
PyTypeObject *tp = Py_TYPE(op);
27662774
PyObject_GC_UnTrack(op);
2767-
TkttObject *self = TkttObject_CAST(op);
2768-
Py_XDECREF(self->func);
2769-
tp->tp_free(self);
2775+
(void)Tktt_Clear(op);
2776+
tp->tp_free(op);
27702777
Py_DECREF(tp);
27712778
}
27722779

@@ -3069,6 +3076,14 @@ _tkinter_tkapp_willdispatch_impl(TkappObject *self)
30693076

30703077
/**** Tkapp Type Methods ****/
30713078

3079+
static int
3080+
Tkapp_Clear(PyObject *op)
3081+
{
3082+
TkappObject *self = TkappObject_CAST(op);
3083+
Py_CLEAR(self->trace);
3084+
return 0;
3085+
}
3086+
30723087
static void
30733088
Tkapp_Dealloc(PyObject *op)
30743089
{
@@ -3079,7 +3094,7 @@ Tkapp_Dealloc(PyObject *op)
30793094
ENTER_TCL
30803095
Tcl_DeleteInterp(Tkapp_Interp(self));
30813096
LEAVE_TCL
3082-
Py_XDECREF(self->trace);
3097+
(void)Tkapp_Clear(op);
30833098
tp->tp_free(self);
30843099
Py_DECREF(tp);
30853100
DisableEventHook();
@@ -3280,6 +3295,7 @@ static PyMethodDef Tktt_methods[] =
32803295
};
32813296

32823297
static PyType_Slot Tktt_Type_slots[] = {
3298+
{Py_tp_dealloc, Tktt_Clear},
32833299
{Py_tp_dealloc, Tktt_Dealloc},
32843300
{Py_tp_traverse, Tktt_Traverse},
32853301
{Py_tp_repr, Tktt_Repr},
@@ -3340,6 +3356,7 @@ static PyMethodDef Tkapp_methods[] =
33403356
};
33413357

33423358
static PyType_Slot Tkapp_Type_slots[] = {
3359+
{Py_tp_dealloc, Tkapp_Clear},
33433360
{Py_tp_dealloc, Tkapp_Dealloc},
33443361
{Py_tp_traverse, Tkapp_Traverse},
33453362
{Py_tp_methods, Tkapp_methods},

0 commit comments

Comments
 (0)