Skip to content

fix: support PyPy 8.0.0 (3.11 and 3.12) - #6197

Open
henryiii wants to merge 2 commits into
masterfrom
pypy-8
Open

henryiii wants to merge 2 commits into
masterfrom
pypy-8

Conversation

@henryiii

@henryiii henryiii commented Oct 7, 2026

Copy link
Copy Markdown
Collaborator

🤖 AI text below 🤖

Description

Test PyPy 8.0.0 in CI on both 3.11 and 3.12. PyPy 3.12 found two bugs:

  • Deallocating a py::dynamic_attr() instance aborted with "Invalid usage of a dying CPython object". PyPy 3.12's _PyObject_GetDictPtr() now publishes the dict into the C slot and cannot be called from tp_dealloc (on 3.11 it always returned NULL). On PyPy, pybind11 now reads the slot from tp_dictoffset. test_mi_dynamic_attributes now runs the GC so that the crash is deterministic.
  • memoryview::from_buffer() passes temporary shape/strides arrays. PyPy (8.0.0 and older) keeps these pointers without copying them unless they point to the inline _shape/_strides arrays of Py_buffer. On 3.12 this gave a MemoryError. On PyPy, pybind11 now copies the values into those arrays. Upstream PyPy fixed this on the py3.12 branch after 8.0.0.

I ran the full test suite locally on macOS with PyPy 3.11 and 3.12 (8.0.0).

Suggested changelog entry:

  • Support PyPy 8.0.0 (3.11 and 3.12): fix a crash when deallocating py::dynamic_attr() instances and a dangling shape/strides pointer in memoryview::from_buffer() on PyPy.

Fix two problems found with PyPy 3.12:

- Deallocating a py::dynamic_attr() instance aborted, because PyPy 3.12's
  _PyObject_GetDictPtr() cannot be called from tp_dealloc. Read the dict
  slot from tp_dictoffset on PyPy instead.
- memoryview::from_buffer() passed temporary shape/strides arrays, which
  PyPy keeps without copying. Use PyPy's inline _shape/_strides arrays.

Assisted-by: ClaudeCode:claude-opus-5-5
A later PyPy GC at an arbitrary point can run the Python-calling destructor
and abort.

Assisted-by: ClaudeCode:claude-opus-5-5
@henryiii
henryiii marked this pull request as ready for review October 7, 2026 19:16

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant