@@ -17,7 +17,7 @@ use std::{iter::ExactSizeIterator, marker::PhantomData};
1717use crate :: convert:: { ArrayExt , IntoPyArray , NpyIndex , ToNpyDims , ToPyArray } ;
1818use crate :: dtype:: { DataType , Element } ;
1919use crate :: error:: { FromVecError , NotContiguousError , ShapeError } ;
20- use crate :: slice_box :: SliceBox ;
20+ use crate :: owner :: Owner ;
2121
2222/// A safe, static-typed interface for
2323/// [NumPy ndarray](https://numpy.org/doc/stable/reference/arrays.ndarray.html).
@@ -442,34 +442,39 @@ impl<T: Element, D: Dimension> PyArray<T, D> {
442442 Self :: from_owned_ptr ( py, ptr)
443443 }
444444
445- pub ( crate ) unsafe fn from_boxed_slice < ' py , ID > (
445+ pub ( crate ) unsafe fn from_raw_parts < ' py , ID , O > (
446446 py : Python < ' py > ,
447447 dims : ID ,
448448 strides : * const npy_intp ,
449- boxed_slice : Box < [ T ] > ,
450- data_ptr : Option < * const T > ,
449+ data_ptr : * const T ,
450+ owner : O ,
451451 ) -> & ' py Self
452452 where
453453 ID : IntoDimension < Dim = D > ,
454+ Owner : From < O > ,
454455 {
455- let dims = dims. into_dimension ( ) ;
456- let data_ptr = data_ptr. unwrap_or_else ( || boxed_slice. as_ptr ( ) ) ;
457- let container = SliceBox :: new ( boxed_slice) ;
458- let cell = pyo3:: PyClassInitializer :: from ( container)
456+ let owner = pyo3:: PyClassInitializer :: from ( Owner :: from ( owner) )
459457 . create_cell ( py)
460458 . expect ( "Object creation failed." ) ;
459+
460+ let dims = dims. into_dimension ( ) ;
461461 let ptr = PY_ARRAY_API . PyArray_New (
462462 PY_ARRAY_API . get_type_object ( npyffi:: NpyTypes :: PyArray_Type ) ,
463463 dims. ndim_cint ( ) ,
464464 dims. as_dims_ptr ( ) ,
465- T :: npy_type ( ) as i32 ,
466- strides as * mut _ , // strides
467- data_ptr as _ , // data
468- mem:: size_of :: < T > ( ) as i32 , // itemsize
469- npyffi:: NPY_ARRAY_WRITEABLE , // flag
470- ptr:: null_mut ( ) , // obj
465+ T :: npy_type ( ) as c_int ,
466+ strides as * mut npy_intp , // strides
467+ data_ptr as * mut c_void , // data
468+ mem:: size_of :: < T > ( ) as c_int , // itemsize
469+ npyffi:: NPY_ARRAY_WRITEABLE , // flag
470+ ptr:: null_mut ( ) , // obj
471471 ) ;
472- PY_ARRAY_API . PyArray_SetBaseObject ( ptr as * mut npyffi:: PyArrayObject , cell as _ ) ;
472+
473+ PY_ARRAY_API . PyArray_SetBaseObject (
474+ ptr as * mut npyffi:: PyArrayObject ,
475+ owner as * mut ffi:: PyObject ,
476+ ) ;
477+
473478 Self :: from_owned_ptr ( py, ptr)
474479 }
475480
0 commit comments