Skip to content

Commit b0bf63d

Browse files
authored
Merge pull request #1 from mtreinish/pyo3_0.12_compatible
Finish migration for pyo3 0.12.0
2 parents 242590a + d701b12 commit b0bf63d

File tree

6 files changed

+15
-12
lines changed

6 files changed

+15
-12
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

examples/linalg/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ ndarray = ">= 0.13"
1414
ndarray-linalg = { version = "0.12", features = ["openblas"] }
1515

1616
[dependencies.pyo3]
17-
version = "0.11.1"
17+
version = "0.12.0"
1818
features = ["extension-module"]

examples/simple-extension/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ numpy = { path = "../.." }
1313
ndarray = ">= 0.12"
1414

1515
[dependencies.pyo3]
16-
version = "0.11.1"
16+
version = "0.12.0"
1717
features = ["extension-module"]

src/error.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Defines error types.
22
use crate::types::DataType;
3-
use pyo3::{exceptions as exc, PyErr, PyErrArguments, PyErrValue, PyObject, Python, ToPyObject};
3+
use pyo3::{exceptions as exc, PyErr, PyErrArguments, PyObject, Python, ToPyObject};
44
use std::fmt;
55

66
/// Represents a dimension and dtype of numpy array.
@@ -63,14 +63,14 @@ macro_rules! impl_pyerr {
6363
impl std::error::Error for $err_type {}
6464

6565
impl PyErrArguments for $err_type {
66-
fn arguments(&self, py: Python) -> PyObject {
66+
fn arguments(self, py: Python) -> PyObject {
6767
format!("{}", self).to_object(py)
6868
}
6969
}
7070

7171
impl std::convert::From<$err_type> for PyErr {
7272
fn from(err: $err_type) -> PyErr {
73-
PyErr::from_value::<exc::PyTypeError>(PyErrValue::from_err_args(err))
73+
exc::PyTypeError::new_err(err)
7474
}
7575
}
7676
};

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)