Skip to content

Commit 70ae250

Browse files
committed
bump to 0.6.0 (broken)
1 parent 99676d3 commit 70ae250

File tree

4 files changed

+37
-31
lines changed

4 files changed

+37
-31
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

src/array.rs

Lines changed: 7 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,7 @@ use types::{NpyDataType, TypeNum};
3737
/// So you can neither retrieve it nor deallocate it manually.
3838
///
3939
/// # Reference
40-
///
40+
///Object
4141
/// Like [`new`](#method.new), all constractor methods of `PyArray` returns `&PyArray`.
4242
///
4343
/// This design follows
@@ -109,9 +109,9 @@ pyobject_native_type_convert!(
109109

110110
pyobject_native_type_named!(PyArray<T, D>, T, D);
111111

112-
impl<'a, T, D> ::std::convert::From<&'a PyArray<T, D>> for &'a PyObjectRef {
112+
impl<'a, T, D> ::std::convert::From<&'a PyArray<T, D>> for &'a PyAny {
113113
fn from(ob: &'a PyArray<T, D>) -> Self {
114-
unsafe { &*(ob as *const PyArray<T, D> as *const PyObjectRef) }
114+
unsafe { &*(ob as *const PyArray<T, D> as *const PyAny) }
115115
}
116116
}
117117

@@ -120,12 +120,12 @@ impl<'a, T: TypeNum, D: Dimension> FromPyObject<'a> for &'a PyArray<T, D> {
120120
// 1. Checks if the object is PyArray
121121
// 2. Checks if the data type of the array is T
122122
// 3. Checks if the dimension is same as D
123-
fn extract(ob: &'a PyObjectRef) -> PyResult<Self> {
123+
fn extract(ob: &'a PyAny) -> PyResult<Self> {
124124
let array = unsafe {
125125
if npyffi::PyArray_Check(ob.as_ptr()) == 0 {
126126
return Err(PyDowncastError.into());
127127
}
128-
&*(ob as *const PyObjectRef as *const PyArray<T, D>)
128+
&*(ob as *const PyAny as *const PyArray<T, D>)
129129
};
130130
array
131131
.type_check()

src/slice_box.rs

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use crate::types::TypeNum;
2-
use pyo3::{ffi, typeob, types::PyObjectRef, PyObjectAlloc, Python, ToPyPointer};
2+
use pyo3::class::methods::PyMethodsProtocol;
3+
use pyo3::{ffi, type_object, types::PyAny, AsPyPointer, PyObjectAlloc, Python};
34
use std::os::raw::c_void;
5+
use std::ptr::NonNull;
46

57
/// It's a memory store for IntoPyArray.
68
/// See IntoPyArray's doc for what concretely this type is for.
@@ -12,8 +14,8 @@ pub(crate) struct SliceBox<T> {
1214

1315
impl<T> SliceBox<T> {
1416
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 _;
17+
// <Self as type_object::PyTypeObject>::init_type();
18+
let type_ob = <Self as type_object::PyTypeInfo>::type_object() as *mut _;
1719
let base = ffi::_PyObject_New(type_ob);
1820
*base = ffi::PyObject_HEAD_INIT;
1921
(*base).ob_type = type_ob;
@@ -26,9 +28,9 @@ impl<T> SliceBox<T> {
2628
}
2729
}
2830

29-
impl<T> typeob::PyTypeInfo for SliceBox<T> {
31+
impl<T> type_object::PyTypeInfo for SliceBox<T> {
3032
type Type = ();
31-
type BaseType = PyObjectRef;
33+
type BaseType = PyAny;
3234
const NAME: &'static str = "SliceBox";
3335
const DESCRIPTION: &'static str = "Memory store for PyArray using rust's Box<[T]>.";
3436
const FLAGS: usize = 0;
@@ -41,38 +43,42 @@ impl<T> typeob::PyTypeInfo for SliceBox<T> {
4143
}
4244
}
4345

44-
impl<T: TypeNum> typeob::PyTypeCreate for SliceBox<T> {
46+
impl<T: TypeNum> type_object::PyTypeObject for SliceBox<T>
47+
where
48+
SliceBox<T>: PyMethodsProtocol,
49+
{
4550
#[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-
});
51+
fn init_type() -> NonNull<ffi::PyTypeObject> {
52+
// static START: std::sync::Once = std::sync::ONCE_INIT;
53+
// START.call_once(|| -> NonNull<ffi::PyTypeObject> {
54+
let ty = unsafe { <Self as type_object::PyTypeInfo>::type_object() };
55+
if (ty.tp_flags & ffi::Py_TPFLAGS_READY) == 0 {
56+
let gil = Python::acquire_gil();
57+
let py = gil.python();
58+
// let mod_name = format!("rust_numpy.{:?}", T::npy_data_type());
59+
type_object::initialize_type::<Self>(py)
60+
.map_err(|e| e.print(py))
61+
.expect("Failed to initialize SliceBox");
62+
}
63+
unsafe { NonNull::new_unchecked(ty) }
64+
// })
5965
}
6066
}
6167

62-
impl<T> ToPyPointer for SliceBox<T> {
68+
impl<T> AsPyPointer for SliceBox<T> {
6369
#[inline]
6470
fn as_ptr(&self) -> *mut ffi::PyObject {
6571
&self.ob_base as *const _ as *mut _
6672
}
6773
}
6874

69-
impl<T> PyObjectAlloc<SliceBox<T>> for SliceBox<T> {
75+
impl<T> PyObjectAlloc for SliceBox<T> {
7076
/// Calls the rust destructor for the object.
7177
unsafe fn drop(py: Python, obj: *mut ffi::PyObject) {
7278
let data = (*(obj as *mut SliceBox<T>)).inner;
7379
let boxed_slice = Box::from_raw(data);
7480
drop(boxed_slice);
75-
<Self as typeob::PyTypeInfo>::BaseType::drop(py, obj);
81+
<Self as type_object::PyTypeInfo>::BaseType::drop(py, obj);
7682
}
7783
unsafe fn dealloc(py: Python, obj: *mut ffi::PyObject) {
7884
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)