Skip to content

Commit 1588413

Browse files
gh-116946: remove unnecessary gc from immutable types (#139073)
1 parent ce23eea commit 1588413

File tree

5 files changed

+5
-48
lines changed

5 files changed

+5
-48
lines changed

Modules/_bz2module.c

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -391,13 +391,6 @@ BZ2Compressor_dealloc(PyObject *op)
391391
Py_DECREF(tp);
392392
}
393393

394-
static int
395-
BZ2Compressor_traverse(PyObject *self, visitproc visit, void *arg)
396-
{
397-
Py_VISIT(Py_TYPE(self));
398-
return 0;
399-
}
400-
401394
static PyMethodDef BZ2Compressor_methods[] = {
402395
_BZ2_BZ2COMPRESSOR_COMPRESS_METHODDEF
403396
_BZ2_BZ2COMPRESSOR_FLUSH_METHODDEF
@@ -409,7 +402,6 @@ static PyType_Slot bz2_compressor_type_slots[] = {
409402
{Py_tp_methods, BZ2Compressor_methods},
410403
{Py_tp_new, _bz2_BZ2Compressor},
411404
{Py_tp_doc, (char *)_bz2_BZ2Compressor__doc__},
412-
{Py_tp_traverse, BZ2Compressor_traverse},
413405
{0, 0}
414406
};
415407

@@ -701,13 +693,6 @@ BZ2Decompressor_dealloc(PyObject *op)
701693
Py_DECREF(tp);
702694
}
703695

704-
static int
705-
BZ2Decompressor_traverse(PyObject *self, visitproc visit, void *arg)
706-
{
707-
Py_VISIT(Py_TYPE(self));
708-
return 0;
709-
}
710-
711696
static PyMethodDef BZ2Decompressor_methods[] = {
712697
_BZ2_BZ2DECOMPRESSOR_DECOMPRESS_METHODDEF
713698
{NULL}
@@ -738,7 +723,6 @@ static PyType_Slot bz2_decompressor_type_slots[] = {
738723
{Py_tp_doc, (char *)_bz2_BZ2Decompressor__doc__},
739724
{Py_tp_members, BZ2Decompressor_members},
740725
{Py_tp_new, _bz2_BZ2Decompressor},
741-
{Py_tp_traverse, BZ2Decompressor_traverse},
742726
{0, 0}
743727
};
744728

Modules/_lzmamodule.c

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -882,13 +882,6 @@ static PyMethodDef Compressor_methods[] = {
882882
{NULL}
883883
};
884884

885-
static int
886-
Compressor_traverse(PyObject *self, visitproc visit, void *arg)
887-
{
888-
Py_VISIT(Py_TYPE(self));
889-
return 0;
890-
}
891-
892885
PyDoc_STRVAR(Compressor_doc,
893886
"LZMACompressor(format=FORMAT_XZ, check=-1, preset=None, filters=None)\n"
894887
"\n"
@@ -922,7 +915,6 @@ static PyType_Slot lzma_compressor_type_slots[] = {
922915
{Py_tp_methods, Compressor_methods},
923916
{Py_tp_new, Compressor_new},
924917
{Py_tp_doc, (char *)Compressor_doc},
925-
{Py_tp_traverse, Compressor_traverse},
926918
{0, 0}
927919
};
928920

@@ -1325,13 +1317,6 @@ Decompressor_dealloc(PyObject *op)
13251317
Py_DECREF(tp);
13261318
}
13271319

1328-
static int
1329-
Decompressor_traverse(PyObject *self, visitproc visit, void *arg)
1330-
{
1331-
Py_VISIT(Py_TYPE(self));
1332-
return 0;
1333-
}
1334-
13351320
static PyMethodDef Decompressor_methods[] = {
13361321
_LZMA_LZMADECOMPRESSOR_DECOMPRESS_METHODDEF
13371322
{NULL}
@@ -1366,7 +1351,6 @@ static PyType_Slot lzma_decompressor_type_slots[] = {
13661351
{Py_tp_methods, Decompressor_methods},
13671352
{Py_tp_new, _lzma_LZMADecompressor},
13681353
{Py_tp_doc, (char *)_lzma_LZMADecompressor__doc__},
1369-
{Py_tp_traverse, Decompressor_traverse},
13701354
{Py_tp_members, Decompressor_members},
13711355
{0, 0}
13721356
};

Modules/_ssl.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5793,7 +5793,6 @@ memory_bio_dealloc(PyObject *op)
57935793
{
57945794
PySSLMemoryBIO *self = PySSLMemoryBIO_CAST(op);
57955795
PyTypeObject *tp = Py_TYPE(self);
5796-
PyObject_GC_UnTrack(self);
57975796
(void)BIO_free(self->bio);
57985797
tp->tp_free(self);
57995798
Py_DECREF(tp);
@@ -5957,15 +5956,13 @@ static PyType_Slot PySSLMemoryBIO_slots[] = {
59575956
{Py_tp_getset, memory_bio_getsetlist},
59585957
{Py_tp_new, _ssl_MemoryBIO},
59595958
{Py_tp_dealloc, memory_bio_dealloc},
5960-
{Py_tp_traverse, _PyObject_VisitType},
59615959
{0, 0},
59625960
};
59635961

59645962
static PyType_Spec PySSLMemoryBIO_spec = {
59655963
.name = "_ssl.MemoryBIO",
59665964
.basicsize = sizeof(PySSLMemoryBIO),
5967-
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IMMUTABLETYPE |
5968-
Py_TPFLAGS_HAVE_GC),
5965+
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IMMUTABLETYPE),
59695966
.slots = PySSLMemoryBIO_slots,
59705967
};
59715968

Modules/_threadmodule.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,6 @@ static void
660660
PyThreadHandleObject_dealloc(PyObject *op)
661661
{
662662
PyThreadHandleObject *self = PyThreadHandleObject_CAST(op);
663-
PyObject_GC_UnTrack(self);
664663
PyTypeObject *tp = Py_TYPE(self);
665664
ThreadHandle_decref(self->handle);
666665
tp->tp_free(self);
@@ -748,7 +747,6 @@ static PyType_Slot ThreadHandle_Type_slots[] = {
748747
{Py_tp_dealloc, PyThreadHandleObject_dealloc},
749748
{Py_tp_repr, PyThreadHandleObject_repr},
750749
{Py_tp_getset, ThreadHandle_getsetlist},
751-
{Py_tp_traverse, _PyObject_VisitType},
752750
{Py_tp_methods, ThreadHandle_methods},
753751
{Py_tp_new, PyThreadHandleObject_tp_new},
754752
{0, 0}
@@ -758,7 +756,7 @@ static PyType_Spec ThreadHandle_Type_spec = {
758756
"_thread._ThreadHandle",
759757
sizeof(PyThreadHandleObject),
760758
0,
761-
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IMMUTABLETYPE | Py_TPFLAGS_HAVE_GC,
759+
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IMMUTABLETYPE,
762760
ThreadHandle_Type_slots,
763761
};
764762

Modules/hmacmodule.c

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -756,7 +756,7 @@ _hmac_new_impl(PyObject *module, PyObject *keyobj, PyObject *msgobj,
756756
return NULL;
757757
}
758758

759-
HMACObject *self = PyObject_GC_New(HMACObject, state->hmac_type);
759+
HMACObject *self = PyObject_New(HMACObject, state->hmac_type);
760760
if (self == NULL) {
761761
return NULL;
762762
}
@@ -791,7 +791,6 @@ _hmac_new_impl(PyObject *module, PyObject *keyobj, PyObject *msgobj,
791791
#endif
792792
}
793793
assert(rc == 0);
794-
PyObject_GC_Track(self);
795794
return (PyObject *)self;
796795

797796
error_on_key:
@@ -852,7 +851,7 @@ _hmac_HMAC_copy_impl(HMACObject *self, PyTypeObject *cls)
852851
/*[clinic end generated code: output=a955bfa55b65b215 input=17b2c0ad0b147e36]*/
853852
{
854853
hmacmodule_state *state = get_hmacmodule_state_by_cls(cls);
855-
HMACObject *copy = PyObject_GC_New(HMACObject, state->hmac_type);
854+
HMACObject *copy = PyObject_New(HMACObject, state->hmac_type);
856855
if (copy == NULL) {
857856
return NULL;
858857
}
@@ -870,7 +869,6 @@ _hmac_HMAC_copy_impl(HMACObject *self, PyTypeObject *cls)
870869
}
871870

872871
HASHLIB_INIT_MUTEX(copy);
873-
PyObject_GC_Track(copy);
874872
return (PyObject *)copy;
875873
}
876874

@@ -1026,7 +1024,6 @@ static void
10261024
HMACObject_dealloc(PyObject *op)
10271025
{
10281026
PyTypeObject *type = Py_TYPE(op);
1029-
PyObject_GC_UnTrack(op);
10301027
(void)HMACObject_clear(op);
10311028
type->tp_free(op);
10321029
Py_DECREF(type);
@@ -1051,9 +1048,7 @@ static PyType_Slot HMACObject_Type_slots[] = {
10511048
{Py_tp_repr, HMACObject_repr},
10521049
{Py_tp_methods, HMACObject_methods},
10531050
{Py_tp_getset, HMACObject_getsets},
1054-
{Py_tp_clear, HMACObject_clear},
10551051
{Py_tp_dealloc, HMACObject_dealloc},
1056-
{Py_tp_traverse, _PyObject_VisitType},
10571052
{0, NULL} /* sentinel */
10581053
};
10591054

@@ -1063,8 +1058,7 @@ static PyType_Spec HMAC_Type_spec = {
10631058
.flags = Py_TPFLAGS_DEFAULT
10641059
| Py_TPFLAGS_DISALLOW_INSTANTIATION
10651060
| Py_TPFLAGS_HEAPTYPE
1066-
| Py_TPFLAGS_IMMUTABLETYPE
1067-
| Py_TPFLAGS_HAVE_GC,
1061+
| Py_TPFLAGS_IMMUTABLETYPE,
10681062
.slots = HMACObject_Type_slots,
10691063
};
10701064

0 commit comments

Comments
 (0)