Skip to content

Commit 8eba2fa

Browse files
authored
Merge pull request #93 from stefan-k/bump_pyo3_version
bump to 0.6.0 (broken)
2 parents 99676d3 + 01926dd commit 8eba2fa

File tree

9 files changed

+27
-41
lines changed

9 files changed

+27
-41
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ libc = "0.2.44"
1414
num-complex = "0.2.1"
1515
num-traits = "0.2.6"
1616
ndarray = "0.12"
17-
pyo3 = "0.5.3"
17+
pyo3 = "0.6.0"
1818

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

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,9 @@ extern crate pyo3;
115115

116116
use ndarray::{ArrayD, ArrayViewD, ArrayViewMutD};
117117
use numpy::{IntoPyArray, PyArrayDyn};
118-
use pyo3::prelude::{pymodinit, Py, PyModule, PyResult, Python};
118+
use pyo3::prelude::{pymodule, Py, PyModule, PyResult, Python};
119119

120-
#[pymodinit]
120+
#[pymodule]
121121
fn rust_ext(_py: Python, m: &PyModule) -> PyResult<()> {
122122
// immutable example
123123
fn axpy(a: f64, x: ArrayViewD<f64>, y: ArrayViewD<f64>) -> ArrayD<f64> {

examples/linalg/Cargo.toml

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

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

examples/linalg/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
use ndarray_linalg::solve::Inverse;
22
use numpy::{IntoPyArray, PyArray2};
33
use pyo3::exceptions::RuntimeError;
4-
use pyo3::prelude::{pymodinit, Py, PyErr, PyModule, PyResult, Python};
4+
use pyo3::prelude::{pymodule, Py, PyErr, PyModule, PyResult, Python};
55
use std::fmt::Display;
66

77
fn make_error<E: Display + Sized>(e: E) -> PyErr {
88
PyErr::new::<RuntimeError, _>(format!("[rust_linalg] {}", e))
99
}
1010

11-
#[pymodinit]
11+
#[pymodule]
1212
fn rust_linalg(_py: Python, m: &PyModule) -> PyResult<()> {
1313
#[pyfn(m, "inv")]
1414
fn inv(py: Python, x: &PyArray2<f64>) -> PyResult<Py<PyArray2<f64>>> {

examples/simple-extension/Cargo.toml

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

1414
[dependencies.pyo3]
15-
version = "0.5.3"
15+
version = "0.6.0"
1616
features = ["extension-module"]

examples/simple-extension/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ extern crate pyo3;
44

55
use ndarray::{ArrayD, ArrayViewD, ArrayViewMutD};
66
use numpy::{IntoPyArray, PyArrayDyn};
7-
use pyo3::prelude::{pymodinit, Py, PyModule, PyResult, Python};
7+
use pyo3::prelude::{pymodule, Py, PyModule, PyResult, Python};
88

9-
#[pymodinit]
9+
#[pymodule]
1010
fn rust_ext(_py: Python, m: &PyModule) -> PyResult<()> {
1111
// immutable example
1212
fn axpy(a: f64, x: ArrayViewD<f64>, y: ArrayViewD<f64>) -> ArrayD<f64> {

src/array.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
use ndarray::*;
33
use npyffi::{self, npy_intp, NPY_ORDER, PY_ARRAY_API};
44
use num_traits::AsPrimitive;
5-
use pyo3::{ffi, prelude::*, types::PyObjectRef};
6-
use pyo3::{PyDowncastError, PyObjectWithToken, ToPyPointer};
5+
use pyo3::{ffi, prelude::*, types::PyAny};
6+
use pyo3::{AsPyPointer, PyDowncastError, PyNativeType};
77
use std::iter::ExactSizeIterator;
88
use std::marker::PhantomData;
99
use std::mem;
@@ -37,7 +37,6 @@ use types::{NpyDataType, TypeNum};
3737
/// So you can neither retrieve it nor deallocate it manually.
3838
///
3939
/// # Reference
40-
///
4140
/// Like [`new`](#method.new), all constractor methods of `PyArray` returns `&PyArray`.
4241
///
4342
/// This design follows
@@ -109,9 +108,9 @@ pyobject_native_type_convert!(
109108

110109
pyobject_native_type_named!(PyArray<T, D>, T, D);
111110

112-
impl<'a, T, D> ::std::convert::From<&'a PyArray<T, D>> for &'a PyObjectRef {
111+
impl<'a, T, D> ::std::convert::From<&'a PyArray<T, D>> for &'a PyAny {
113112
fn from(ob: &'a PyArray<T, D>) -> Self {
114-
unsafe { &*(ob as *const PyArray<T, D> as *const PyObjectRef) }
113+
unsafe { &*(ob as *const PyArray<T, D> as *const PyAny) }
115114
}
116115
}
117116

@@ -120,12 +119,12 @@ impl<'a, T: TypeNum, D: Dimension> FromPyObject<'a> for &'a PyArray<T, D> {
120119
// 1. Checks if the object is PyArray
121120
// 2. Checks if the data type of the array is T
122121
// 3. Checks if the dimension is same as D
123-
fn extract(ob: &'a PyObjectRef) -> PyResult<Self> {
122+
fn extract(ob: &'a PyAny) -> PyResult<Self> {
124123
let array = unsafe {
125124
if npyffi::PyArray_Check(ob.as_ptr()) == 0 {
126125
return Err(PyDowncastError.into());
127126
}
128-
&*(ob as *const PyObjectRef as *const PyArray<T, D>)
127+
&*(ob as *const PyAny as *const PyArray<T, D>)
129128
};
130129
array
131130
.type_check()

src/slice_box.rs

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use crate::types::TypeNum;
2-
use pyo3::{ffi, typeob, types::PyObjectRef, PyObjectAlloc, Python, ToPyPointer};
1+
use pyo3::class::methods::{PyMethodDefType, PyMethodsProtocol};
2+
use pyo3::{ffi, type_object, types::PyAny, AsPyPointer, PyObjectAlloc, Python};
33
use std::os::raw::c_void;
44

55
/// It's a memory store for IntoPyArray.
@@ -12,8 +12,7 @@ pub(crate) struct SliceBox<T> {
1212

1313
impl<T> SliceBox<T> {
1414
pub(crate) unsafe fn new<'a>(box_: Box<[T]>) -> &'a Self {
15-
<Self as typeob::PyTypeObject>::init_type();
16-
let type_ob = <Self as typeob::PyTypeInfo>::type_object() as *mut _;
15+
let type_ob = <Self as type_object::PyTypeObject>::init_type().as_ptr();
1716
let base = ffi::_PyObject_New(type_ob);
1817
*base = ffi::PyObject_HEAD_INIT;
1918
(*base).ob_type = type_ob;
@@ -26,9 +25,9 @@ impl<T> SliceBox<T> {
2625
}
2726
}
2827

29-
impl<T> typeob::PyTypeInfo for SliceBox<T> {
28+
impl<T> type_object::PyTypeInfo for SliceBox<T> {
3029
type Type = ();
31-
type BaseType = PyObjectRef;
30+
type BaseType = PyAny;
3231
const NAME: &'static str = "SliceBox";
3332
const DESCRIPTION: &'static str = "Memory store for PyArray using rust's Box<[T]>.";
3433
const FLAGS: usize = 0;
@@ -41,38 +40,26 @@ impl<T> typeob::PyTypeInfo for SliceBox<T> {
4140
}
4241
}
4342

44-
impl<T: TypeNum> typeob::PyTypeCreate for SliceBox<T> {
45-
#[inline(always)]
46-
fn init_type() {
47-
static START: std::sync::Once = std::sync::ONCE_INIT;
48-
START.call_once(|| {
49-
let ty = unsafe { <Self as typeob::PyTypeInfo>::type_object() };
50-
if (ty.tp_flags & ffi::Py_TPFLAGS_READY) == 0 {
51-
let gil = Python::acquire_gil();
52-
let py = gil.python();
53-
let mod_name = format!("rust_numpy.{:?}", T::npy_data_type());
54-
typeob::initialize_type::<Self>(py, Some(&mod_name))
55-
.map_err(|e| e.print(py))
56-
.expect("Failed to initialize SliceBox");
57-
}
58-
});
43+
impl<T> PyMethodsProtocol for SliceBox<T> {
44+
fn py_methods() -> Vec<&'static PyMethodDefType> {
45+
Vec::new()
5946
}
6047
}
6148

62-
impl<T> ToPyPointer for SliceBox<T> {
49+
impl<T> AsPyPointer for SliceBox<T> {
6350
#[inline]
6451
fn as_ptr(&self) -> *mut ffi::PyObject {
6552
&self.ob_base as *const _ as *mut _
6653
}
6754
}
6855

69-
impl<T> PyObjectAlloc<SliceBox<T>> for SliceBox<T> {
56+
impl<T> PyObjectAlloc for SliceBox<T> {
7057
/// Calls the rust destructor for the object.
7158
unsafe fn drop(py: Python, obj: *mut ffi::PyObject) {
7259
let data = (*(obj as *mut SliceBox<T>)).inner;
7360
let boxed_slice = Box::from_raw(data);
7461
drop(boxed_slice);
75-
<Self as typeob::PyTypeInfo>::BaseType::drop(py, obj);
62+
<Self as type_object::PyTypeInfo>::BaseType::drop(py, obj);
7663
}
7764
unsafe fn dealloc(py: Python, obj: *mut ffi::PyObject) {
7865
Self::drop(py, obj);

tests/array.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ extern crate pyo3;
44

55
use ndarray::*;
66
use numpy::*;
7-
use pyo3::{prelude::*, types::PyDict, types::PyList, ToPyPointer};
7+
use pyo3::{prelude::*, types::PyDict, types::PyList, AsPyPointer};
88

99
#[test]
1010
fn new_c_order() {

0 commit comments

Comments
 (0)