summaryrefslogtreecommitdiffstats
path: root/Modules/_testcapi
diff options
context:
space:
mode:
authorMark Shannon <mark@hotpy.org>2022-08-03 17:56:24 (GMT)
committerGitHub <noreply@github.com>2022-08-03 17:56:24 (GMT)
commit906e4509328917fe9951f85457897f6a841e0529 (patch)
tree0ee26881b28d07bc0ec00ae72e3af3f8f134f8a6 /Modules/_testcapi
parent89f52293281b6efc4ef666ef25e677683821f4b9 (diff)
downloadcpython-906e4509328917fe9951f85457897f6a841e0529.zip
cpython-906e4509328917fe9951f85457897f6a841e0529.tar.gz
cpython-906e4509328917fe9951f85457897f6a841e0529.tar.bz2
GH-92678: Fix tp_dictoffset inheritance. (GH-95596)
* Add test for inheriting explicit __dict__ and weakref. * Restore 3.10 behavior for multiple inheritance of C extension classes that store their dictionary at the end of the struct.
Diffstat (limited to 'Modules/_testcapi')
-rw-r--r--Modules/_testcapi/heaptype.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/Modules/_testcapi/heaptype.c b/Modules/_testcapi/heaptype.c
index 9fb0051..12889e8 100644
--- a/Modules/_testcapi/heaptype.c
+++ b/Modules/_testcapi/heaptype.c
@@ -737,6 +737,14 @@ static PyType_Spec HeapCTypeWithDict_spec = {
HeapCTypeWithDict_slots
};
+static PyType_Spec HeapCTypeWithDict2_spec = {
+ "_testcapi.HeapCTypeWithDict2",
+ sizeof(HeapCTypeWithDictObject),
+ 0,
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
+ HeapCTypeWithDict_slots
+};
+
static struct PyMemberDef heapctypewithnegativedict_members[] = {
{"dictobj", T_OBJECT, offsetof(HeapCTypeWithDictObject, dict)},
{"__dictoffset__", T_PYSSIZET, -(Py_ssize_t)sizeof(void*), READONLY},
@@ -796,6 +804,14 @@ static PyType_Spec HeapCTypeWithWeakref_spec = {
HeapCTypeWithWeakref_slots
};
+static PyType_Spec HeapCTypeWithWeakref2_spec = {
+ "_testcapi.HeapCTypeWithWeakref2",
+ sizeof(HeapCTypeWithWeakrefObject),
+ 0,
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
+ HeapCTypeWithWeakref_slots
+};
+
PyDoc_STRVAR(heapctypesetattr__doc__,
"A heap type without GC, but with overridden __setattr__.\n\n"
"The 'value' attribute is set to 10 in __init__ and updated via attribute setting.");
@@ -919,6 +935,12 @@ _PyTestCapi_Init_Heaptype(PyObject *m) {
}
PyModule_AddObject(m, "HeapCTypeWithDict", HeapCTypeWithDict);
+ PyObject *HeapCTypeWithDict2 = PyType_FromSpec(&HeapCTypeWithDict2_spec);
+ if (HeapCTypeWithDict2 == NULL) {
+ return -1;
+ }
+ PyModule_AddObject(m, "HeapCTypeWithDict2", HeapCTypeWithDict2);
+
PyObject *HeapCTypeWithNegativeDict = PyType_FromSpec(&HeapCTypeWithNegativeDict_spec);
if (HeapCTypeWithNegativeDict == NULL) {
return -1;
@@ -931,6 +953,12 @@ _PyTestCapi_Init_Heaptype(PyObject *m) {
}
PyModule_AddObject(m, "HeapCTypeWithWeakref", HeapCTypeWithWeakref);
+ PyObject *HeapCTypeWithWeakref2 = PyType_FromSpec(&HeapCTypeWithWeakref2_spec);
+ if (HeapCTypeWithWeakref2 == NULL) {
+ return -1;
+ }
+ PyModule_AddObject(m, "HeapCTypeWithWeakref2", HeapCTypeWithWeakref2);
+
PyObject *HeapCTypeWithBuffer = PyType_FromSpec(&HeapCTypeWithBuffer_spec);
if (HeapCTypeWithBuffer == NULL) {
return -1;