bpo-43908: Make heap types converted during 3.10 alpha immutable (GH-26351)

* Make functools types immutable

* Multibyte codec types are now immutable

* pyexpat.xmlparser is now immutable

* array.arrayiterator is now immutable

* _thread types are now immutable

* _csv types are now immutable

* _queue.SimpleQueue is now immutable

* mmap.mmap is now immutable

* unicodedata.UCD is now immutable

* sqlite3 types are now immutable

* _lsprof.Profiler is now immutable

* _overlapped.Overlapped is now immutable

* _operator types are now immutable

* winapi__overlapped.Overlapped is now immutable

* _lzma types are now immutable

* _bz2 types are now immutable

* _dbm.dbm and _gdbm.gdbm are now immutable
This commit is contained in:
Erlend Egeberg Aasland 2021-06-17 12:06:09 +02:00 committed by GitHub
parent c544393b89
commit 00710e6346
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 61 additions and 38 deletions

View File

@ -422,7 +422,7 @@ static PyType_Spec bz2_compressor_type_spec = {
// bz2_compressor_type_spec does not have Py_TPFLAGS_BASETYPE flag
// which prevents to create a subclass.
// So calling PyType_GetModuleState() in this file is always safe.
.flags = Py_TPFLAGS_DEFAULT,
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IMMUTABLETYPE),
.slots = bz2_compressor_type_slots,
};
@ -766,7 +766,7 @@ static PyType_Spec bz2_decompressor_type_spec = {
// bz2_decompressor_type_spec does not have Py_TPFLAGS_BASETYPE flag
// which prevents to create a subclass.
// So calling PyType_GetModuleState() in this file is always safe.
.flags = Py_TPFLAGS_DEFAULT,
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IMMUTABLETYPE),
.slots = bz2_decompressor_type_slots,
};

View File

@ -537,7 +537,8 @@ static PyType_Slot Dialect_Type_slots[] = {
PyType_Spec Dialect_Type_spec = {
.name = "_csv.Dialect",
.basicsize = sizeof(DialectObj),
.flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC,
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC |
Py_TPFLAGS_IMMUTABLETYPE),
.slots = Dialect_Type_slots,
};
@ -958,7 +959,8 @@ static PyType_Slot Reader_Type_slots[] = {
PyType_Spec Reader_Type_spec = {
.name = "_csv.reader",
.basicsize = sizeof(ReaderObj),
.flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC,
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC |
Py_TPFLAGS_IMMUTABLETYPE),
.slots = Reader_Type_slots
};
@ -1382,7 +1384,8 @@ static PyType_Slot Writer_Type_slots[] = {
PyType_Spec Writer_Type_spec = {
.name = "_csv.writer",
.basicsize = sizeof(WriterObj),
.flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC,
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC |
Py_TPFLAGS_IMMUTABLETYPE),
.slots = Writer_Type_slots,
};

View File

@ -423,7 +423,7 @@ static PyType_Spec dbmtype_spec = {
// which prevents to create a subclass.
// So calling PyType_GetModuleState() in this file is always safe.
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_DISALLOW_INSTANTIATION |
Py_TPFLAGS_HAVE_GC),
Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_IMMUTABLETYPE),
.slots = dbmtype_spec_slots,
};

View File

@ -491,7 +491,8 @@ static PyType_Spec partial_type_spec = {
.name = "functools.partial",
.basicsize = sizeof(partialobject),
.flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_VECTORCALL,
Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_VECTORCALL |
Py_TPFLAGS_IMMUTABLETYPE,
.slots = partial_type_slots
};
@ -559,7 +560,7 @@ static PyType_Spec keyobject_type_spec = {
.name = "functools.KeyWrapper",
.basicsize = sizeof(keyobject),
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_DISALLOW_INSTANTIATION |
Py_TPFLAGS_HAVE_GC),
Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_IMMUTABLETYPE),
.slots = keyobject_type_slots
};
@ -781,7 +782,8 @@ static PyType_Slot lru_list_elem_type_slots[] = {
static PyType_Spec lru_list_elem_type_spec = {
.name = "functools._lru_list_elem",
.basicsize = sizeof(lru_list_elem),
.flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_DISALLOW_INSTANTIATION,
.flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_DISALLOW_INSTANTIATION |
Py_TPFLAGS_IMMUTABLETYPE,
.slots = lru_list_elem_type_slots
};
@ -1417,7 +1419,7 @@ static PyType_Spec lru_cache_type_spec = {
.name = "functools._lru_cache_wrapper",
.basicsize = sizeof(lru_cache_object),
.flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
Py_TPFLAGS_METHOD_DESCRIPTOR,
Py_TPFLAGS_METHOD_DESCRIPTOR | Py_TPFLAGS_IMMUTABLETYPE,
.slots = lru_cache_type_slots
};

View File

@ -581,7 +581,7 @@ static PyType_Spec gdbmtype_spec = {
// which prevents to create a subclass.
// So calling PyType_GetModuleState() in this file is always safe.
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_DISALLOW_INSTANTIATION |
Py_TPFLAGS_HAVE_GC),
Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_IMMUTABLETYPE),
.slots = gdbmtype_spec_slots,
};

View File

@ -812,7 +812,8 @@ static PyType_Slot _lsprof_profiler_type_spec_slots[] = {
static PyType_Spec _lsprof_profiler_type_spec = {
.name = "_lsprof.Profiler",
.basicsize = sizeof(ProfilerObject),
.flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC,
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE |
Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_IMMUTABLETYPE),
.slots = _lsprof_profiler_type_spec_slots,
};

View File

@ -915,7 +915,7 @@ static PyType_Spec lzma_compressor_type_spec = {
// lzma_compressor_type_spec does not have Py_TPFLAGS_BASETYPE flag
// which prevents to create a subclass.
// So calling PyType_GetModuleState() in this file is always safe.
.flags = Py_TPFLAGS_DEFAULT,
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IMMUTABLETYPE),
.slots = lzma_compressor_type_slots,
};
@ -1359,7 +1359,7 @@ static PyType_Spec lzma_decompressor_type_spec = {
// lzma_decompressor_type_spec does not have Py_TPFLAGS_BASETYPE flag
// which prevents to create a subclass.
// So calling PyType_GetModuleState() in this file is always safe.
.flags = Py_TPFLAGS_DEFAULT,
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IMMUTABLETYPE),
.slots = lzma_decompressor_type_slots,
};

View File

@ -1133,7 +1133,8 @@ static PyType_Spec itemgetter_type_spec = {
.name = "operator.itemgetter",
.basicsize = sizeof(itemgetterobject),
.itemsize = 0,
.flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
Py_TPFLAGS_IMMUTABLETYPE),
.slots = itemgetter_type_slots,
};
@ -1464,7 +1465,8 @@ static PyType_Spec attrgetter_type_spec = {
.name = "operator.attrgetter",
.basicsize = sizeof(attrgetterobject),
.itemsize = 0,
.flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
Py_TPFLAGS_IMMUTABLETYPE),
.slots = attrgetter_type_slots,
};
@ -1719,7 +1721,8 @@ static PyType_Spec methodcaller_type_spec = {
.name = "operator.methodcaller",
.basicsize = sizeof(methodcallerobject),
.itemsize = 0,
.flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
Py_TPFLAGS_IMMUTABLETYPE),
.slots = methodcaller_type_slots,
};

View File

@ -380,7 +380,8 @@ static PyType_Slot simplequeue_slots[] = {
static PyType_Spec simplequeue_spec = {
.name = "_queue.SimpleQueue",
.basicsize = sizeof(simplequeueobject),
.flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC,
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC |
Py_TPFLAGS_IMMUTABLETYPE),
.slots = simplequeue_slots,
};

View File

@ -1914,7 +1914,8 @@ static PyType_Slot connection_slots[] = {
static PyType_Spec connection_spec = {
.name = MODULE_NAME ".Connection",
.basicsize = sizeof(pysqlite_Connection),
.flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC,
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE |
Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_IMMUTABLETYPE),
.slots = connection_slots,
};

View File

@ -1078,7 +1078,8 @@ static PyType_Slot cursor_slots[] = {
static PyType_Spec cursor_spec = {
.name = MODULE_NAME ".Cursor",
.basicsize = sizeof(pysqlite_Cursor),
.flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC,
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE |
Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_IMMUTABLETYPE),
.slots = cursor_slots,
};

View File

@ -56,7 +56,8 @@ static PyType_Slot type_slots[] = {
static PyType_Spec type_spec = {
.name = MODULE_NAME ".PrepareProtocol",
.basicsize = sizeof(pysqlite_PrepareProtocol),
.flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
Py_TPFLAGS_IMMUTABLETYPE),
.slots = type_slots,
};

View File

@ -258,7 +258,8 @@ static PyType_Slot row_slots[] = {
static PyType_Spec row_spec = {
.name = MODULE_NAME ".Row",
.basicsize = sizeof(pysqlite_Row),
.flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC,
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE |
Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_IMMUTABLETYPE),
.slots = row_slots,
};

View File

@ -502,7 +502,8 @@ static PyType_Slot stmt_slots[] = {
static PyType_Spec stmt_spec = {
.name = MODULE_NAME ".Statement",
.basicsize = sizeof(pysqlite_Statement),
.flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
Py_TPFLAGS_IMMUTABLETYPE),
.slots = stmt_slots,
};

View File

@ -313,7 +313,7 @@ static PyType_Spec lock_type_spec = {
.name = "_thread.lock",
.basicsize = sizeof(lockobject),
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
Py_TPFLAGS_DISALLOW_INSTANTIATION),
Py_TPFLAGS_DISALLOW_INSTANTIATION | Py_TPFLAGS_IMMUTABLETYPE),
.slots = lock_type_slots,
};
@ -594,7 +594,8 @@ static PyType_Slot rlock_type_slots[] = {
static PyType_Spec rlock_type_spec = {
.name = "_thread.RLock",
.basicsize = sizeof(rlockobject),
.flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE,
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE |
Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_IMMUTABLETYPE),
.slots = rlock_type_slots,
};
@ -693,7 +694,8 @@ static PyType_Slot local_dummy_type_slots[] = {
static PyType_Spec local_dummy_type_spec = {
.name = "_thread._localdummy",
.basicsize = sizeof(localdummyobject),
.flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_DISALLOW_INSTANTIATION,
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_DISALLOW_INSTANTIATION |
Py_TPFLAGS_IMMUTABLETYPE),
.slots = local_dummy_type_slots,
};
@ -977,7 +979,8 @@ static PyType_Slot local_type_slots[] = {
static PyType_Spec local_type_spec = {
.name = "_thread._local",
.basicsize = sizeof(localobject),
.flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC,
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC |
Py_TPFLAGS_IMMUTABLETYPE),
.slots = local_type_slots,
};

View File

@ -348,7 +348,7 @@ static PyType_Spec winapi_overlapped_type_spec = {
.name = "_winapi.Overlapped",
.basicsize = sizeof(OverlappedObject),
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_DISALLOW_INSTANTIATION |
Py_TPFLAGS_HAVE_GC),
Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_IMMUTABLETYPE),
.slots = winapi_overlapped_type_slots,
};

View File

@ -2997,7 +2997,7 @@ static PyType_Spec arrayiter_spec = {
.name = "array.arrayiterator",
.basicsize = sizeof(arrayiterobject),
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
Py_TPFLAGS_DISALLOW_INSTANTIATION),
Py_TPFLAGS_DISALLOW_INSTANTIATION | Py_TPFLAGS_IMMUTABLETYPE),
.slots = arrayiter_slots,
};

View File

@ -749,7 +749,7 @@ static PyType_Spec multibytecodec_spec = {
.name = MODULE_NAME ".MultibyteCodec",
.basicsize = sizeof(MultibyteCodecObject),
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
Py_TPFLAGS_DISALLOW_INSTANTIATION),
Py_TPFLAGS_DISALLOW_INSTANTIATION | Py_TPFLAGS_IMMUTABLETYPE),
.slots = multibytecodec_slots,
};
@ -1111,7 +1111,8 @@ static PyType_Slot encoder_slots[] = {
static PyType_Spec encoder_spec = {
.name = MODULE_NAME ".MultibyteIncrementalEncoder",
.basicsize = sizeof(MultibyteIncrementalEncoderObject),
.flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE,
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE |
Py_TPFLAGS_IMMUTABLETYPE),
.slots = encoder_slots,
};
@ -1384,7 +1385,8 @@ static PyType_Slot decoder_slots[] = {
static PyType_Spec decoder_spec = {
.name = MODULE_NAME ".MultibyteIncrementalDecoder",
.basicsize = sizeof(MultibyteIncrementalDecoderObject),
.flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE,
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE |
Py_TPFLAGS_IMMUTABLETYPE),
.slots = decoder_slots,
};
@ -1705,7 +1707,8 @@ static PyType_Slot reader_slots[] = {
static PyType_Spec reader_spec = {
.name = MODULE_NAME ".MultibyteStreamReader",
.basicsize = sizeof(MultibyteStreamReaderObject),
.flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE,
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE |
Py_TPFLAGS_IMMUTABLETYPE),
.slots = reader_slots,
};
@ -1925,7 +1928,8 @@ static PyType_Slot writer_slots[] = {
static PyType_Spec writer_spec = {
.name = MODULE_NAME ".MultibyteStreamWriter",
.basicsize = sizeof(MultibyteStreamWriterObject),
.flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE,
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE |
Py_TPFLAGS_IMMUTABLETYPE),
.slots = writer_slots,
};

View File

@ -1121,7 +1121,8 @@ static PyType_Slot mmap_object_slots[] = {
static PyType_Spec mmap_object_spec = {
.name = "mmap.mmap",
.basicsize = sizeof(mmap_object),
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC),
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE |
Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_IMMUTABLETYPE),
.slots = mmap_object_slots,
};

View File

@ -1876,7 +1876,7 @@ static PyType_Slot overlapped_type_slots[] = {
static PyType_Spec overlapped_type_spec = {
.name = "_overlapped.Overlapped",
.basicsize = sizeof(OverlappedObject),
.flags = Py_TPFLAGS_DEFAULT,
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IMMUTABLETYPE),
.slots = overlapped_type_slots
};

View File

@ -1504,7 +1504,7 @@ static PyType_Spec _xml_parse_type_spec = {
.name = "pyexpat.xmlparser",
.basicsize = sizeof(xmlparseobject),
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
Py_TPFLAGS_DISALLOW_INSTANTIATION),
Py_TPFLAGS_DISALLOW_INSTANTIATION | Py_TPFLAGS_IMMUTABLETYPE),
.slots = _xml_parse_type_spec_slots,
};

View File

@ -1465,7 +1465,7 @@ static PyType_Spec ucd_type_spec = {
.name = "unicodedata.UCD",
.basicsize = sizeof(PreviousDBVersion),
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_DISALLOW_INSTANTIATION |
Py_TPFLAGS_HAVE_GC),
Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_IMMUTABLETYPE),
.slots = ucd_type_slots
};