Skip to content

Commit

Permalink
Merge pull request #1058 from sebpuetz/dict-unsendable
Browse files Browse the repository at this point in the history
Move the ThreadChecker field in front of dict and weakref.
  • Loading branch information
davidhewitt authored Jul 20, 2020
2 parents be67a15 + e75f768 commit 4cf0db0
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

### Fixed
- Conversion from types with an `__index__` method to Rust BigInts. [#1027](https://github.com/PyO3/pyo3/pull/1027)
- Fix segfault with #[pyclass(dict, unsendable)] [#1058](https://github.com/PyO3/pyo3/pull/1058)

## [0.11.1] - 2020-06-30
### Added
Expand Down
2 changes: 1 addition & 1 deletion src/pycell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,9 @@ impl<T: PyClass> PyCellInner<T> {
#[repr(C)]
pub struct PyCell<T: PyClass> {
inner: PyCellInner<T>,
thread_checker: T::ThreadChecker,
dict: T::Dict,
weakref: T::WeakRef,
thread_checker: T::ThreadChecker,
}

unsafe impl<T: PyClass> PyNativeType for PyCell<T> {}
Expand Down
21 changes: 21 additions & 0 deletions tests/test_unsendable_dict.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use pyo3::prelude::*;
use pyo3::py_run;

#[pyclass(dict, unsendable)]
struct UnsendableDictClass {}

#[pymethods]
impl UnsendableDictClass {
#[new]
fn new() -> Self {
UnsendableDictClass {}
}
}

#[test]
fn test_unsendable_dict() {
let gil = Python::acquire_gil();
let py = gil.python();
let inst = Py::new(py, UnsendableDictClass {}).unwrap();
py_run!(py, inst, "assert inst.__dict__ == {}");
}

0 comments on commit 4cf0db0

Please sign in to comment.