@@ -20,7 +20,7 @@ use pyo3::{
20
20
ffi, pyobject_native_type_base,
21
21
types:: { DerefToPyAny , PyAnyMethods , PyModule } ,
22
22
AsPyPointer , Bound , DowncastError , FromPyObject , IntoPy , Py , PyAny , PyErr , PyNativeType ,
23
- PyObject , PyResult , PyTypeInfo , Python , ToPyObject ,
23
+ PyObject , PyResult , PyTypeInfo , Python ,
24
24
} ;
25
25
26
26
use crate :: borrow:: { PyReadonlyArray , PyReadwriteArray } ;
@@ -430,6 +430,24 @@ impl<T: Element, D: Dimension> PyArray<T, D> {
430
430
Self :: new_with_data ( py, dims, strides, data_ptr, container. cast ( ) )
431
431
}
432
432
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
+
433
451
/// Creates a NumPy array backed by `array` and ties its ownership to the Python object `container`.
434
452
///
435
453
/// # Safety
@@ -451,19 +469,19 @@ impl<T: Element, D: Dimension> PyArray<T, D> {
451
469
/// #[pymethods]
452
470
/// impl Owner {
453
471
/// #[getter]
454
- /// fn array<'py>(this: & 'py PyCell< Self>) -> & 'py PyArray1<f64> {
472
+ /// fn array<'py>(this: Bound< 'py, Self>) -> Bound< 'py, PyArray1<f64> > {
455
473
/// let array = &this.borrow().array;
456
474
///
457
475
/// // SAFETY: The memory backing `array` will stay valid as long as this object is alive
458
476
/// // 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() ) }
460
478
/// }
461
479
/// }
462
480
/// ```
463
- pub unsafe fn borrow_from_array < ' py , S > (
481
+ pub unsafe fn borrow_from_array_bound < ' py , S > (
464
482
array : & ArrayBase < S , D > ,
465
- container : & ' py PyAny ,
466
- ) -> & ' py Self
483
+ container : Bound < ' py , PyAny > ,
484
+ ) -> Bound < ' py , Self >
467
485
where
468
486
S : Data < Elem = T > ,
469
487
{
@@ -472,16 +490,13 @@ impl<T: Element, D: Dimension> PyArray<T, D> {
472
490
473
491
let py = container. py ( ) ;
474
492
475
- mem:: forget ( container. to_object ( py) ) ;
476
-
477
493
Self :: new_with_data (
478
494
py,
479
495
dims,
480
496
strides. as_ptr ( ) ,
481
497
data_ptr,
482
- container as * const PyAny as * mut PyAny ,
498
+ container. into_ptr ( ) . cast ( ) ,
483
499
)
484
- . into_gil_ref ( )
485
500
}
486
501
487
502
/// Construct a new NumPy array filled with zeros.
0 commit comments