@@ -1004,19 +1004,27 @@ itemgetter_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
10041004 return (PyObject * )ig ;
10051005}
10061006
1007+ static int
1008+ itemgetter_clear (itemgetterobject * ig )
1009+ {
1010+ Py_CLEAR (ig -> item );
1011+ return 0 ;
1012+ }
1013+
10071014static void
10081015itemgetter_dealloc (itemgetterobject * ig )
10091016{
10101017 PyTypeObject * tp = Py_TYPE (ig );
10111018 PyObject_GC_UnTrack (ig );
1012- Py_XDECREF ( ig -> item );
1019+ ( void ) itemgetter_clear ( ig );
10131020 tp -> tp_free (ig );
10141021 Py_DECREF (tp );
10151022}
10161023
10171024static int
10181025itemgetter_traverse (itemgetterobject * ig , visitproc visit , void * arg )
10191026{
1027+ Py_VISIT (Py_TYPE (ig ));
10201028 Py_VISIT (ig -> item );
10211029 return 0 ;
10221030}
@@ -1113,6 +1121,7 @@ static PyType_Slot itemgetter_type_slots[] = {
11131121 {Py_tp_dealloc , itemgetter_dealloc },
11141122 {Py_tp_call , itemgetter_call },
11151123 {Py_tp_traverse , itemgetter_traverse },
1124+ {Py_tp_clear , itemgetter_clear },
11161125 {Py_tp_methods , itemgetter_methods },
11171126 {Py_tp_new , itemgetter_new },
11181127 {Py_tp_getattro , PyObject_GenericGetAttr },
@@ -1250,12 +1259,19 @@ attrgetter_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
12501259 return (PyObject * )ag ;
12511260}
12521261
1262+ static int
1263+ attrgetter_clear (attrgetterobject * ag )
1264+ {
1265+ Py_CLEAR (ag -> attr );
1266+ return 0 ;
1267+ }
1268+
12531269static void
12541270attrgetter_dealloc (attrgetterobject * ag )
12551271{
12561272 PyTypeObject * tp = Py_TYPE (ag );
12571273 PyObject_GC_UnTrack (ag );
1258- Py_XDECREF ( ag -> attr );
1274+ ( void ) attrgetter_clear ( ag );
12591275 tp -> tp_free (ag );
12601276 Py_DECREF (tp );
12611277}
@@ -1264,6 +1280,7 @@ static int
12641280attrgetter_traverse (attrgetterobject * ag , visitproc visit , void * arg )
12651281{
12661282 Py_VISIT (ag -> attr );
1283+ Py_VISIT (Py_TYPE (ag ));
12671284 return 0 ;
12681285}
12691286
@@ -1435,6 +1452,7 @@ static PyType_Slot attrgetter_type_slots[] = {
14351452 {Py_tp_dealloc , attrgetter_dealloc },
14361453 {Py_tp_call , attrgetter_call },
14371454 {Py_tp_traverse , attrgetter_traverse },
1455+ {Py_tp_clear , attrgetter_clear },
14381456 {Py_tp_methods , attrgetter_methods },
14391457 {Py_tp_new , attrgetter_new },
14401458 {Py_tp_getattro , PyObject_GenericGetAttr },
@@ -1505,23 +1523,32 @@ methodcaller_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
15051523 return (PyObject * )mc ;
15061524}
15071525
1526+ static int
1527+ methodcaller_clear (methodcallerobject * mc )
1528+ {
1529+ Py_CLEAR (mc -> name );
1530+ Py_CLEAR (mc -> args );
1531+ Py_CLEAR (mc -> kwds );
1532+ return 0 ;
1533+ }
1534+
15081535static void
15091536methodcaller_dealloc (methodcallerobject * mc )
15101537{
15111538 PyTypeObject * tp = Py_TYPE (mc );
15121539 PyObject_GC_UnTrack (mc );
1513- Py_XDECREF (mc -> name );
1514- Py_XDECREF (mc -> args );
1515- Py_XDECREF (mc -> kwds );
1540+ (void )methodcaller_clear (mc );
15161541 tp -> tp_free (mc );
15171542 Py_DECREF (tp );
15181543}
15191544
15201545static int
15211546methodcaller_traverse (methodcallerobject * mc , visitproc visit , void * arg )
15221547{
1548+ Py_VISIT (mc -> name );
15231549 Py_VISIT (mc -> args );
15241550 Py_VISIT (mc -> kwds );
1551+ Py_VISIT (Py_TYPE (mc ));
15251552 return 0 ;
15261553}
15271554
@@ -1680,6 +1707,7 @@ static PyType_Slot methodcaller_type_slots[] = {
16801707 {Py_tp_dealloc , methodcaller_dealloc },
16811708 {Py_tp_call , methodcaller_call },
16821709 {Py_tp_traverse , methodcaller_traverse },
1710+ {Py_tp_clear , methodcaller_clear },
16831711 {Py_tp_methods , methodcaller_methods },
16841712 {Py_tp_new , methodcaller_new },
16851713 {Py_tp_getattro , PyObject_GenericGetAttr },
0 commit comments