Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Require the GIL to be held in ReleasePool::drain #585

Merged
merged 1 commit into from
Sep 5, 2019
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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
* Implementing the Using the `gc` parameter for `pyclass` (e.g. `#[pyclass(gc)]`) without implementing the `class::PyGCProtocol` trait is now a compile-time error. Failing to implement this trait could lead to segfaults. [#532](https://github.com/PyO3/pyo3/pull/532)
* `PyByteArray::data` has been replaced with `PyDataArray::to_vec` because returning a `&[u8]` is unsound. (See [this comment](https://github.com/PyO3/pyo3/issues/373#issuecomment-512332696) for a great write-up for why that was unsound)
* Replace `mashup` with `paste`.
* `GILPool` gained a `Python` marker to prevent it from being misused to release Python objects without the GIL held.

## [0.7.0] - 2018-05-26

Expand Down
2 changes: 1 addition & 1 deletion pyo3-derive-backend/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,8 @@ fn function_c_wrapper(name: &Ident, spec: &method::FnSpec<'_>) -> TokenStream {
{
const _LOCATION: &'static str = concat!(stringify!(#name), "()");

let _pool = pyo3::GILPool::new();
let _py = pyo3::Python::assume_gil_acquired();
let _pool = pyo3::GILPool::new(_py);
let _args = _py.from_borrowed_ptr::<pyo3::types::PyTuple>(_args);
let _kwargs: Option<&pyo3::types::PyDict> = _py.from_borrowed_ptr_or_opt(_kwargs);

Expand Down
18 changes: 9 additions & 9 deletions pyo3-derive-backend/src/pymethod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ fn impl_wrap_common(
{
const _LOCATION: &'static str = concat!(
stringify!(#cls), ".", stringify!(#name), "()");
let _pool = pyo3::GILPool::new();
let _py = pyo3::Python::assume_gil_acquired();
let _pool = pyo3::GILPool::new(_py);
#slf
let _result = {
pyo3::derive_utils::IntoPyResult::into_py_result(#body)
Expand All @@ -135,8 +135,8 @@ fn impl_wrap_common(
{
const _LOCATION: &'static str = concat!(
stringify!(#cls), ".", stringify!(#name), "()");
let _pool = pyo3::GILPool::new();
let _py = pyo3::Python::assume_gil_acquired();
let _pool = pyo3::GILPool::new(_py);
#slf
let _args = _py.from_borrowed_ptr::<pyo3::types::PyTuple>(_args);
let _kwargs: Option<&pyo3::types::PyDict> = _py.from_borrowed_ptr_or_opt(_kwargs);
Expand All @@ -163,8 +163,8 @@ pub fn impl_proto_wrap(cls: &syn::Type, name: &syn::Ident, spec: &FnSpec<'_>) ->
_kwargs: *mut pyo3::ffi::PyObject) -> *mut pyo3::ffi::PyObject
{
const _LOCATION: &'static str = concat!(stringify!(#cls),".",stringify!(#name),"()");
let _pool = pyo3::GILPool::new();
let _py = pyo3::Python::assume_gil_acquired();
let _pool = pyo3::GILPool::new(_py);
let _slf = _py.mut_from_borrowed_ptr::<#cls>(_slf);
let _args = _py.from_borrowed_ptr::<pyo3::types::PyTuple>(_args);
let _kwargs: Option<&pyo3::types::PyDict> = _py.from_borrowed_ptr_or_opt(_kwargs);
Expand Down Expand Up @@ -194,8 +194,8 @@ pub fn impl_wrap_new(cls: &syn::Type, name: &syn::Ident, spec: &FnSpec<'_>) -> T
use pyo3::type_object::PyTypeInfo;

const _LOCATION: &'static str = concat!(stringify!(#cls),".",stringify!(#name),"()");
let _pool = pyo3::GILPool::new();
let _py = pyo3::Python::assume_gil_acquired();
let _pool = pyo3::GILPool::new(_py);
match pyo3::type_object::PyRawObject::new(_py, #cls::type_object(), _cls) {
Ok(_obj) => {
let _args = _py.from_borrowed_ptr::<pyo3::types::PyTuple>(_args);
Expand Down Expand Up @@ -240,8 +240,8 @@ fn impl_wrap_init(cls: &syn::Type, name: &syn::Ident, spec: &FnSpec<'_>) -> Toke
_kwargs: *mut pyo3::ffi::PyObject) -> pyo3::libc::c_int
{
const _LOCATION: &'static str = concat!(stringify!(#cls),".",stringify!(#name),"()");
let _pool = pyo3::GILPool::new();
let _py = pyo3::Python::assume_gil_acquired();
let _pool = pyo3::GILPool::new(_py);
let _slf = _py.mut_from_borrowed_ptr::<#cls>(_slf);
let _args = _py.from_borrowed_ptr::<pyo3::types::PyTuple>(_args);
let _kwargs: Option<&pyo3::types::PyDict> = _py.from_borrowed_ptr_or_opt(_kwargs);
Expand Down Expand Up @@ -274,8 +274,8 @@ pub fn impl_wrap_class(cls: &syn::Type, name: &syn::Ident, spec: &FnSpec<'_>) ->
_kwargs: *mut pyo3::ffi::PyObject) -> *mut pyo3::ffi::PyObject
{
const _LOCATION: &'static str = concat!(stringify!(#cls),".",stringify!(#name),"()");
let _pool = pyo3::GILPool::new();
let _py = pyo3::Python::assume_gil_acquired();
let _pool = pyo3::GILPool::new(_py);
let _cls = pyo3::types::PyType::from_type_ptr(_py, _cls as *mut pyo3::ffi::PyTypeObject);
let _args = _py.from_borrowed_ptr::<pyo3::types::PyTuple>(_args);
let _kwargs: Option<&pyo3::types::PyDict> = _py.from_borrowed_ptr_or_opt(_kwargs);
Expand Down Expand Up @@ -303,8 +303,8 @@ pub fn impl_wrap_static(cls: &syn::Type, name: &syn::Ident, spec: &FnSpec<'_>) -
_kwargs: *mut pyo3::ffi::PyObject) -> *mut pyo3::ffi::PyObject
{
const _LOCATION: &'static str = concat!(stringify!(#cls),".",stringify!(#name),"()");
let _pool = pyo3::GILPool::new();
let _py = pyo3::Python::assume_gil_acquired();
let _pool = pyo3::GILPool::new(_py);
let _args = _py.from_borrowed_ptr::<pyo3::types::PyTuple>(_args);
let _kwargs: Option<&pyo3::types::PyDict> = _py.from_borrowed_ptr_or_opt(_kwargs);

Expand All @@ -329,8 +329,8 @@ pub(crate) fn impl_wrap_getter(cls: &syn::Type, name: &syn::Ident, takes_py: boo
{
const _LOCATION: &'static str = concat!(stringify!(#cls),".",stringify!(#name),"()");

let _pool = pyo3::GILPool::new();
let _py = pyo3::Python::assume_gil_acquired();
let _pool = pyo3::GILPool::new(_py);
let _slf = _py.mut_from_borrowed_ptr::<#cls>(_slf);

let result = pyo3::derive_utils::IntoPyResult::into_py_result(#fncall);
Expand Down Expand Up @@ -370,8 +370,8 @@ pub(crate) fn impl_wrap_setter(
_value: *mut pyo3::ffi::PyObject, _: *mut ::std::os::raw::c_void) -> pyo3::libc::c_int
{
const _LOCATION: &'static str = concat!(stringify!(#cls),".",stringify!(#name),"()");
let _pool = pyo3::GILPool::new();
let _py = pyo3::Python::assume_gil_acquired();
let _pool = pyo3::GILPool::new(_py);
let _slf = _py.mut_from_borrowed_ptr::<#cls>(_slf);
let _value = _py.from_borrowed_ptr(_value);

Expand Down
4 changes: 2 additions & 2 deletions src/class/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,8 @@ where
where
T: for<'p> PyObjectGetAttrProtocol<'p>,
{
let _pool = crate::GILPool::new();
let py = Python::assume_gil_acquired();
let _pool = crate::GILPool::new(py);

// Behave like python's __getattr__ (as opposed to __getattribute__) and check
// for existing fields and methods first
Expand Down Expand Up @@ -450,8 +450,8 @@ where
where
T: for<'p> PyObjectRichcmpProtocol<'p>,
{
let _pool = crate::GILPool::new();
let py = Python::assume_gil_acquired();
let _pool = crate::GILPool::new(py);
let slf = py.from_borrowed_ptr::<T>(slf);
let arg = py.from_borrowed_ptr::<PyAny>(arg);

Expand Down
2 changes: 1 addition & 1 deletion src/class/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ where
where
T: for<'p> PyBufferGetBufferProtocol<'p>,
{
let _pool = crate::GILPool::new();
let py = crate::Python::assume_gil_acquired();
let _pool = crate::GILPool::new(py);
let slf = py.mut_from_borrowed_ptr::<T>(slf);

let result = slf.bf_getbuffer(arg1, arg2).into();
Expand Down
4 changes: 2 additions & 2 deletions src/class/gc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ where
where
T: for<'p> PyGCTraverseProtocol<'p>,
{
let _pool = crate::GILPool::new();
let py = Python::assume_gil_acquired();
let _pool = crate::GILPool::new(py);
let slf = py.mut_from_borrowed_ptr::<T>(slf);

let visit = PyVisit {
Expand Down Expand Up @@ -122,8 +122,8 @@ where
where
T: for<'p> PyGCClearProtocol<'p>,
{
let _pool = crate::GILPool::new();
let py = Python::assume_gil_acquired();
let _pool = crate::GILPool::new(py);
let slf = py.mut_from_borrowed_ptr::<T>(slf);

slf.__clear__();
Expand Down
26 changes: 13 additions & 13 deletions src/class/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ macro_rules! py_unary_func {
where
T: for<'p> $trait<'p>,
{
let _pool = $crate::GILPool::new();
let py = $crate::Python::assume_gil_acquired();
let _pool = $crate::GILPool::new(py);
let slf = py.mut_from_borrowed_ptr::<T>(slf);
let res = slf.$f().into();
$crate::callback::cb_convert($conv, py, res.map(|x| x))
Expand All @@ -36,8 +36,8 @@ macro_rules! py_unary_pyref_func {
T: for<'p> $trait<'p>,
{
use $crate::instance::PyRefMut;
let _pool = $crate::GILPool::new();
let py = $crate::Python::assume_gil_acquired();
let _pool = $crate::GILPool::new(py);
let slf = py.mut_from_borrowed_ptr::<T>(slf);
let res = $class::$f(PyRefMut::from_mut(slf)).into();
$crate::callback::cb_convert($conv, py, res)
Expand All @@ -54,8 +54,8 @@ macro_rules! py_len_func {
where
T: for<'p> $trait<'p>,
{
let _pool = $crate::GILPool::new();
let py = Python::assume_gil_acquired();
let _pool = $crate::GILPool::new(py);
let slf = py.mut_from_borrowed_ptr::<T>(slf);

let result = slf.$f().into();
Expand Down Expand Up @@ -84,8 +84,8 @@ macro_rules! py_binary_func {
T: for<'p> $trait<'p>,
{
use $crate::ObjectProtocol;
let _pool = $crate::GILPool::new();
let py = $crate::Python::assume_gil_acquired();
let _pool = $crate::GILPool::new(py);
let slf = py.mut_from_borrowed_ptr::<T>(slf);
let arg = py.from_borrowed_ptr::<$crate::types::PyAny>(arg);

Expand All @@ -112,8 +112,8 @@ macro_rules! py_binary_num_func {
T: for<'p> $trait<'p>,
{
use $crate::ObjectProtocol;
let _pool = $crate::GILPool::new();
let py = $crate::Python::assume_gil_acquired();
let _pool = $crate::GILPool::new(py);
let lhs = py.from_borrowed_ptr::<$crate::types::PyAny>(lhs);
let rhs = py.from_borrowed_ptr::<$crate::types::PyAny>(rhs);

Expand Down Expand Up @@ -144,8 +144,8 @@ macro_rules! py_binary_self_func {
{
use $crate::ObjectProtocol;

let _pool = $crate::GILPool::new();
let py = $crate::Python::assume_gil_acquired();
let _pool = $crate::GILPool::new(py);
let slf1 = py.mut_from_borrowed_ptr::<T>(slf);
let arg = py.from_borrowed_ptr::<$crate::types::PyAny>(arg);

Expand Down Expand Up @@ -180,8 +180,8 @@ macro_rules! py_ssizearg_func {
where
T: for<'p> $trait<'p>,
{
let _pool = $crate::GILPool::new();
let py = $crate::Python::assume_gil_acquired();
let _pool = $crate::GILPool::new(py);
let slf = py.mut_from_borrowed_ptr::<T>(slf);
let result = slf.$f(arg.into()).into();
$crate::callback::cb_convert($conv, py, result)
Expand Down Expand Up @@ -213,8 +213,8 @@ macro_rules! py_ternary_func {
{
use $crate::ObjectProtocol;

let _pool = $crate::GILPool::new();
let py = $crate::Python::assume_gil_acquired();
let _pool = $crate::GILPool::new(py);
let slf = py.mut_from_borrowed_ptr::<T>(slf);
let arg1 = py.from_borrowed_ptr::<$crate::types::PyAny>(arg1);
let arg2 = py.from_borrowed_ptr::<$crate::types::PyAny>(arg2);
Expand Down Expand Up @@ -247,8 +247,8 @@ macro_rules! py_ternary_num_func {
{
use $crate::ObjectProtocol;

let _pool = $crate::GILPool::new();
let py = $crate::Python::assume_gil_acquired();
let _pool = $crate::GILPool::new(py);
let arg1 = py.from_borrowed_ptr::<$crate::types::PyAny>(arg1);
let arg2 = py.from_borrowed_ptr::<$crate::types::PyAny>(arg2);
let arg3 = py.from_borrowed_ptr::<$crate::types::PyAny>(arg3);
Expand Down Expand Up @@ -284,8 +284,8 @@ macro_rules! py_ternary_self_func {
{
use $crate::ObjectProtocol;

let _pool = $crate::GILPool::new();
let py = $crate::Python::assume_gil_acquired();
let _pool = $crate::GILPool::new(py);
let slf1 = py.mut_from_borrowed_ptr::<T>(slf);
let arg1 = py.from_borrowed_ptr::<$crate::types::PyAny>(arg1);
let arg2 = py.from_borrowed_ptr::<$crate::types::PyAny>(arg2);
Expand Down Expand Up @@ -323,8 +323,8 @@ macro_rules! py_func_set {
{
use $crate::ObjectProtocol;

let _pool = $crate::GILPool::new();
let py = $crate::Python::assume_gil_acquired();
let _pool = $crate::GILPool::new(py);
let slf = py.mut_from_borrowed_ptr::<$generic>(slf);

let result = if value.is_null() {
Expand Down Expand Up @@ -371,8 +371,8 @@ macro_rules! py_func_del {
{
use $crate::ObjectProtocol;

let _pool = $crate::GILPool::new();
let py = $crate::Python::assume_gil_acquired();
let _pool = $crate::GILPool::new(py);

let result = if value.is_null() {
let slf = py.mut_from_borrowed_ptr::<U>(slf);
Expand Down Expand Up @@ -413,8 +413,8 @@ macro_rules! py_func_set_del {
{
use $crate::ObjectProtocol;

let _pool = $crate::GILPool::new();
let py = $crate::Python::assume_gil_acquired();
let _pool = $crate::GILPool::new(py);
let slf = py.mut_from_borrowed_ptr::<$generic>(slf);
let name = py.from_borrowed_ptr::<$crate::types::PyAny>(name);

Expand Down
6 changes: 3 additions & 3 deletions src/class/sequence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,8 @@ where
where
T: for<'p> PySequenceSetItemProtocol<'p>,
{
let _pool = crate::GILPool::new();
let py = Python::assume_gil_acquired();
let _pool = crate::GILPool::new(py);
let slf = py.mut_from_borrowed_ptr::<T>(slf);

let result = if value.is_null() {
Expand Down Expand Up @@ -295,8 +295,8 @@ mod sq_ass_item_impl {
where
T: for<'p> PySequenceDelItemProtocol<'p>,
{
let _pool = crate::GILPool::new();
let py = Python::assume_gil_acquired();
let _pool = crate::GILPool::new(py);
let slf = py.mut_from_borrowed_ptr::<T>(slf);

let result = if value.is_null() {
Expand Down Expand Up @@ -341,8 +341,8 @@ mod sq_ass_item_impl {
where
T: for<'p> PySequenceSetItemProtocol<'p> + for<'p> PySequenceDelItemProtocol<'p>,
{
let _pool = crate::GILPool::new();
let py = Python::assume_gil_acquired();
let _pool = crate::GILPool::new(py);
let slf = py.mut_from_borrowed_ptr::<T>(slf);

let result = if value.is_null() {
Expand Down
2 changes: 1 addition & 1 deletion src/derive_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ pub unsafe fn make_module(
return module;
}

let _pool = GILPool::new();
let py = Python::assume_gil_acquired();
let _pool = GILPool::new(py);
let module = match py.from_owned_ptr_or_err::<PyModule>(module) {
Ok(m) => m,
Err(e) => {
Expand Down
Loading