-
Notifications
You must be signed in to change notification settings - Fork 806
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix lifetime safety bug of AsPyRef::as_ref(). (#876)
* Fix lifetime safety bug of AsPyRef::as_ref(). Fixes #875. * Add test for AsPyRef's lifetimes.
- Loading branch information
Showing
5 changed files
with
24 additions
and
3 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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
use pyo3::{types::PyDict, AsPyRef, Py, PyNativeType, Python}; | ||
|
||
fn main() { | ||
let gil = Python::acquire_gil(); | ||
let dict: Py<PyDict> = PyDict::new(gil.python()).into(); | ||
let dict: &PyDict = dict.as_ref(gil.python()); | ||
drop(gil); | ||
|
||
let _py: Python = dict.py(); // Obtain a Python<'p> without GIL. | ||
} |
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,10 @@ | ||
error[E0505]: cannot move out of `gil` because it is borrowed | ||
--> $DIR/wrong_aspyref_lifetimes.rs:7:10 | ||
| | ||
6 | let dict: &PyDict = dict.as_ref(gil.python()); | ||
| --- borrow of `gil` occurs here | ||
7 | drop(gil); | ||
| ^^^ move out of `gil` occurs here | ||
8 | | ||
9 | let _py: Python = dict.py(); // Obtain a Python<'p> without GIL. | ||
| ---- borrow later used here |