Skip to content

Commit a2afcbd

Browse files
committed
Remove PyUnstable_TPFLAGS_CAN_IMMORTALIZE
It didn't provide enough security to be useful (because an object could store a reference to something that doesn't support immortalization *after* becoming immortal).
1 parent 678d08a commit a2afcbd

140 files changed

Lines changed: 397 additions & 428 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Doc/includes/newtypes/custom.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ static PyTypeObject CustomType = {
1212
.tp_doc = PyDoc_STR("Custom objects"),
1313
.tp_basicsize = sizeof(CustomObject),
1414
.tp_itemsize = 0,
15-
.tp_flags = _Py_TPFLAGS_CPYTHON,
15+
.tp_flags = Py_TPFLAGS_DEFAULT,
1616
.tp_new = PyType_GenericNew,
1717
};
1818

Doc/includes/newtypes/custom2.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ static PyTypeObject CustomType = {
9898
.tp_doc = PyDoc_STR("Custom objects"),
9999
.tp_basicsize = sizeof(CustomObject),
100100
.tp_itemsize = 0,
101-
.tp_flags = _Py_TPFLAGS_CPYTHON | Py_TPFLAGS_BASETYPE,
101+
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
102102
.tp_new = Custom_new,
103103
.tp_init = Custom_init,
104104
.tp_dealloc = Custom_dealloc,

Doc/includes/newtypes/custom3.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ static PyTypeObject CustomType = {
142142
.tp_doc = PyDoc_STR("Custom objects"),
143143
.tp_basicsize = sizeof(CustomObject),
144144
.tp_itemsize = 0,
145-
.tp_flags = _Py_TPFLAGS_CPYTHON | Py_TPFLAGS_BASETYPE,
145+
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
146146
.tp_new = Custom_new,
147147
.tp_init = Custom_init,
148148
.tp_dealloc = Custom_dealloc,

Doc/includes/newtypes/custom4.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ static PyTypeObject CustomType = {
159159
.tp_doc = PyDoc_STR("Custom objects"),
160160
.tp_basicsize = sizeof(CustomObject),
161161
.tp_itemsize = 0,
162-
.tp_flags = _Py_TPFLAGS_CPYTHON | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC,
162+
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC,
163163
.tp_new = Custom_new,
164164
.tp_init = Custom_init,
165165
.tp_dealloc = Custom_dealloc,

Include/object.h

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -611,22 +611,6 @@ given type object has a specified feature.
611611
Py_TPFLAGS_HAVE_STACKLESS_EXTENSION | \
612612
0)
613613

614-
/* Type supports immortalization.
615-
*
616-
* In order to support immortality, an object must:
617-
* - Be allocated under the "object" or "memory" domain.
618-
* - Not rely on a Py_REFCNT() value to be something other than 0 or 1.
619-
* - Use tp_finalize() and/or PyObject_CallFinalizerFromDealloc() to run destruction code.
620-
* - Traverse all objects it holds a reference to in tp_traverse().
621-
*
622-
* These are all best practices in the C API, but it's not *guaranteed* that a type follows it.
623-
* In practice, there are very few types that don't support the immortalization contract.
624-
*/
625-
#define PyUnstable_TPFLAGS_CAN_IMMORTALIZE (1UL << 16)
626-
627-
/* All types in CPython can immortalize. */
628-
#define _Py_TPFLAGS_CPYTHON Py_TPFLAGS_DEFAULT | PyUnstable_TPFLAGS_CAN_IMMORTALIZE
629-
630614
/* NOTE: Some of the following flags reuse lower bits (removed as part of the
631615
* Python 3.0 transition). */
632616

Modules/_abc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ static PyType_Slot _abc_data_type_spec_slots[] = {
157157
static PyType_Spec _abc_data_type_spec = {
158158
.name = "_abc._abc_data",
159159
.basicsize = sizeof(_abc_data),
160-
.flags = _Py_TPFLAGS_CPYTHON | Py_TPFLAGS_HAVE_GC,
160+
.flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,
161161
.slots = _abc_data_type_spec_slots,
162162
};
163163

Modules/_asynciomodule.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1796,7 +1796,7 @@ static PyType_Slot Future_slots[] = {
17961796
static PyType_Spec Future_spec = {
17971797
.name = "_asyncio.Future",
17981798
.basicsize = sizeof(FutureObj),
1799-
.flags = (_Py_TPFLAGS_CPYTHON | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE |
1799+
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE |
18001800
Py_TPFLAGS_IMMUTABLETYPE | Py_TPFLAGS_MANAGED_DICT |
18011801
Py_TPFLAGS_MANAGED_WEAKREF),
18021802
.slots = Future_slots,
@@ -2039,7 +2039,7 @@ static PyType_Slot FutureIter_slots[] = {
20392039
static PyType_Spec FutureIter_spec = {
20402040
.name = "_asyncio.FutureIter",
20412041
.basicsize = sizeof(futureiterobject),
2042-
.flags = (_Py_TPFLAGS_CPYTHON | Py_TPFLAGS_HAVE_GC |
2042+
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
20432043
Py_TPFLAGS_IMMUTABLETYPE),
20442044
.slots = FutureIter_slots,
20452045
};
@@ -2161,7 +2161,7 @@ static PyType_Slot TaskStepMethWrapper_slots[] = {
21612161
static PyType_Spec TaskStepMethWrapper_spec = {
21622162
.name = "_asyncio.TaskStepMethWrapper",
21632163
.basicsize = sizeof(TaskStepMethWrapper),
2164-
.flags = (_Py_TPFLAGS_CPYTHON | Py_TPFLAGS_HAVE_GC |
2164+
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
21652165
Py_TPFLAGS_IMMUTABLETYPE),
21662166
.slots = TaskStepMethWrapper_slots,
21672167
};
@@ -2981,7 +2981,7 @@ static PyType_Slot Task_slots[] = {
29812981
static PyType_Spec Task_spec = {
29822982
.name = "_asyncio.Task",
29832983
.basicsize = sizeof(TaskObj),
2984-
.flags = (_Py_TPFLAGS_CPYTHON | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE |
2984+
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE |
29852985
Py_TPFLAGS_IMMUTABLETYPE | Py_TPFLAGS_MANAGED_DICT |
29862986
Py_TPFLAGS_MANAGED_WEAKREF),
29872987
.slots = Task_slots,

Modules/_bz2module.c

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

@@ -750,7 +750,7 @@ static PyType_Spec bz2_decompressor_type_spec = {
750750
// bz2_decompressor_type_spec does not have Py_TPFLAGS_BASETYPE flag
751751
// which prevents to create a subclass.
752752
// So calling PyType_GetModuleState() in this file is always safe.
753-
.flags = (_Py_TPFLAGS_CPYTHON | Py_TPFLAGS_IMMUTABLETYPE),
753+
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_IMMUTABLETYPE),
754754
.slots = bz2_decompressor_type_slots,
755755
};
756756

Modules/_collectionsmodule.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1881,7 +1881,7 @@ static PyType_Slot deque_slots[] = {
18811881
static PyType_Spec deque_spec = {
18821882
.name = "collections.deque",
18831883
.basicsize = sizeof(dequeobject),
1884-
.flags = (_Py_TPFLAGS_CPYTHON | Py_TPFLAGS_BASETYPE |
1884+
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE |
18851885
Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_SEQUENCE |
18861886
Py_TPFLAGS_IMMUTABLETYPE),
18871887
.slots = deque_slots,
@@ -2073,7 +2073,7 @@ static PyType_Slot dequeiter_slots[] = {
20732073
static PyType_Spec dequeiter_spec = {
20742074
.name = "collections._deque_iterator",
20752075
.basicsize = sizeof(dequeiterobject),
2076-
.flags = (_Py_TPFLAGS_CPYTHON | Py_TPFLAGS_HAVE_GC |
2076+
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
20772077
Py_TPFLAGS_IMMUTABLETYPE),
20782078
.slots = dequeiter_slots,
20792079
};
@@ -2191,7 +2191,7 @@ static PyType_Slot dequereviter_slots[] = {
21912191
static PyType_Spec dequereviter_spec = {
21922192
.name = "collections._deque_reverse_iterator",
21932193
.basicsize = sizeof(dequeiterobject),
2194-
.flags = (_Py_TPFLAGS_CPYTHON | Py_TPFLAGS_HAVE_GC |
2194+
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
21952195
Py_TPFLAGS_IMMUTABLETYPE),
21962196
.slots = dequereviter_slots,
21972197
};
@@ -2501,7 +2501,7 @@ static PyType_Slot defdict_slots[] = {
25012501
static PyType_Spec defdict_spec = {
25022502
.name = "collections.defaultdict",
25032503
.basicsize = sizeof(defdictobject),
2504-
.flags = (_Py_TPFLAGS_CPYTHON | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC |
2504+
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC |
25052505
Py_TPFLAGS_IMMUTABLETYPE),
25062506
.slots = defdict_slots,
25072507
};
@@ -2773,7 +2773,7 @@ static PyType_Slot tuplegetter_slots[] = {
27732773
static PyType_Spec tuplegetter_spec = {
27742774
.name = "collections._tuplegetter",
27752775
.basicsize = sizeof(_tuplegetterobject),
2776-
.flags = (_Py_TPFLAGS_CPYTHON | Py_TPFLAGS_HAVE_GC |
2776+
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
27772777
Py_TPFLAGS_IMMUTABLETYPE),
27782778
.slots = tuplegetter_slots,
27792779
};

Modules/_csv.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,7 @@ static PyType_Slot Dialect_Type_slots[] = {
625625
PyType_Spec Dialect_Type_spec = {
626626
.name = "_csv.Dialect",
627627
.basicsize = sizeof(DialectObj),
628-
.flags = (_Py_TPFLAGS_CPYTHON | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC |
628+
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC |
629629
Py_TPFLAGS_IMMUTABLETYPE),
630630
.slots = Dialect_Type_slots,
631631
};
@@ -1057,7 +1057,7 @@ static PyType_Slot Reader_Type_slots[] = {
10571057
PyType_Spec Reader_Type_spec = {
10581058
.name = "_csv.reader",
10591059
.basicsize = sizeof(ReaderObj),
1060-
.flags = (_Py_TPFLAGS_CPYTHON | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC |
1060+
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC |
10611061
Py_TPFLAGS_IMMUTABLETYPE | Py_TPFLAGS_DISALLOW_INSTANTIATION),
10621062
.slots = Reader_Type_slots
10631063
};
@@ -1514,7 +1514,7 @@ static PyType_Slot Writer_Type_slots[] = {
15141514
PyType_Spec Writer_Type_spec = {
15151515
.name = "_csv.writer",
15161516
.basicsize = sizeof(WriterObj),
1517-
.flags = (_Py_TPFLAGS_CPYTHON | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC |
1517+
.flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC |
15181518
Py_TPFLAGS_IMMUTABLETYPE | Py_TPFLAGS_DISALLOW_INSTANTIATION),
15191519
.slots = Writer_Type_slots,
15201520
};
@@ -1694,7 +1694,7 @@ static PyType_Slot error_slots[] = {
16941694

16951695
PyType_Spec error_spec = {
16961696
.name = "_csv.Error",
1697-
.flags = _Py_TPFLAGS_CPYTHON | Py_TPFLAGS_BASETYPE,
1697+
.flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
16981698
.slots = error_slots,
16991699
};
17001700

0 commit comments

Comments
 (0)