summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorMark Shannon <mark@hotpy.org>2021-05-02 23:38:22 (GMT)
committerGitHub <noreply@github.com>2021-05-02 23:38:22 (GMT)
commit33ec88ac81f23668293d101b83367b086c795e5e (patch)
treeba5203f9375440ef1f63ceffe55f423d3b28195b /Objects
parent9387fac100db359cbb6ec2a76f8a5eba8f9d7b65 (diff)
downloadcpython-33ec88ac81f23668293d101b83367b086c795e5e.zip
cpython-33ec88ac81f23668293d101b83367b086c795e5e.tar.gz
cpython-33ec88ac81f23668293d101b83367b086c795e5e.tar.bz2
bpo-43977: Make sure that tp_flags for pattern matching are inherited correctly. (GH-25813)
Diffstat (limited to 'Objects')
-rw-r--r--Objects/typeobject.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index 621bb0c..e511cf9 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -5713,12 +5713,6 @@ inherit_special(PyTypeObject *type, PyTypeObject *base)
if (PyType_HasFeature(base, _Py_TPFLAGS_MATCH_SELF)) {
type->tp_flags |= _Py_TPFLAGS_MATCH_SELF;
}
- if (PyType_HasFeature(base, Py_TPFLAGS_SEQUENCE)) {
- type->tp_flags |= Py_TPFLAGS_SEQUENCE;
- }
- if (PyType_HasFeature(base, Py_TPFLAGS_MAPPING)) {
- type->tp_flags |= Py_TPFLAGS_MAPPING;
- }
}
static int
@@ -5936,6 +5930,7 @@ inherit_slots(PyTypeObject *type, PyTypeObject *base)
static int add_operators(PyTypeObject *);
static int add_tp_new_wrapper(PyTypeObject *type);
+#define COLLECTION_FLAGS (Py_TPFLAGS_SEQUENCE | Py_TPFLAGS_MAPPING)
static int
type_ready_checks(PyTypeObject *type)
@@ -5962,6 +5957,10 @@ type_ready_checks(PyTypeObject *type)
_PyObject_ASSERT((PyObject *)type, type->tp_as_async->am_send != NULL);
}
+ /* Consistency checks for pattern matching
+ * Py_TPFLAGS_SEQUENCE and Py_TPFLAGS_MAPPING are mutually exclusive */
+ _PyObject_ASSERT((PyObject *)type, (type->tp_flags & COLLECTION_FLAGS) != COLLECTION_FLAGS);
+
if (type->tp_name == NULL) {
PyErr_Format(PyExc_SystemError,
"Type does not define the tp_name field.");
@@ -6156,6 +6155,12 @@ type_ready_inherit_as_structs(PyTypeObject *type, PyTypeObject *base)
}
}
+static void
+inherit_patma_flags(PyTypeObject *type, PyTypeObject *base) {
+ if ((type->tp_flags & COLLECTION_FLAGS) == 0) {
+ type->tp_flags |= base->tp_flags & COLLECTION_FLAGS;
+ }
+}
static int
type_ready_inherit(PyTypeObject *type)
@@ -6175,6 +6180,7 @@ type_ready_inherit(PyTypeObject *type)
if (inherit_slots(type, (PyTypeObject *)b) < 0) {
return -1;
}
+ inherit_patma_flags(type, (PyTypeObject *)b);
}
}