Skip to content

use PyErr::write_unraisable when panicking#5496

Merged
davidhewitt merged 7 commits intoPyO3:mainfrom
davidhewitt:panic-on-non-null
Nov 3, 2025
Merged

use PyErr::write_unraisable when panicking#5496
davidhewitt merged 7 commits intoPyO3:mainfrom
davidhewitt:panic-on-non-null

Conversation

@davidhewitt
Copy link
Copy Markdown
Member

@davidhewitt davidhewitt commented Oct 5, 2025

This PR tidies up the panic pathway of Bound, Borrowed and Py constructors from FFI pointer:

  • Marks the function as #[cold]
  • Send any set exception to PyErr::write_unraisable rather than PyErr_Print.

Overall a minor change but I think is more correct.

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Oct 5, 2025

CodSpeed Performance Report

Merging #5496 will not alter performance

Comparing davidhewitt:panic-on-non-null (0a74e8a) with main (0d4580c)

Summary

✅ 98 untouched

@davidhewitt davidhewitt marked this pull request as ready for review November 1, 2025 20:29
Comment thread src/instance.rs
/// # Safety
///
/// - `ptr` must be a valid pointer to a Python object
/// - `ptr` must be a valid pointer to a Python object (or null, which will cause a panic)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It might make sense to (also?) put this in a "Panics" heading as is done for the Py variants.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Good idea, done 👍

@davidhewitt davidhewitt enabled auto-merge November 3, 2025 08:45
@davidhewitt davidhewitt added this pull request to the merge queue Nov 3, 2025
Merged via the queue into PyO3:main with commit 7d9464b Nov 3, 2025
43 checks passed
@davidhewitt davidhewitt deleted the panic-on-non-null branch November 3, 2025 10:46
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.

2 participants