-
Notifications
You must be signed in to change notification settings - Fork 804
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
opt: improve handle_panic generated code
- Loading branch information
1 parent
947055d
commit 3b6d347
Showing
11 changed files
with
76 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,4 @@ pub mod deprecations; | |
pub mod freelist; | ||
#[doc(hidden)] | ||
pub mod frompyobject; | ||
pub(crate) mod not_send; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
use std::marker::PhantomData; | ||
|
||
use crate::Python; | ||
|
||
/// A marker type that makes the type !Send. | ||
/// Temporal hack until https://github.com/rust-lang/rust/issues/13231 is resolved. | ||
#[derive(Copy, Clone)] | ||
pub(crate) struct NotSend(PhantomData<*mut Python<'static>>); | ||
|
||
pub(crate) const NOT_SEND: NotSend = NotSend(PhantomData); | ||
|
||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::NotSend; | ||
|
||
// https://users.rust-lang.org/t/a-macro-to-assert-that-a-type-does-not-implement-trait-bounds/31179 | ||
macro_rules! assert_not_impl { | ||
($x:ty, $($t:path),+ $(,)*) => { | ||
const _: fn() -> () = || { | ||
struct Check<T: ?Sized>(T); | ||
trait AmbiguousIfImpl<A> { fn some_item() { } } | ||
|
||
impl<T: ?Sized> AmbiguousIfImpl<()> for Check<T> { } | ||
impl<T: ?Sized $(+ $t)*> AmbiguousIfImpl<u8> for Check<T> { } | ||
|
||
<Check::<$x> as AmbiguousIfImpl<_>>::some_item() | ||
}; | ||
}; | ||
} | ||
|
||
#[test] | ||
fn not_send() { | ||
assert_not_impl!(NotSend, Send); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
use pyo3::prelude::*; | ||
|
||
fn test_not_send_allow_threads(py: Python) { | ||
py.allow_threads(|| { drop(py); }); | ||
} | ||
|
||
fn main() { | ||
Python::with_gil(|py| { | ||
test_not_send_allow_threads(py); | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
error[E0277]: `*mut pyo3::Python<'static>` cannot be shared between threads safely | ||
--> tests/ui/not_send.rs:4:8 | ||
| | ||
4 | py.allow_threads(|| { drop(py); }); | ||
| ^^^^^^^^^^^^^ `*mut pyo3::Python<'static>` cannot be shared between threads safely | ||
| | ||
= help: within `pyo3::Python<'_>`, the trait `Sync` is not implemented for `*mut pyo3::Python<'static>` | ||
= note: required because it appears within the type `PhantomData<*mut pyo3::Python<'static>>` | ||
= note: required because it appears within the type `pyo3::impl_::not_send::NotSend` | ||
= note: required because it appears within the type `pyo3::Python<'_>` | ||
= note: required because of the requirements on the impl of `Send` for `&pyo3::Python<'_>` | ||
= note: required because it appears within the type `[closure@$DIR/tests/ui/not_send.rs:4:22: 4:38]` |