@@ -762,45 +762,25 @@ typedef struct lru_list_elem {
762
762
PyObject * key , * result ;
763
763
} lru_list_elem ;
764
764
765
- static int
766
- lru_list_elem_clear (lru_list_elem * link )
767
- {
768
- Py_CLEAR (link -> key );
769
- Py_CLEAR (link -> result );
770
- return 0 ;
771
- }
772
-
773
- static int
774
- lru_list_elem_traverse (lru_list_elem * link , visitproc visit , void * arg )
775
- {
776
- Py_VISIT (link -> key );
777
- Py_VISIT (link -> result );
778
- Py_VISIT (Py_TYPE (link ));
779
- return 0 ;
780
- }
781
-
782
765
static void
783
766
lru_list_elem_dealloc (lru_list_elem * link )
784
767
{
785
768
PyTypeObject * tp = Py_TYPE (link );
786
- PyObject_GC_UnTrack (link );
787
- ( void ) lru_list_elem_clear ( link );
788
- PyObject_GC_Del (link );
769
+ Py_CLEAR (link -> key );
770
+ Py_CLEAR ( link -> result );
771
+ tp -> tp_free (link );
789
772
Py_DECREF (tp );
790
773
}
791
774
792
775
static PyType_Slot lru_list_elem_type_slots [] = {
793
776
{Py_tp_dealloc , lru_list_elem_dealloc },
794
- {Py_tp_traverse , lru_list_elem_traverse },
795
- {Py_tp_clear , lru_list_elem_clear },
796
777
{0 , 0 }
797
778
};
798
779
799
780
static PyType_Spec lru_list_elem_type_spec = {
800
781
.name = "functools._lru_list_elem" ,
801
782
.basicsize = sizeof (lru_list_elem ),
802
- .flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_DISALLOW_INSTANTIATION |
803
- Py_TPFLAGS_HAVE_GC ),
783
+ .flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_DISALLOW_INSTANTIATION ,
804
784
.slots = lru_list_elem_type_slots
805
785
};
806
786
@@ -1065,8 +1045,8 @@ bounded_lru_cache_wrapper(lru_cache_object *self, PyObject *args, PyObject *kwds
1065
1045
self -> root .next == & self -> root )
1066
1046
{
1067
1047
/* Cache is not full, so put the result in a new link */
1068
- link = (lru_list_elem * )PyObject_GC_New (lru_list_elem ,
1069
- self -> lru_list_elem_type );
1048
+ link = (lru_list_elem * )PyObject_New (lru_list_elem ,
1049
+ self -> lru_list_elem_type );
1070
1050
if (link == NULL ) {
1071
1051
Py_DECREF (key );
1072
1052
Py_DECREF (result );
@@ -1076,7 +1056,6 @@ bounded_lru_cache_wrapper(lru_cache_object *self, PyObject *args, PyObject *kwds
1076
1056
link -> hash = hash ;
1077
1057
link -> key = key ;
1078
1058
link -> result = result ;
1079
- PyObject_GC_Track (link );
1080
1059
/* What is really needed here is a SetItem variant with a "no clobber"
1081
1060
option. If the __eq__ call triggers a reentrant call that adds
1082
1061
this same key, then this setitem call will update the cache dict
@@ -1365,7 +1344,8 @@ lru_cache_tp_traverse(lru_cache_object *self, visitproc visit, void *arg)
1365
1344
lru_list_elem * link = self -> root .next ;
1366
1345
while (link != & self -> root ) {
1367
1346
lru_list_elem * next = link -> next ;
1368
- Py_VISIT (link );
1347
+ Py_VISIT (link -> key );
1348
+ Py_VISIT (link -> result );
1369
1349
link = next ;
1370
1350
}
1371
1351
Py_VISIT (self -> func );
0 commit comments