From f1c8674da29a0b4f7f1790a223515de645f76ecd Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 7 Jun 2022 17:05:17 +0200 Subject: [PATCH] gh-93585: Set PyCode_Type.tp_basicsize to sizeof(PyCodeObject) Cython makes the assumption that PyCode_Type.tp_basicsize equals to sizeof(PyCodeObject). This assumption is no longer true since the commit 2bde6827ea4f136297b2d882480b981ff26262b6. Restore tp_basicsize until the PyCodeObject structure can use a C99 flexible array of size zero with the syntax "char co_code_adaptive[]". --- .../C API/2022-06-07-17-08-35.gh-issue-93585.EfIKlx.rst | 6 ++++++ Objects/codeobject.c | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 Misc/NEWS.d/next/C API/2022-06-07-17-08-35.gh-issue-93585.EfIKlx.rst diff --git a/Misc/NEWS.d/next/C API/2022-06-07-17-08-35.gh-issue-93585.EfIKlx.rst b/Misc/NEWS.d/next/C API/2022-06-07-17-08-35.gh-issue-93585.EfIKlx.rst new file mode 100644 index 00000000000000..76f431d5fdb579 --- /dev/null +++ b/Misc/NEWS.d/next/C API/2022-06-07-17-08-35.gh-issue-93585.EfIKlx.rst @@ -0,0 +1,6 @@ +Set ``PyCode_Type.tp_basicsize`` to ``sizeof(PyCodeObject)``. Cython makes the +assumption that ``PyCode_Type.tp_basicsize`` equals to +``sizeof(PyCodeObject)``. This assumption is no longer true since the commit +2bde6827ea4f136297b2d882480b981ff26262b6. Restore ``tp_basicsize`` until the +PyCodeObject structure can use a C99 flexible array of size zero with the +syntax ``char co_code_adaptive[]``. Patch by Victor Stinner. diff --git a/Objects/codeobject.c b/Objects/codeobject.c index dc6dec1b2a549b..2d4807d2e8c138 100644 --- a/Objects/codeobject.c +++ b/Objects/codeobject.c @@ -1910,7 +1910,7 @@ static struct PyMethodDef code_methods[] = { PyTypeObject PyCode_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) "code", - offsetof(PyCodeObject, co_code_adaptive), + sizeof(PyCodeObject), sizeof(_Py_CODEUNIT), (destructor)code_dealloc, /* tp_dealloc */ 0, /* tp_vectorcall_offset */