8000 bpo-43908: Make heap types converted during 3.10 alpha immutable (GH-… · python/cpython@7297d74 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7297d74

Browse files
miss-islingtonErlend Egeberg Aasland
andauthored
bpo-43908: Make heap types converted during 3.10 alpha immutable (GH-26351) (GH-26766)
* 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 (cherry picked from commit 00710e6) Co-authored-by: Erlend Egeberg Aasland <erlend.aasland@innova.no> Co-authored-by: Erlend Egeberg Aasland <erlend.aasland@innova.no>
1 parent 08f2b9d commit 7297d74

22 files changed

+61
-38
lines changed

Modules/_bz2module.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ static PyType_Spec bz2_compressor_type_spec = {
422422
// bz2_compressor_type_spec does not have Py_TPFLAGS_BASETYPE flag
423423
// which prevents to create a subclass.
424424
// So calling PyType_GetModuleState() in this file is always safe.
425-
.flags = Py_TPFLAGS_DEFAULT,
425+
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IMMUTABLETYPE),
426426
.slots = bz2_compressor_type_slots,
427427
};
428428

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

Modules/_csv.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,8 @@ static PyType_Slot Dialect_Type_slots[] = {
537537
PyType_Spec Dialect_Type_spec = {
538538
.name = "_csv.Dialect",
539539
.basicsize = sizeof(DialectObj),
540-
.flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC,
540+
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC |
541+
Py_TPFLAGS_IMMUTABLETYPE),
541542
.slots = Dialect_Type_slots,
542543
};
543544

@@ -958,7 +959,8 @@ static PyType_Slot Reader_Type_slots[] = {
958959
PyType_Spec Reader_Type_spec = {
959960
.name = "_csv.reader",
960961
.basicsize = sizeof(ReaderObj),
961-
.flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC,
962+
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC |
963+
Py_TPFLAGS_IMMUTABLETYPE),
962964
.slots = Reader_Type_slots
963965
};
964966

@@ -1382,7 +1384,8 @@ static PyType_Slot Writer_Type_slots[] = {
13821384
PyType_Spec Writer_Type_spec = {
13831385
.name = "_csv.writer",
13841386
.basicsize = sizeof(WriterObj),
1385-
.flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC,
1387+
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC |
1388+
Py_TPFLAGS_IMMUTABLETYPE),
13861389
.slots = Writer_Type_slots,
13871390
};
13881391

Modules/_dbmmodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ static PyType_Spec dbmtype_spec = {
424424
// which prevents to create a subclass.
425425
// So calling PyType_GetModuleState() in this file is always safe.
426426
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_DISALLOW_INSTANTIATION |
427-
Py_TPFLAGS_HAVE_GC),
427+
Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_IMMUTABLETYPE),
428428
.slots = dbmtype_spec_slots,
429429
};
430430

Modules/_functoolsmodule.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,8 @@ static PyType_Spec partial_type_spec = {
491491
.name = "functools.partial",
492492
.basicsize = sizeof(partialobject),
493493
.flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
494-
Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_VECTORCALL,
494+
Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_VECTORCALL |
495+
Py_TPFLAGS_IMMUTABLETYPE,
495496
.slots = partial_type_slots
496497
};
497498

@@ -559,7 +560,7 @@ static PyType_Spec keyobject_type_spec = {
559560
.name = "functools.KeyWrapper",
560561
.basicsize = sizeof(keyobject),
561562
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_DISALLOW_INSTANTIATION |
562-
Py_TPFLAGS_HAVE_GC),
563+
Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_IMMUTABLETYPE),
563564
.slots = keyobject_type_slots
564565
};
565566

@@ -781,7 +782,8 @@ static PyType_Slot lru_list_elem_type_slots[] = {
781782
static PyType_Spec lru_list_elem_type_spec = {
782783
.name = "functools._lru_list_elem",
783784
.basicsize = sizeof(lru_list_elem),
784-
.flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_DISALLOW_INSTANTIATION,
785+
.flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_DISALLOW_INSTANTIATION |
786+
Py_TPFLAGS_IMMUTABLETYPE,
785787
.slots = lru_list_elem_type_slots
786788
};
787789

@@ -1417,7 +1419,7 @@ static PyType_Spec lru_cache_type_spec = {
14171419
.name = "functools._lru_cache_wrapper",
14181420
.basicsize = sizeof(lru_cache_object),
14191421
.flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
1420-
Py_TPFLAGS_METHOD_DESCRIPTOR,
1422+
Py_TPFLAGS_METHOD_DESCRIPTOR | Py_TPFLAGS_IMMUTABLETYPE,
14211423
.slots = lru_cache_type_slots
14221424
};
14231425

Modules/_gdbmmodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ static PyType_Spec gdbmtype_spec = {
581581
// which prevents to create a subclass.
582582
// So calling PyType_GetModuleState() in this file is always safe.
583583
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_DISALLOW_INSTANTIATION |
584-
Py_TPFLAGS_HAVE_GC),
584+
Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_IMMUTABLETYPE),
585585
.slots = gdbmtype_spec_slots,
586586
};
587587

Modules/_lsprof.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,8 @@ static PyType_Slot _lsprof_profiler_type_spec_slots[] = {
812812
static PyType_Spec _lsprof_profiler_type_spec = {
813813
.name = "_lsprof.Profiler",
814814
.basicsize = sizeof(ProfilerObject),
815-
.flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC,
815+
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE |
816+
Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_IMMUTABLETYPE),
816817
.slots = _lsprof_profiler_type_spec_slots,
817818
};
818819

Modules/_lzmamodule.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -915,7 +915,7 @@ static PyType_Spec lzma_compressor_type_spec = {
915915
// lzma_compressor_type_spec does not have Py_TPFLAGS_BASETYPE flag
916916
// which prevents to create a subclass.
917917
// So calling PyType_GetModuleState() in this file is always safe.
918-
.flags = Py_TPFLAGS_DEFAULT,
918+
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IMMUTABLETYPE),
919919
.slots = lzma_compressor_type_slots,
920920
};
921921

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

Modules/_operator.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,7 +1133,8 @@ static PyType_Spec itemgetter_type_spec = {
11331133
.name = "operator.itemgetter",
11341134
.basicsize = sizeof(itemgetterobject),
11351135
.itemsize = 0,
1136-
.flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,
1136+
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
1137+
Py_TPFLAGS_IMMUTABLETYPE),
11371138
.slots = itemgetter_type_slots,
11381139
};
11391140

@@ -1464,7 +1465,8 @@ static PyType_Spec attrgetter_type_spec = {
14641465
.name = "operator.attrgetter",
14651466
.basicsize = sizeof(attrgetterobject),
14661467
.itemsize = 0,
1467-
.flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,
1468+
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
1469+
Py_TPFLAGS_IMMUTABLETYPE),
14681470
.slots = attrgetter_type_slots,
14691471
};
14701472

@@ -1719,7 +1721,8 @@ static PyType_Spec methodcaller_type_spec = {
17191721
.name = "operator.methodcaller",
17201722
.basicsize = sizeof(methodcallerobject),
17211723
.itemsize = 0,
1722-
.flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,
1724+
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
1725+
Py_TPFLAGS_IMMUTABLETYPE),
17231726
.slots = methodcaller_type_slots,
17241727
};
17251728

Modules/_queuemodule.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,8 @@ static PyType_Slot simplequeue_slots[] = {
380380
static PyType_Spec simplequeue_spec = {
381381
.name = "_queue.SimpleQueue",
382382
.basicsize = sizeof(simplequeueobject),
383-
.flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC,
383+
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC |
384+
Py_TPFLAGS_IMMUTABLETYPE),
384385
.slots = simplequeue_slots,
385386
};
386387

Modules/_sqlite/connection.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1934,7 +1934,8 @@ static PyType_Slot connection_slots[] = {
19341934
static PyType_Spec connection_spec = {
19351935
.name = MODULE_NAME ".Connection",
19361936
.basicsize = sizeof(pysqlite_Connection),
1937-
.flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC,
1937+
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE |
1938+
Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_IMMUTABLETYPE),
19381939
.slots = connection_slots,
19391940
};
19401941

0 commit comments

Comments
 (0)
0