From 11514efd30447251160daa625cacbd787bc14021 Mon Sep 17 00:00:00 2001 From: Janis Date: Fri, 21 Feb 2025 20:05:02 +0100 Subject: [PATCH] HeapJob drops Job and Self --- src/praetor/mod.rs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/praetor/mod.rs b/src/praetor/mod.rs index 5583431..4e437ca 100644 --- a/src/praetor/mod.rs +++ b/src/praetor/mod.rs @@ -803,15 +803,22 @@ mod job { #[allow(dead_code)] pub struct HeapJob { f: F, + _phantom: PhantomPinned, } impl HeapJob { #[allow(dead_code)] pub fn new(f: F) -> Box { - Box::new(Self { f }) + Box::new(Self { + f, + _phantom: PhantomPinned, + }) + } + pub fn into_inner(self) -> F { + self.f } #[allow(dead_code)] - pub fn into_boxed_job(self: Box) -> Box> + pub fn into_boxed_job(self: Box) -> Pin>> where F: FnOnce(&super::Scope) -> T + Send, T: Send, @@ -824,13 +831,12 @@ mod job { let this = unsafe { Box::from_raw(this.cast::>().cast_mut()) }; let f = this.f; - let result = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| f(scope))); + _ = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| f(scope))); - let job = unsafe { &*job.cast::>() }; - job.complete(result); + _ = unsafe { Box::from_raw(job.cast_mut()) }; } - Box::new(Job::new(harness::, unsafe { + Box::pin(Job::new(harness::, unsafe { NonNull::new_unchecked(Box::into_raw(self)).cast() })) }