From d13be6411e452b688b0e65a9c1b4a98cfc0bcd10 Mon Sep 17 00:00:00 2001 From: Matti Picus Date: Mon, 3 Feb 2025 05:14:17 +1100 Subject: [PATCH 1/3] PyPy 3.11 does not implement Py_TPFLAGS_MANAGED_DICT --- include/pybind11/detail/class.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/pybind11/detail/class.h b/include/pybind11/detail/class.h index f501467ded..e6a501699d 100644 --- a/include/pybind11/detail/class.h +++ b/include/pybind11/detail/class.h @@ -574,7 +574,7 @@ extern "C" inline int pybind11_clear(PyObject *self) { inline void enable_dynamic_attributes(PyHeapTypeObject *heap_type) { auto *type = &heap_type->ht_type; type->tp_flags |= Py_TPFLAGS_HAVE_GC; -#if PY_VERSION_HEX < 0x030B0000 +#if PY_VERSION_HEX < 0x030B0000 || defined(PYPY_VERSION) type->tp_dictoffset = type->tp_basicsize; // place dict at the end type->tp_basicsize += (ssize_t) sizeof(PyObject *); // and allocate enough space for it #else From 6e590e4aa89cf7fb9902cc13e15ea39363b04297 Mon Sep 17 00:00:00 2001 From: Matti Picus Date: Mon, 3 Feb 2025 06:00:39 +1100 Subject: [PATCH 2/3] add a comment (from review) --- include/pybind11/detail/class.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/pybind11/detail/class.h b/include/pybind11/detail/class.h index e6a501699d..8a0414c7ec 100644 --- a/include/pybind11/detail/class.h +++ b/include/pybind11/detail/class.h @@ -574,7 +574,7 @@ extern "C" inline int pybind11_clear(PyObject *self) { inline void enable_dynamic_attributes(PyHeapTypeObject *heap_type) { auto *type = &heap_type->ht_type; type->tp_flags |= Py_TPFLAGS_HAVE_GC; -#if PY_VERSION_HEX < 0x030B0000 || defined(PYPY_VERSION) +#if PY_VERSION_HEX < 0x030B0000 || defined(PYPY_VERSION) // For PyPy see PR #5508 type->tp_dictoffset = type->tp_basicsize; // place dict at the end type->tp_basicsize += (ssize_t) sizeof(PyObject *); // and allocate enough space for it #else From 0097583da0109101277713f5a6e319201449d4d7 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 2 Feb 2025 19:01:07 +0000 Subject: [PATCH 3/3] style: pre-commit fixes --- include/pybind11/detail/class.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/pybind11/detail/class.h b/include/pybind11/detail/class.h index 8a0414c7ec..1ed2e90c2c 100644 --- a/include/pybind11/detail/class.h +++ b/include/pybind11/detail/class.h @@ -575,8 +575,8 @@ inline void enable_dynamic_attributes(PyHeapTypeObject *heap_type) { auto *type = &heap_type->ht_type; type->tp_flags |= Py_TPFLAGS_HAVE_GC; #if PY_VERSION_HEX < 0x030B0000 || defined(PYPY_VERSION) // For PyPy see PR #5508 - type->tp_dictoffset = type->tp_basicsize; // place dict at the end - type->tp_basicsize += (ssize_t) sizeof(PyObject *); // and allocate enough space for it + type->tp_dictoffset = type->tp_basicsize; // place dict at the end + type->tp_basicsize += (ssize_t) sizeof(PyObject *); // and allocate enough space for it #else type->tp_flags |= Py_TPFLAGS_MANAGED_DICT; #endif