Skip to content

Commit a9c01ef

Browse files
committed
make _tkinter.Tcl_Obj immutable instead of supporting full GC
1 parent 84f832f commit a9c01ef

File tree

1 file changed

+6
-20
lines changed

1 file changed

+6
-20
lines changed

Modules/_tkinter.c

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -792,13 +792,8 @@ static PyObject *PyTclObject_Type;
792792
static PyObject *
793793
newPyTclObject(Tcl_Obj *arg)
794794
{
795-
PyTypeObject *type;
796795
PyTclObject *self;
797-
798-
type = (PyTypeObject *)PyTclObject_Type;
799-
assert(type != NULL);
800-
assert(type->tp_alloc != NULL);
801-
self = (PyTclObject *)type->tp_alloc(type, 0);
796+
self = PyObject_New(PyTclObject, (PyTypeObject *) PyTclObject_Type);
802797
if (self == NULL)
803798
return NULL;
804799
Tcl_IncrRefCount(arg);
@@ -808,24 +803,16 @@ newPyTclObject(Tcl_Obj *arg)
808803
}
809804

810805
static void
811-
PyTclObject_dealloc(PyObject *op)
806+
PyTclObject_dealloc(PyObject *_self)
812807
{
813-
PyTypeObject *tp = Py_TYPE(op);
814-
PyObject_GC_UnTrack(op);
815-
PyTclObject *self = PyTclObject_CAST(op);
808+
PyTclObject *self = PyTclObject_CAST(_self);
809+
PyObject *tp = (PyObject *) Py_TYPE(self);
816810
Tcl_DecrRefCount(self->value);
817811
Py_XDECREF(self->string);
818-
tp->tp_free(self);
812+
PyObject_Free(self);
819813
Py_DECREF(tp);
820814
}
821815

822-
static int
823-
PyTclObject_traverse(PyObject *op, visitproc visit, void *arg)
824-
{
825-
Py_VISIT(Py_TYPE(op));
826-
return 0;
827-
}
828-
829816
/* Like _str, but create Unicode if necessary. */
830817
PyDoc_STRVAR(PyTclObject_string__doc__,
831818
"the string representation of this object, either as str or bytes");
@@ -914,7 +901,6 @@ static PyGetSetDef PyTclObject_getsetlist[] = {
914901

915902
static PyType_Slot PyTclObject_Type_slots[] = {
916903
{Py_tp_dealloc, PyTclObject_dealloc},
917-
{Py_tp_traverse, PyTclObject_traverse},
918904
{Py_tp_repr, PyTclObject_repr},
919905
{Py_tp_str, PyTclObject_str},
920906
{Py_tp_getattro, PyObject_GenericGetAttr},
@@ -929,7 +915,7 @@ static PyType_Spec PyTclObject_Type_spec = {
929915
.flags = (
930916
Py_TPFLAGS_DEFAULT
931917
| Py_TPFLAGS_DISALLOW_INSTANTIATION
932-
| Py_TPFLAGS_HAVE_GC
918+
| Py_TPFLAGS_IMMUTABLETYPE
933919
),
934920
.slots = PyTclObject_Type_slots,
935921
};

0 commit comments

Comments
 (0)