diff options
author | Mark Shannon <mark@hotpy.org> | 2022-08-04 11:21:38 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-04 11:21:38 (GMT) |
commit | 2ab560105b9bfda503148e66e58d1d9a6031745e (patch) | |
tree | 99a68b4ba11bb6666cb3350c7dc233e688c15e7a /Modules | |
parent | d8df7e02071087894e4295e9b299689d8db74973 (diff) | |
download | cpython-2ab560105b9bfda503148e66e58d1d9a6031745e.zip cpython-2ab560105b9bfda503148e66e58d1d9a6031745e.tar.gz cpython-2ab560105b9bfda503148e66e58d1d9a6031745e.tar.bz2 |
GH-92678: Fix tp_dictoffset inheritance. (GH-95596) (GH-95604)
* 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')
-rw-r--r-- | Modules/_testcapimodule.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index 9022ee4..a394f46 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -7321,6 +7321,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}, @@ -7380,6 +7388,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."); @@ -7757,6 +7773,12 @@ PyInit__testcapi(void) } 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 NULL; @@ -7775,6 +7797,12 @@ PyInit__testcapi(void) } PyModule_AddObject(m, "HeapCTypeWithBuffer", HeapCTypeWithBuffer); + PyObject *HeapCTypeWithWeakref2 = PyType_FromSpec(&HeapCTypeWithWeakref2_spec); + if (HeapCTypeWithWeakref2 == NULL) { + return -1; + } + PyModule_AddObject(m, "HeapCTypeWithWeakref2", HeapCTypeWithWeakref2); + PyObject *HeapCTypeSetattr = PyType_FromSpec(&HeapCTypeSetattr_spec); if (HeapCTypeSetattr == NULL) { return NULL; |