Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions newsfragments/6049.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Require `PyCapsule` destructors to be `'static`.
11 changes: 7 additions & 4 deletions src/types/capsule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ impl PyCapsule {
) -> PyResult<Bound<'py, Self>>
where
T: 'static + Send,
F: FnOnce(T, *mut c_void) + Send,
F: FnOnce(T, *mut c_void) + Send + 'static,
{
// Sanity check for capsule layout
debug_assert_eq!(offset_of!(CapsuleContents::<T, F>, value), 0);
Expand Down Expand Up @@ -229,7 +229,7 @@ impl PyCapsule {
since = "0.29.0",
note = "use `PyCapsule::new_with_value_and_destructor` instead"
)]
pub fn new_with_destructor<T: 'static + Send, F: FnOnce(T, *mut c_void) + Send>(
pub fn new_with_destructor<T: 'static + Send, F: FnOnce(T, *mut c_void) + Send + 'static>(
py: Python<'_>,
value: T,
name: Option<CString>,
Expand Down Expand Up @@ -652,7 +652,7 @@ impl CapsuleName {

// C layout, as casting the capsule pointer to `T` depends on `T` being first.
#[repr(C)]
struct CapsuleContents<T: 'static + Send, D: FnOnce(T, *mut c_void) + Send> {
struct CapsuleContents<T: 'static + Send, D: FnOnce(T, *mut c_void) + Send + 'static> {
/// Value of the capsule
value: T,
/// Destructor to be used by the capsule
Expand All @@ -663,7 +663,10 @@ struct CapsuleContents<T: 'static + Send, D: FnOnce(T, *mut c_void) + Send> {
}

// Wrapping ffi::PyCapsule_Destructor for a user supplied FnOnce(T) for capsule destructor
unsafe extern "C" fn capsule_destructor<T: 'static + Send, F: FnOnce(T, *mut c_void) + Send>(
unsafe extern "C" fn capsule_destructor<
T: 'static + Send,
F: FnOnce(T, *mut c_void) + Send + 'static,
>(
capsule: *mut ffi::PyObject,
) {
/// Gets the pointer and context from the capsule.
Expand Down
Loading