@@ -3,9 +3,9 @@ use crate::ffi_ptr_ext::FfiPtrExt;
3
3
use crate :: instance:: { Borrowed , Bound } ;
4
4
use crate :: py_result_ext:: PyResultExt ;
5
5
use crate :: types:: any:: PyAnyMethods ;
6
+ use crate :: { ffi, PyAny , Python } ;
6
7
#[ cfg( feature = "gil-refs" ) ]
7
- use crate :: AsPyPointer ;
8
- use crate :: { ffi, PyAny , PyNativeType , Python } ;
8
+ use crate :: { AsPyPointer , PyNativeType } ;
9
9
use std:: os:: raw:: c_char;
10
10
use std:: slice;
11
11
@@ -16,16 +16,6 @@ pub struct PyByteArray(PyAny);
16
16
pyobject_native_type_core ! ( PyByteArray , pyobject_native_static_type_object!( ffi:: PyByteArray_Type ) , #checkfunction=ffi:: PyByteArray_Check ) ;
17
17
18
18
impl PyByteArray {
19
- /// Deprecated form of [`PyByteArray::new_bound`]
20
- #[ cfg( feature = "gil-refs" ) ]
21
- #[ deprecated(
22
- since = "0.21.0" ,
23
- note = "`PyByteArray::new` will be replaced by `PyByteArray::new_bound` in a future PyO3 version"
24
- ) ]
25
- pub fn new < ' py > ( py : Python < ' py > , src : & [ u8 ] ) -> & ' py PyByteArray {
26
- Self :: new_bound ( py, src) . into_gil_ref ( )
27
- }
28
-
29
19
/// Creates a new Python bytearray object.
30
20
///
31
21
/// The byte string is initialized by copying the data from the `&[u8]`.
@@ -39,19 +29,6 @@ impl PyByteArray {
39
29
}
40
30
}
41
31
42
- /// Deprecated form of [`PyByteArray::new_bound_with`]
43
- #[ cfg( feature = "gil-refs" ) ]
44
- #[ deprecated(
45
- since = "0.21.0" ,
46
- note = "`PyByteArray::new_with` will be replaced by `PyByteArray::new_bound_with` in a future PyO3 version"
47
- ) ]
48
- pub fn new_with < F > ( py : Python < ' _ > , len : usize , init : F ) -> PyResult < & PyByteArray >
49
- where
50
- F : FnOnce ( & mut [ u8 ] ) -> PyResult < ( ) > ,
51
- {
52
- Self :: new_bound_with ( py, len, init) . map ( Bound :: into_gil_ref)
53
- }
54
-
55
32
/// Creates a new Python `bytearray` object with an `init` closure to write its contents.
56
33
/// Before calling `init` the bytearray is zero-initialised.
57
34
/// * If Python raises a MemoryError on the allocation, `new_with` will return
@@ -101,16 +78,6 @@ impl PyByteArray {
101
78
}
102
79
}
103
80
104
- /// Deprecated form of [`PyByteArray::from_bound`]
105
- #[ cfg( feature = "gil-refs" ) ]
106
- #[ deprecated(
107
- since = "0.21.0" ,
108
- note = "`PyByteArray::from` will be replaced by `PyByteArray::from_bound` in a future PyO3 version"
109
- ) ]
110
- pub fn from ( src : & PyAny ) -> PyResult < & PyByteArray > {
111
- PyByteArray :: from_bound ( & src. as_borrowed ( ) ) . map ( Bound :: into_gil_ref)
112
- }
113
-
114
81
/// Creates a new Python `bytearray` object from another Python object that
115
82
/// implements the buffer protocol.
116
83
pub fn from_bound < ' py > ( src : & Bound < ' py , PyAny > ) -> PyResult < Bound < ' py , PyByteArray > > {
@@ -120,6 +87,39 @@ impl PyByteArray {
120
87
. downcast_into_unchecked ( )
121
88
}
122
89
}
90
+ }
91
+
92
+ #[ cfg( feature = "gil-refs" ) ]
93
+ impl PyByteArray {
94
+ /// Deprecated form of [`PyByteArray::new_bound`]
95
+ #[ deprecated(
96
+ since = "0.21.0" ,
97
+ note = "`PyByteArray::new` will be replaced by `PyByteArray::new_bound` in a future PyO3 version"
98
+ ) ]
99
+ pub fn new < ' py > ( py : Python < ' py > , src : & [ u8 ] ) -> & ' py PyByteArray {
100
+ Self :: new_bound ( py, src) . into_gil_ref ( )
101
+ }
102
+
103
+ /// Deprecated form of [`PyByteArray::new_bound_with`]
104
+ #[ deprecated(
105
+ since = "0.21.0" ,
106
+ note = "`PyByteArray::new_with` will be replaced by `PyByteArray::new_bound_with` in a future PyO3 version"
107
+ ) ]
108
+ pub fn new_with < F > ( py : Python < ' _ > , len : usize , init : F ) -> PyResult < & PyByteArray >
109
+ where
110
+ F : FnOnce ( & mut [ u8 ] ) -> PyResult < ( ) > ,
111
+ {
112
+ Self :: new_bound_with ( py, len, init) . map ( Bound :: into_gil_ref)
113
+ }
114
+
115
+ /// Deprecated form of [`PyByteArray::from_bound`]
116
+ #[ deprecated(
117
+ since = "0.21.0" ,
118
+ note = "`PyByteArray::from` will be replaced by `PyByteArray::from_bound` in a future PyO3 version"
119
+ ) ]
120
+ pub fn from ( src : & PyAny ) -> PyResult < & PyByteArray > {
121
+ PyByteArray :: from_bound ( & src. as_borrowed ( ) ) . map ( Bound :: into_gil_ref)
122
+ }
123
123
124
124
/// Gets the length of the bytearray.
125
125
#[ inline]
@@ -300,7 +300,7 @@ pub trait PyByteArrayMethods<'py>: crate::sealed::Sealed {
300
300
///
301
301
/// # Safety
302
302
///
303
- /// See the safety requirements of [`PyByteArray ::as_bytes`] and [`PyByteArray ::as_bytes_mut`].
303
+ /// See the safety requirements of [`PyByteArrayMethods ::as_bytes`] and [`PyByteArrayMethods ::as_bytes_mut`].
304
304
fn data ( & self ) -> * mut u8 ;
305
305
306
306
/// Extracts a slice of the `ByteArray`'s entire buffer.
@@ -311,7 +311,7 @@ pub trait PyByteArrayMethods<'py>: crate::sealed::Sealed {
311
311
/// undefined.
312
312
///
313
313
/// These mutations may occur in Python code as well as from Rust:
314
- /// - Calling methods like [`PyByteArray ::as_bytes_mut`] and [`PyByteArray ::resize`] will
314
+ /// - Calling methods like [`PyByteArrayMethods ::as_bytes_mut`] and [`PyByteArrayMethods ::resize`] will
315
315
/// invalidate the slice.
316
316
/// - Actions like dropping objects or raising exceptions can invoke `__del__`methods or signal
317
317
/// handlers, which may execute arbitrary Python code. This means that if Python code has a
@@ -405,7 +405,7 @@ pub trait PyByteArrayMethods<'py>: crate::sealed::Sealed {
405
405
/// # Safety
406
406
///
407
407
/// Any other accesses of the `bytearray`'s buffer invalidate the slice. If it is used
408
- /// afterwards, the behavior is undefined. The safety requirements of [`PyByteArray ::as_bytes`]
408
+ /// afterwards, the behavior is undefined. The safety requirements of [`PyByteArrayMethods ::as_bytes`]
409
409
/// apply to this function as well.
410
410
#[ allow( clippy:: mut_from_ref) ]
411
411
unsafe fn as_bytes_mut ( & self ) -> & mut [ u8 ] ;
@@ -432,8 +432,8 @@ pub trait PyByteArrayMethods<'py>: crate::sealed::Sealed {
432
432
433
433
/// Resizes the bytearray object to the new length `len`.
434
434
///
435
- /// Note that this will invalidate any pointers obtained by [PyByteArray ::data], as well as
436
- /// any (unsafe) slices obtained from [PyByteArray ::as_bytes] and [PyByteArray ::as_bytes_mut].
435
+ /// Note that this will invalidate any pointers obtained by [PyByteArrayMethods ::data], as well as
436
+ /// any (unsafe) slices obtained from [PyByteArrayMethods ::as_bytes] and [PyByteArrayMethods ::as_bytes_mut].
437
437
fn resize ( & self , len : usize ) -> PyResult < ( ) > ;
438
438
}
439
439
0 commit comments