Skip to content

Commit 11d29cc

Browse files
committed
Switch from pyo3::internal_utils::ensure_gil to with_gil
In PyO3/pyo3#1115 the internal_utils module was removed from pyo3. There is a note in the review that rust-numpy will need to migrate to using with_gil() instead. This commit makes this change to enable running with pyo3 0.12.0.
1 parent 242590a commit 11d29cc

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ libc = "0.2"
1515
num-complex = "0.2"
1616
num-traits = "0.2"
1717
ndarray = ">=0.13"
18-
pyo3 = { git = "https://github.com/PyO3/pyo3" }
18+
pyo3 = "0.12.0"
1919

2020
[features]
2121
# In default setting, python version is automatically detected

src/npyffi/array.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,10 @@ impl PyArrayAPI {
4242
}
4343
fn get(&self, offset: isize) -> *const *const c_void {
4444
if self.api.get().is_null() {
45-
let ensure_gil = pyo3::internal_utils::ensure_gil();
46-
let api = get_numpy_api(unsafe { ensure_gil.python() }, MOD_NAME, CAPSULE_NAME);
47-
self.api.set(api);
45+
Python::with_gil(|py| {
46+
let api = get_numpy_api(py, MOD_NAME, CAPSULE_NAME);
47+
self.api.set(api);
48+
})
4849
}
4950
unsafe { self.api.get().offset(offset) }
5051
}

src/npyffi/ufunc.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use std::os::raw::*;
44
use std::{cell::Cell, ptr};
55

66
use pyo3::ffi::PyObject;
7+
use pyo3::Python;
78

89
use super::get_numpy_api;
910
use super::objects::*;
@@ -28,9 +29,10 @@ impl PyUFuncAPI {
2829
}
2930
fn get(&self, offset: isize) -> *const *const c_void {
3031
if self.api.get().is_null() {
31-
let ensure_gil = pyo3::internal_utils::ensure_gil();
32-
let api = get_numpy_api(unsafe { ensure_gil.python() }, MOD_NAME, CAPSULE_NAME);
33-
self.api.set(api);
32+
Python::with_gil(|py| {
33+
let api = get_numpy_api(py, MOD_NAME, CAPSULE_NAME);
34+
self.api.set(api);
35+
})
3436
}
3537
unsafe { self.api.get().offset(offset) }
3638
}

0 commit comments

Comments
 (0)