mirror of https://github.com/python/cpython.git
bpo-42972: Fully support GC protocol for _operator heap types (GH-26371) (GH-26413)
(cherry picked from commit f4b70c22c8
)
Co-authored-by: Erlend Egeberg Aasland <erlend.aasland@innova.no>
This commit is contained in:
parent
0574b0686d
commit
d1c732912e
|
@ -1004,12 +1004,19 @@ itemgetter_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||||
return (PyObject *)ig;
|
return (PyObject *)ig;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
itemgetter_clear(itemgetterobject *ig)
|
||||||
|
{
|
||||||
|
Py_CLEAR(ig->item);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
itemgetter_dealloc(itemgetterobject *ig)
|
itemgetter_dealloc(itemgetterobject *ig)
|
||||||
{
|
{
|
||||||
PyTypeObject *tp = Py_TYPE(ig);
|
PyTypeObject *tp = Py_TYPE(ig);
|
||||||
PyObject_GC_UnTrack(ig);
|
PyObject_GC_UnTrack(ig);
|
||||||
Py_XDECREF(ig->item);
|
(void)itemgetter_clear(ig);
|
||||||
tp->tp_free(ig);
|
tp->tp_free(ig);
|
||||||
Py_DECREF(tp);
|
Py_DECREF(tp);
|
||||||
}
|
}
|
||||||
|
@ -1017,6 +1024,7 @@ itemgetter_dealloc(itemgetterobject *ig)
|
||||||
static int
|
static int
|
||||||
itemgetter_traverse(itemgetterobject *ig, visitproc visit, void *arg)
|
itemgetter_traverse(itemgetterobject *ig, visitproc visit, void *arg)
|
||||||
{
|
{
|
||||||
|
Py_VISIT(Py_TYPE(ig));
|
||||||
Py_VISIT(ig->item);
|
Py_VISIT(ig->item);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -1113,6 +1121,7 @@ static PyType_Slot itemgetter_type_slots[] = {
|
||||||
{Py_tp_dealloc, itemgetter_dealloc},
|
{Py_tp_dealloc, itemgetter_dealloc},
|
||||||
{Py_tp_call, itemgetter_call},
|
{Py_tp_call, itemgetter_call},
|
||||||
{Py_tp_traverse, itemgetter_traverse},
|
{Py_tp_traverse, itemgetter_traverse},
|
||||||
|
{Py_tp_clear, itemgetter_clear},
|
||||||
{Py_tp_methods, itemgetter_methods},
|
{Py_tp_methods, itemgetter_methods},
|
||||||
{Py_tp_new, itemgetter_new},
|
{Py_tp_new, itemgetter_new},
|
||||||
{Py_tp_getattro, PyObject_GenericGetAttr},
|
{Py_tp_getattro, PyObject_GenericGetAttr},
|
||||||
|
@ -1250,12 +1259,19 @@ attrgetter_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||||
return (PyObject *)ag;
|
return (PyObject *)ag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
attrgetter_clear(attrgetterobject *ag)
|
||||||
|
{
|
||||||
|
Py_CLEAR(ag->attr);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
attrgetter_dealloc(attrgetterobject *ag)
|
attrgetter_dealloc(attrgetterobject *ag)
|
||||||
{
|
{
|
||||||
PyTypeObject *tp = Py_TYPE(ag);
|
PyTypeObject *tp = Py_TYPE(ag);
|
||||||
PyObject_GC_UnTrack(ag);
|
PyObject_GC_UnTrack(ag);
|
||||||
Py_XDECREF(ag->attr);
|
(void)attrgetter_clear(ag);
|
||||||
tp->tp_free(ag);
|
tp->tp_free(ag);
|
||||||
Py_DECREF(tp);
|
Py_DECREF(tp);
|
||||||
}
|
}
|
||||||
|
@ -1264,6 +1280,7 @@ static int
|
||||||
attrgetter_traverse(attrgetterobject *ag, visitproc visit, void *arg)
|
attrgetter_traverse(attrgetterobject *ag, visitproc visit, void *arg)
|
||||||
{
|
{
|
||||||
Py_VISIT(ag->attr);
|
Py_VISIT(ag->attr);
|
||||||
|
Py_VISIT(Py_TYPE(ag));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1435,6 +1452,7 @@ static PyType_Slot attrgetter_type_slots[] = {
|
||||||
{Py_tp_dealloc, attrgetter_dealloc},
|
{Py_tp_dealloc, attrgetter_dealloc},
|
||||||
{Py_tp_call, attrgetter_call},
|
{Py_tp_call, attrgetter_call},
|
||||||
{Py_tp_traverse, attrgetter_traverse},
|
{Py_tp_traverse, attrgetter_traverse},
|
||||||
|
{Py_tp_clear, attrgetter_clear},
|
||||||
{Py_tp_methods, attrgetter_methods},
|
{Py_tp_methods, attrgetter_methods},
|
||||||
{Py_tp_new, attrgetter_new},
|
{Py_tp_new, attrgetter_new},
|
||||||
{Py_tp_getattro, PyObject_GenericGetAttr},
|
{Py_tp_getattro, PyObject_GenericGetAttr},
|
||||||
|
@ -1505,14 +1523,21 @@ methodcaller_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||||
return (PyObject *)mc;
|
return (PyObject *)mc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
methodcaller_clear(methodcallerobject *mc)
|
||||||
|
{
|
||||||
|
Py_CLEAR(mc->name);
|
||||||
|
Py_CLEAR(mc->args);
|
||||||
|
Py_CLEAR(mc->kwds);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
methodcaller_dealloc(methodcallerobject *mc)
|
methodcaller_dealloc(methodcallerobject *mc)
|
||||||
{
|
{
|
||||||
PyTypeObject *tp = Py_TYPE(mc);
|
PyTypeObject *tp = Py_TYPE(mc);
|
||||||
PyObject_GC_UnTrack(mc);
|
PyObject_GC_UnTrack(mc);
|
||||||
Py_XDECREF(mc->name);
|
(void)methodcaller_clear(mc);
|
||||||
Py_XDECREF(mc->args);
|
|
||||||
Py_XDECREF(mc->kwds);
|
|
||||||
tp->tp_free(mc);
|
tp->tp_free(mc);
|
||||||
Py_DECREF(tp);
|
Py_DECREF(tp);
|
||||||
}
|
}
|
||||||
|
@ -1520,8 +1545,10 @@ methodcaller_dealloc(methodcallerobject *mc)
|
||||||
static int
|
static int
|
||||||
methodcaller_traverse(methodcallerobject *mc, visitproc visit, void *arg)
|
methodcaller_traverse(methodcallerobject *mc, visitproc visit, void *arg)
|
||||||
{
|
{
|
||||||
|
Py_VISIT(mc->name);
|
||||||
Py_VISIT(mc->args);
|
Py_VISIT(mc->args);
|
||||||
Py_VISIT(mc->kwds);
|
Py_VISIT(mc->kwds);
|
||||||
|
Py_VISIT(Py_TYPE(mc));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1680,6 +1707,7 @@ static PyType_Slot methodcaller_type_slots[] = {
|
||||||
{Py_tp_dealloc, methodcaller_dealloc},
|
{Py_tp_dealloc, methodcaller_dealloc},
|
||||||
{Py_tp_call, methodcaller_call},
|
{Py_tp_call, methodcaller_call},
|
||||||
{Py_tp_traverse, methodcaller_traverse},
|
{Py_tp_traverse, methodcaller_traverse},
|
||||||
|
{Py_tp_clear, methodcaller_clear},
|
||||||
{Py_tp_methods, methodcaller_methods},
|
{Py_tp_methods, methodcaller_methods},
|
||||||
{Py_tp_new, methodcaller_new},
|
{Py_tp_new, methodcaller_new},
|
||||||
{Py_tp_getattro, PyObject_GenericGetAttr},
|
{Py_tp_getattro, PyObject_GenericGetAttr},
|
||||||
|
|
Loading…
Reference in New Issue