mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
bpo-43916: Apply Py_TPFLAGS_DISALLOW_INSTANTIATION to selected types (GH-25748)
Apply Py_TPFLAGS_DISALLOW_INSTANTIATION to the following types: * _dbm.dbm * _gdbm.gdbm * _multibytecodec.MultibyteCodec * _sre..SRE_Scanner * _thread._localdummy * _thread.lock * _winapi.Overlapped * array.arrayiterator * functools.KeyWrapper * functools._lru_list_elem * pyexpat.xmlparser * re.Match * re.Pattern * unicodedata.UCD * zlib.Compress * zlib.Decompress
This commit is contained in:
parent
387397f8a4
commit
9746cda705
20 changed files with 87 additions and 28 deletions
|
@ -414,7 +414,7 @@ static PyType_Spec dbmtype_spec = {
|
|||
// dbmtype_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_DISALLOW_INSTANTIATION,
|
||||
.slots = dbmtype_spec_slots,
|
||||
};
|
||||
|
||||
|
|
|
@ -546,7 +546,7 @@ static PyType_Slot keyobject_type_slots[] = {
|
|||
static PyType_Spec keyobject_type_spec = {
|
||||
.name = "functools.KeyWrapper",
|
||||
.basicsize = sizeof(keyobject),
|
||||
.flags = Py_TPFLAGS_DEFAULT,
|
||||
.flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_DISALLOW_INSTANTIATION,
|
||||
.slots = keyobject_type_slots
|
||||
};
|
||||
|
||||
|
@ -766,7 +766,7 @@ 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,
|
||||
.flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_DISALLOW_INSTANTIATION,
|
||||
.slots = lru_list_elem_type_slots
|
||||
};
|
||||
|
||||
|
|
|
@ -570,7 +570,7 @@ static PyType_Spec gdbmtype_spec = {
|
|||
// dbmtype_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_DISALLOW_INSTANTIATION,
|
||||
.slots = gdbmtype_spec_slots,
|
||||
};
|
||||
|
||||
|
|
|
@ -2690,7 +2690,8 @@ static PyType_Spec pattern_spec = {
|
|||
.name = "re.Pattern",
|
||||
.basicsize = sizeof(PatternObject),
|
||||
.itemsize = sizeof(SRE_CODE),
|
||||
.flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IMMUTABLETYPE,
|
||||
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IMMUTABLETYPE |
|
||||
Py_TPFLAGS_DISALLOW_INSTANTIATION),
|
||||
.slots = pattern_slots,
|
||||
};
|
||||
|
||||
|
@ -2755,7 +2756,8 @@ static PyType_Spec match_spec = {
|
|||
.name = "re.Match",
|
||||
.basicsize = sizeof(MatchObject),
|
||||
.itemsize = sizeof(Py_ssize_t),
|
||||
.flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IMMUTABLETYPE,
|
||||
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IMMUTABLETYPE |
|
||||
Py_TPFLAGS_DISALLOW_INSTANTIATION),
|
||||
.slots = match_slots,
|
||||
};
|
||||
|
||||
|
@ -2781,7 +2783,8 @@ static PyType_Slot scanner_slots[] = {
|
|||
static PyType_Spec scanner_spec = {
|
||||
.name = "_" SRE_MODULE ".SRE_Scanner",
|
||||
.basicsize = sizeof(ScannerObject),
|
||||
.flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IMMUTABLETYPE,
|
||||
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IMMUTABLETYPE |
|
||||
Py_TPFLAGS_DISALLOW_INSTANTIATION),
|
||||
.slots = scanner_slots,
|
||||
};
|
||||
|
||||
|
|
|
@ -312,7 +312,8 @@ static PyType_Slot lock_type_slots[] = {
|
|||
static PyType_Spec lock_type_spec = {
|
||||
.name = "_thread.lock",
|
||||
.basicsize = sizeof(lockobject),
|
||||
.flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,
|
||||
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
|
||||
Py_TPFLAGS_DISALLOW_INSTANTIATION),
|
||||
.slots = lock_type_slots,
|
||||
};
|
||||
|
||||
|
@ -683,7 +684,7 @@ static PyType_Slot local_dummy_type_slots[] = {
|
|||
static PyType_Spec local_dummy_type_spec = {
|
||||
.name = "_thread._localdummy",
|
||||
.basicsize = sizeof(localdummyobject),
|
||||
.flags = Py_TPFLAGS_DEFAULT,
|
||||
.flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_DISALLOW_INSTANTIATION,
|
||||
.slots = local_dummy_type_slots,
|
||||
};
|
||||
|
||||
|
|
|
@ -331,7 +331,7 @@ static PyType_Slot winapi_overlapped_type_slots[] = {
|
|||
static PyType_Spec winapi_overlapped_type_spec = {
|
||||
.name = "_winapi.Overlapped",
|
||||
.basicsize = sizeof(OverlappedObject),
|
||||
.flags = Py_TPFLAGS_DEFAULT,
|
||||
.flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_DISALLOW_INSTANTIATION,
|
||||
.slots = winapi_overlapped_type_slots,
|
||||
};
|
||||
|
||||
|
|
|
@ -2987,7 +2987,8 @@ static PyType_Slot arrayiter_slots[] = {
|
|||
static PyType_Spec arrayiter_spec = {
|
||||
.name = "array.arrayiterator",
|
||||
.basicsize = sizeof(arrayiterobject),
|
||||
.flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,
|
||||
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
|
||||
Py_TPFLAGS_DISALLOW_INSTANTIATION),
|
||||
.slots = arrayiter_slots,
|
||||
};
|
||||
|
||||
|
|
|
@ -748,7 +748,8 @@ static PyType_Slot multibytecodec_slots[] = {
|
|||
static PyType_Spec multibytecodec_spec = {
|
||||
.name = MODULE_NAME ".MultibyteCodec",
|
||||
.basicsize = sizeof(MultibyteCodecObject),
|
||||
.flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,
|
||||
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
|
||||
Py_TPFLAGS_DISALLOW_INSTANTIATION),
|
||||
.slots = multibytecodec_slots,
|
||||
};
|
||||
|
||||
|
|
|
@ -1506,7 +1506,8 @@ static PyType_Slot _xml_parse_type_spec_slots[] = {
|
|||
static PyType_Spec _xml_parse_type_spec = {
|
||||
.name = "pyexpat.xmlparser",
|
||||
.basicsize = sizeof(xmlparseobject),
|
||||
.flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,
|
||||
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
|
||||
Py_TPFLAGS_DISALLOW_INSTANTIATION),
|
||||
.slots = _xml_parse_type_spec_slots,
|
||||
};
|
||||
|
||||
|
|
|
@ -1454,7 +1454,7 @@ static PyType_Slot ucd_type_slots[] = {
|
|||
static PyType_Spec ucd_type_spec = {
|
||||
.name = "unicodedata.UCD",
|
||||
.basicsize = sizeof(PreviousDBVersion),
|
||||
.flags = Py_TPFLAGS_DEFAULT,
|
||||
.flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_DISALLOW_INSTANTIATION,
|
||||
.slots = ucd_type_slots
|
||||
};
|
||||
|
||||
|
|
|
@ -1386,11 +1386,10 @@ static PyType_Slot Comptype_slots[] = {
|
|||
};
|
||||
|
||||
static PyType_Spec Comptype_spec = {
|
||||
"zlib.Compress",
|
||||
sizeof(compobject),
|
||||
0,
|
||||
Py_TPFLAGS_DEFAULT,
|
||||
Comptype_slots
|
||||
.name = "zlib.Compress",
|
||||
.basicsize = sizeof(compobject),
|
||||
.flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_DISALLOW_INSTANTIATION,
|
||||
.slots= Comptype_slots,
|
||||
};
|
||||
|
||||
static PyType_Slot Decomptype_slots[] = {
|
||||
|
@ -1401,11 +1400,10 @@ static PyType_Slot Decomptype_slots[] = {
|
|||
};
|
||||
|
||||
static PyType_Spec Decomptype_spec = {
|
||||
"zlib.Decompress",
|
||||
sizeof(compobject),
|
||||
0,
|
||||
Py_TPFLAGS_DEFAULT,
|
||||
Decomptype_slots
|
||||
.name = "zlib.Decompress",
|
||||
.basicsize = sizeof(compobject),
|
||||
.flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_DISALLOW_INSTANTIATION,
|
||||
.slots = Decomptype_slots,
|
||||
};
|
||||
|
||||
PyDoc_STRVAR(zlib_module_documentation,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue