Skip to content

Commit f58438e

Browse files
committed
initialize pointer in SliceBox constructor, replaced PyTypeObject impl with default impl, added PyMethodsProtocol impl for SliceBox
1 parent 70ae250 commit f58438e

File tree

2 files changed

+5
-25
lines changed

2 files changed

+5
-25
lines changed

src/array.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ use types::{NpyDataType, TypeNum};
3737
/// So you can neither retrieve it nor deallocate it manually.
3838
///
3939
/// # Reference
40-
///Object
4140
/// Like [`new`](#method.new), all constractor methods of `PyArray` returns `&PyArray`.
4241
///
4342
/// This design follows

src/slice_box.rs

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
use crate::types::TypeNum;
2-
use pyo3::class::methods::PyMethodsProtocol;
1+
use pyo3::class::methods::{PyMethodDefType, PyMethodsProtocol};
32
use pyo3::{ffi, type_object, types::PyAny, AsPyPointer, PyObjectAlloc, Python};
43
use std::os::raw::c_void;
5-
use std::ptr::NonNull;
64

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

1513
impl<T> SliceBox<T> {
1614
pub(crate) unsafe fn new<'a>(box_: Box<[T]>) -> &'a Self {
17-
// <Self as type_object::PyTypeObject>::init_type();
18-
let type_ob = <Self as type_object::PyTypeInfo>::type_object() as *mut _;
15+
let type_ob = <Self as type_object::PyTypeObject>::init_type().as_ptr();
1916
let base = ffi::_PyObject_New(type_ob);
2017
*base = ffi::PyObject_HEAD_INIT;
2118
(*base).ob_type = type_ob;
@@ -43,25 +40,9 @@ impl<T> type_object::PyTypeInfo for SliceBox<T> {
4340
}
4441
}
4542

46-
impl<T: TypeNum> type_object::PyTypeObject for SliceBox<T>
47-
where
48-
SliceBox<T>: PyMethodsProtocol,
49-
{
50-
#[inline(always)]
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-
// })
43+
impl<T> PyMethodsProtocol for SliceBox<T> {
44+
fn py_methods() -> Vec<&'static PyMethodDefType> {
45+
Vec::new()
6546
}
6647
}
6748

0 commit comments

Comments
 (0)