Skip to content

Conversation

@davidhewitt
Copy link
Member

Fixes #4632

This adds a test that dropping PyBuffer<T> after finalizing the interpreter won't cause a bad crash. We don't really support the interpreter lifecycle much (other than saying it's unsafe to interact with due to risk of objects outliving the interpreter) but I think it's reasonable to attempt to avoid a segfault, at least.

@davidhewitt davidhewitt mentioned this pull request Jul 19, 2025
@davidhewitt davidhewitt added this to the 0.26 milestone Jul 25, 2025
@davidhewitt
Copy link
Member Author

Anyone got a few mins to review this one so we can get it into 0.26 please? 🙏

Copy link
Contributor

@Icxolu Icxolu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not an expert here, but the implementation makes sense to me and I did not see anything that stood out to me.

@davidhewitt davidhewitt added this pull request to the merge queue Aug 7, 2025
Merged via the queue into PyO3:main with commit cb0a209 Aug 7, 2025
43 checks passed
@davidhewitt davidhewitt deleted the buffer-drop branch August 7, 2025 06:08
Rafa-Gu98 pushed a commit to Rafa-Gu98/pyo3 that referenced this pull request Aug 9, 2025
…5242)

* fix crash when dropping `PyBuffer` after interpreter finalized

* newsfragment

* fixup CI

* fixup test cfgs

* add more test coverage

* fix cfg combinations
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.

Segfault from pyo3 trying to call PyBuffer::drop after Python interpreter already finalized

2 participants