@@ -20,7 +20,7 @@ use pyo3::{
2020 ffi, pyobject_native_type_base,
2121 types:: { DerefToPyAny , PyAnyMethods , PyModule } ,
2222 AsPyPointer , Bound , DowncastError , FromPyObject , IntoPy , Py , PyAny , PyErr , PyNativeType ,
23- PyObject , PyResult , PyTypeInfo , Python , ToPyObject ,
23+ PyObject , PyResult , PyTypeInfo , Python ,
2424} ;
2525
2626use crate :: borrow:: { PyReadonlyArray , PyReadwriteArray } ;
@@ -430,6 +430,24 @@ impl<T: Element, D: Dimension> PyArray<T, D> {
430430 Self :: new_with_data ( py, dims, strides, data_ptr, container. cast ( ) )
431431 }
432432
433+ /// Deprecated form of [`PyArray<T, D>::borrow_from_array_bound`]
434+ ///
435+ /// # Safety
436+ /// Same as [`PyArray<T, D>::borrow_from_array_bound`]
437+ #[ deprecated(
438+ since = "0.21.0" ,
439+ note = "will be replaced by `PyArray::borrow_from_array_bound` in the future"
440+ ) ]
441+ pub unsafe fn borrow_from_array < ' py , S > (
442+ array : & ArrayBase < S , D > ,
443+ container : & ' py PyAny ,
444+ ) -> & ' py Self
445+ where
446+ S : Data < Elem = T > ,
447+ {
448+ Self :: borrow_from_array_bound ( array, ( * container. as_borrowed ( ) ) . clone ( ) ) . into_gil_ref ( )
449+ }
450+
433451 /// Creates a NumPy array backed by `array` and ties its ownership to the Python object `container`.
434452 ///
435453 /// # Safety
@@ -451,19 +469,19 @@ impl<T: Element, D: Dimension> PyArray<T, D> {
451469 /// #[pymethods]
452470 /// impl Owner {
453471 /// #[getter]
454- /// fn array<'py>(this: & 'py PyCell< Self>) -> & 'py PyArray1<f64> {
472+ /// fn array<'py>(this: Bound< 'py, Self>) -> Bound< 'py, PyArray1<f64> > {
455473 /// let array = &this.borrow().array;
456474 ///
457475 /// // SAFETY: The memory backing `array` will stay valid as long as this object is alive
458476 /// // as we do not modify `array` in any way which would cause it to be reallocated.
459- /// unsafe { PyArray1::borrow_from_array (array, this) }
477+ /// unsafe { PyArray1::borrow_from_array_bound (array, this.into_any() ) }
460478 /// }
461479 /// }
462480 /// ```
463- pub unsafe fn borrow_from_array < ' py , S > (
481+ pub unsafe fn borrow_from_array_bound < ' py , S > (
464482 array : & ArrayBase < S , D > ,
465- container : & ' py PyAny ,
466- ) -> & ' py Self
483+ container : Bound < ' py , PyAny > ,
484+ ) -> Bound < ' py , Self >
467485 where
468486 S : Data < Elem = T > ,
469487 {
@@ -472,16 +490,13 @@ impl<T: Element, D: Dimension> PyArray<T, D> {
472490
473491 let py = container. py ( ) ;
474492
475- mem:: forget ( container. to_object ( py) ) ;
476-
477493 Self :: new_with_data (
478494 py,
479495 dims,
480496 strides. as_ptr ( ) ,
481497 data_ptr,
482- container as * const PyAny as * mut PyAny ,
498+ container. into_ptr ( ) . cast ( ) ,
483499 )
484- . into_gil_ref ( )
485500 }
486501
487502 /// Construct a new NumPy array filled with zeros.
0 commit comments