mirror of
https://github.com/python/cpython.git
synced 2025-10-31 21:51:50 +00:00
gh-116946: remove unnecessary gc from immutable types (#139073)
This commit is contained in:
parent
ce23eeaa2b
commit
1588413ca7
5 changed files with 5 additions and 48 deletions
|
|
@ -391,13 +391,6 @@ BZ2Compressor_dealloc(PyObject *op)
|
||||||
Py_DECREF(tp);
|
Py_DECREF(tp);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
|
||||||
BZ2Compressor_traverse(PyObject *self, visitproc visit, void *arg)
|
|
||||||
{
|
|
||||||
Py_VISIT(Py_TYPE(self));
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static PyMethodDef BZ2Compressor_methods[] = {
|
static PyMethodDef BZ2Compressor_methods[] = {
|
||||||
_BZ2_BZ2COMPRESSOR_COMPRESS_METHODDEF
|
_BZ2_BZ2COMPRESSOR_COMPRESS_METHODDEF
|
||||||
_BZ2_BZ2COMPRESSOR_FLUSH_METHODDEF
|
_BZ2_BZ2COMPRESSOR_FLUSH_METHODDEF
|
||||||
|
|
@ -409,7 +402,6 @@ static PyType_Slot bz2_compressor_type_slots[] = {
|
||||||
{Py_tp_methods, BZ2Compressor_methods},
|
{Py_tp_methods, BZ2Compressor_methods},
|
||||||
{Py_tp_new, _bz2_BZ2Compressor},
|
{Py_tp_new, _bz2_BZ2Compressor},
|
||||||
{Py_tp_doc, (char *)_bz2_BZ2Compressor__doc__},
|
{Py_tp_doc, (char *)_bz2_BZ2Compressor__doc__},
|
||||||
{Py_tp_traverse, BZ2Compressor_traverse},
|
|
||||||
{0, 0}
|
{0, 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -701,13 +693,6 @@ BZ2Decompressor_dealloc(PyObject *op)
|
||||||
Py_DECREF(tp);
|
Py_DECREF(tp);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
|
||||||
BZ2Decompressor_traverse(PyObject *self, visitproc visit, void *arg)
|
|
||||||
{
|
|
||||||
Py_VISIT(Py_TYPE(self));
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static PyMethodDef BZ2Decompressor_methods[] = {
|
static PyMethodDef BZ2Decompressor_methods[] = {
|
||||||
_BZ2_BZ2DECOMPRESSOR_DECOMPRESS_METHODDEF
|
_BZ2_BZ2DECOMPRESSOR_DECOMPRESS_METHODDEF
|
||||||
{NULL}
|
{NULL}
|
||||||
|
|
@ -738,7 +723,6 @@ static PyType_Slot bz2_decompressor_type_slots[] = {
|
||||||
{Py_tp_doc, (char *)_bz2_BZ2Decompressor__doc__},
|
{Py_tp_doc, (char *)_bz2_BZ2Decompressor__doc__},
|
||||||
{Py_tp_members, BZ2Decompressor_members},
|
{Py_tp_members, BZ2Decompressor_members},
|
||||||
{Py_tp_new, _bz2_BZ2Decompressor},
|
{Py_tp_new, _bz2_BZ2Decompressor},
|
||||||
{Py_tp_traverse, BZ2Decompressor_traverse},
|
|
||||||
{0, 0}
|
{0, 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -882,13 +882,6 @@ static PyMethodDef Compressor_methods[] = {
|
||||||
{NULL}
|
{NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
static int
|
|
||||||
Compressor_traverse(PyObject *self, visitproc visit, void *arg)
|
|
||||||
{
|
|
||||||
Py_VISIT(Py_TYPE(self));
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
PyDoc_STRVAR(Compressor_doc,
|
PyDoc_STRVAR(Compressor_doc,
|
||||||
"LZMACompressor(format=FORMAT_XZ, check=-1, preset=None, filters=None)\n"
|
"LZMACompressor(format=FORMAT_XZ, check=-1, preset=None, filters=None)\n"
|
||||||
"\n"
|
"\n"
|
||||||
|
|
@ -922,7 +915,6 @@ static PyType_Slot lzma_compressor_type_slots[] = {
|
||||||
{Py_tp_methods, Compressor_methods},
|
{Py_tp_methods, Compressor_methods},
|
||||||
{Py_tp_new, Compressor_new},
|
{Py_tp_new, Compressor_new},
|
||||||
{Py_tp_doc, (char *)Compressor_doc},
|
{Py_tp_doc, (char *)Compressor_doc},
|
||||||
{Py_tp_traverse, Compressor_traverse},
|
|
||||||
{0, 0}
|
{0, 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -1325,13 +1317,6 @@ Decompressor_dealloc(PyObject *op)
|
||||||
Py_DECREF(tp);
|
Py_DECREF(tp);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
|
||||||
Decompressor_traverse(PyObject *self, visitproc visit, void *arg)
|
|
||||||
{
|
|
||||||
Py_VISIT(Py_TYPE(self));
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static PyMethodDef Decompressor_methods[] = {
|
static PyMethodDef Decompressor_methods[] = {
|
||||||
_LZMA_LZMADECOMPRESSOR_DECOMPRESS_METHODDEF
|
_LZMA_LZMADECOMPRESSOR_DECOMPRESS_METHODDEF
|
||||||
{NULL}
|
{NULL}
|
||||||
|
|
@ -1366,7 +1351,6 @@ static PyType_Slot lzma_decompressor_type_slots[] = {
|
||||||
{Py_tp_methods, Decompressor_methods},
|
{Py_tp_methods, Decompressor_methods},
|
||||||
{Py_tp_new, _lzma_LZMADecompressor},
|
{Py_tp_new, _lzma_LZMADecompressor},
|
||||||
{Py_tp_doc, (char *)_lzma_LZMADecompressor__doc__},
|
{Py_tp_doc, (char *)_lzma_LZMADecompressor__doc__},
|
||||||
{Py_tp_traverse, Decompressor_traverse},
|
|
||||||
{Py_tp_members, Decompressor_members},
|
{Py_tp_members, Decompressor_members},
|
||||||
{0, 0}
|
{0, 0}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -5793,7 +5793,6 @@ memory_bio_dealloc(PyObject *op)
|
||||||
{
|
{
|
||||||
PySSLMemoryBIO *self = PySSLMemoryBIO_CAST(op);
|
PySSLMemoryBIO *self = PySSLMemoryBIO_CAST(op);
|
||||||
PyTypeObject *tp = Py_TYPE(self);
|
PyTypeObject *tp = Py_TYPE(self);
|
||||||
PyObject_GC_UnTrack(self);
|
|
||||||
(void)BIO_free(self->bio);
|
(void)BIO_free(self->bio);
|
||||||
tp->tp_free(self);
|
tp->tp_free(self);
|
||||||
Py_DECREF(tp);
|
Py_DECREF(tp);
|
||||||
|
|
@ -5957,15 +5956,13 @@ static PyType_Slot PySSLMemoryBIO_slots[] = {
|
||||||
{Py_tp_getset, memory_bio_getsetlist},
|
{Py_tp_getset, memory_bio_getsetlist},
|
||||||
{Py_tp_new, _ssl_MemoryBIO},
|
{Py_tp_new, _ssl_MemoryBIO},
|
||||||
{Py_tp_dealloc, memory_bio_dealloc},
|
{Py_tp_dealloc, memory_bio_dealloc},
|
||||||
{Py_tp_traverse, _PyObject_VisitType},
|
|
||||||
{0, 0},
|
{0, 0},
|
||||||
};
|
};
|
||||||
|
|
||||||
static PyType_Spec PySSLMemoryBIO_spec = {
|
static PyType_Spec PySSLMemoryBIO_spec = {
|
||||||
.name = "_ssl.MemoryBIO",
|
.name = "_ssl.MemoryBIO",
|
||||||
.basicsize = sizeof(PySSLMemoryBIO),
|
.basicsize = sizeof(PySSLMemoryBIO),
|
||||||
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IMMUTABLETYPE |
|
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IMMUTABLETYPE),
|
||||||
Py_TPFLAGS_HAVE_GC),
|
|
||||||
.slots = PySSLMemoryBIO_slots,
|
.slots = PySSLMemoryBIO_slots,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -660,7 +660,6 @@ static void
|
||||||
PyThreadHandleObject_dealloc(PyObject *op)
|
PyThreadHandleObject_dealloc(PyObject *op)
|
||||||
{
|
{
|
||||||
PyThreadHandleObject *self = PyThreadHandleObject_CAST(op);
|
PyThreadHandleObject *self = PyThreadHandleObject_CAST(op);
|
||||||
PyObject_GC_UnTrack(self);
|
|
||||||
PyTypeObject *tp = Py_TYPE(self);
|
PyTypeObject *tp = Py_TYPE(self);
|
||||||
ThreadHandle_decref(self->handle);
|
ThreadHandle_decref(self->handle);
|
||||||
tp->tp_free(self);
|
tp->tp_free(self);
|
||||||
|
|
@ -748,7 +747,6 @@ static PyType_Slot ThreadHandle_Type_slots[] = {
|
||||||
{Py_tp_dealloc, PyThreadHandleObject_dealloc},
|
{Py_tp_dealloc, PyThreadHandleObject_dealloc},
|
||||||
{Py_tp_repr, PyThreadHandleObject_repr},
|
{Py_tp_repr, PyThreadHandleObject_repr},
|
||||||
{Py_tp_getset, ThreadHandle_getsetlist},
|
{Py_tp_getset, ThreadHandle_getsetlist},
|
||||||
{Py_tp_traverse, _PyObject_VisitType},
|
|
||||||
{Py_tp_methods, ThreadHandle_methods},
|
{Py_tp_methods, ThreadHandle_methods},
|
||||||
{Py_tp_new, PyThreadHandleObject_tp_new},
|
{Py_tp_new, PyThreadHandleObject_tp_new},
|
||||||
{0, 0}
|
{0, 0}
|
||||||
|
|
@ -758,7 +756,7 @@ static PyType_Spec ThreadHandle_Type_spec = {
|
||||||
"_thread._ThreadHandle",
|
"_thread._ThreadHandle",
|
||||||
sizeof(PyThreadHandleObject),
|
sizeof(PyThreadHandleObject),
|
||||||
0,
|
0,
|
||||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IMMUTABLETYPE | Py_TPFLAGS_HAVE_GC,
|
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IMMUTABLETYPE,
|
||||||
ThreadHandle_Type_slots,
|
ThreadHandle_Type_slots,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -756,7 +756,7 @@ _hmac_new_impl(PyObject *module, PyObject *keyobj, PyObject *msgobj,
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
HMACObject *self = PyObject_GC_New(HMACObject, state->hmac_type);
|
HMACObject *self = PyObject_New(HMACObject, state->hmac_type);
|
||||||
if (self == NULL) {
|
if (self == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
@ -791,7 +791,6 @@ _hmac_new_impl(PyObject *module, PyObject *keyobj, PyObject *msgobj,
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
assert(rc == 0);
|
assert(rc == 0);
|
||||||
PyObject_GC_Track(self);
|
|
||||||
return (PyObject *)self;
|
return (PyObject *)self;
|
||||||
|
|
||||||
error_on_key:
|
error_on_key:
|
||||||
|
|
@ -852,7 +851,7 @@ _hmac_HMAC_copy_impl(HMACObject *self, PyTypeObject *cls)
|
||||||
/*[clinic end generated code: output=a955bfa55b65b215 input=17b2c0ad0b147e36]*/
|
/*[clinic end generated code: output=a955bfa55b65b215 input=17b2c0ad0b147e36]*/
|
||||||
{
|
{
|
||||||
hmacmodule_state *state = get_hmacmodule_state_by_cls(cls);
|
hmacmodule_state *state = get_hmacmodule_state_by_cls(cls);
|
||||||
HMACObject *copy = PyObject_GC_New(HMACObject, state->hmac_type);
|
HMACObject *copy = PyObject_New(HMACObject, state->hmac_type);
|
||||||
if (copy == NULL) {
|
if (copy == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
@ -870,7 +869,6 @@ _hmac_HMAC_copy_impl(HMACObject *self, PyTypeObject *cls)
|
||||||
}
|
}
|
||||||
|
|
||||||
HASHLIB_INIT_MUTEX(copy);
|
HASHLIB_INIT_MUTEX(copy);
|
||||||
PyObject_GC_Track(copy);
|
|
||||||
return (PyObject *)copy;
|
return (PyObject *)copy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1026,7 +1024,6 @@ static void
|
||||||
HMACObject_dealloc(PyObject *op)
|
HMACObject_dealloc(PyObject *op)
|
||||||
{
|
{
|
||||||
PyTypeObject *type = Py_TYPE(op);
|
PyTypeObject *type = Py_TYPE(op);
|
||||||
PyObject_GC_UnTrack(op);
|
|
||||||
(void)HMACObject_clear(op);
|
(void)HMACObject_clear(op);
|
||||||
type->tp_free(op);
|
type->tp_free(op);
|
||||||
Py_DECREF(type);
|
Py_DECREF(type);
|
||||||
|
|
@ -1051,9 +1048,7 @@ static PyType_Slot HMACObject_Type_slots[] = {
|
||||||
{Py_tp_repr, HMACObject_repr},
|
{Py_tp_repr, HMACObject_repr},
|
||||||
{Py_tp_methods, HMACObject_methods},
|
{Py_tp_methods, HMACObject_methods},
|
||||||
{Py_tp_getset, HMACObject_getsets},
|
{Py_tp_getset, HMACObject_getsets},
|
||||||
{Py_tp_clear, HMACObject_clear},
|
|
||||||
{Py_tp_dealloc, HMACObject_dealloc},
|
{Py_tp_dealloc, HMACObject_dealloc},
|
||||||
{Py_tp_traverse, _PyObject_VisitType},
|
|
||||||
{0, NULL} /* sentinel */
|
{0, NULL} /* sentinel */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -1063,8 +1058,7 @@ static PyType_Spec HMAC_Type_spec = {
|
||||||
.flags = Py_TPFLAGS_DEFAULT
|
.flags = Py_TPFLAGS_DEFAULT
|
||||||
| Py_TPFLAGS_DISALLOW_INSTANTIATION
|
| Py_TPFLAGS_DISALLOW_INSTANTIATION
|
||||||
| Py_TPFLAGS_HEAPTYPE
|
| Py_TPFLAGS_HEAPTYPE
|
||||||
| Py_TPFLAGS_IMMUTABLETYPE
|
| Py_TPFLAGS_IMMUTABLETYPE,
|
||||||
| Py_TPFLAGS_HAVE_GC,
|
|
||||||
.slots = HMACObject_Type_slots,
|
.slots = HMACObject_Type_slots,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue