@@ -43,8 +43,8 @@ impl Blob {
43
43
pub fn allocate ( description : & TensorDesc ) -> Result < Self > {
44
44
let mut instance = std:: ptr:: null_mut ( ) ;
45
45
try_unsafe ! ( ie_blob_make_memory(
46
- & description. instance as * const _ ,
47
- & mut instance as * mut * mut _
46
+ std :: ptr :: addr_of! ( description. instance) ,
47
+ std :: ptr :: addr_of_mut! ( instance)
48
48
) ) ?;
49
49
Ok ( Self { instance } )
50
50
}
@@ -54,16 +54,19 @@ impl Blob {
54
54
let blob = self . instance as * const ie_blob_t ;
55
55
56
56
let mut layout = Layout :: ANY ;
57
- try_unsafe ! ( ie_blob_get_layout( blob, & mut layout as * mut _ ) ) ?;
57
+ try_unsafe ! ( ie_blob_get_layout( blob, std :: ptr :: addr_of_mut! ( layout) ) ) ?;
58
58
59
59
let mut dimensions = dimensions_t {
60
60
ranks : 0 ,
61
61
dims : [ 0 ; 8usize ] ,
62
62
} ;
63
- try_unsafe ! ( ie_blob_get_dims( blob, & mut dimensions as * mut _ ) ) ?;
63
+ try_unsafe ! ( ie_blob_get_dims( blob, std :: ptr :: addr_of_mut! ( dimensions) ) ) ?;
64
64
65
65
let mut precision = Precision :: UNSPECIFIED ;
66
- try_unsafe ! ( ie_blob_get_precision( blob, & mut precision as * mut _) ) ?;
66
+ try_unsafe ! ( ie_blob_get_precision(
67
+ blob,
68
+ std:: ptr:: addr_of_mut!( precision)
69
+ ) ) ?;
67
70
68
71
Ok ( TensorDesc :: new ( layout, & dimensions. dims , precision) )
69
72
}
@@ -75,7 +78,7 @@ impl Blob {
75
78
/// Panics if the returned OpenVINO size will not fit in `usize`.
76
79
pub fn len ( & mut self ) -> Result < usize > {
77
80
let mut size = 0 ;
78
- try_unsafe ! ( ie_blob_size( self . instance, & mut size as * mut _ ) ) ?;
81
+ try_unsafe ! ( ie_blob_size( self . instance, std :: ptr :: addr_of_mut! ( size) ) ) ?;
79
82
Ok ( usize:: try_from ( size) . unwrap ( ) )
80
83
}
81
84
@@ -86,14 +89,20 @@ impl Blob {
86
89
/// Panics if the returned OpenVINO size will not fit in `usize`.
87
90
pub fn byte_len ( & mut self ) -> Result < usize > {
88
91
let mut size = 0 ;
89
- try_unsafe ! ( ie_blob_byte_size( self . instance, & mut size as * mut _) ) ?;
92
+ try_unsafe ! ( ie_blob_byte_size(
93
+ self . instance,
94
+ std:: ptr:: addr_of_mut!( size)
95
+ ) ) ?;
90
96
Ok ( usize:: try_from ( size) . unwrap ( ) )
91
97
}
92
98
93
99
/// Retrieve the [`Blob`]'s data as an immutable slice of bytes.
94
100
pub fn buffer ( & mut self ) -> Result < & [ u8 ] > {
95
101
let mut buffer = Blob :: empty_buffer ( ) ;
96
- try_unsafe ! ( ie_blob_get_buffer( self . instance, & mut buffer as * mut _) ) ?;
102
+ try_unsafe ! ( ie_blob_get_buffer(
103
+ self . instance,
104
+ std:: ptr:: addr_of_mut!( buffer)
105
+ ) ) ?;
97
106
let size = self . byte_len ( ) ?;
98
107
let slice = unsafe {
99
108
std:: slice:: from_raw_parts ( buffer. __bindgen_anon_1 . buffer as * const u8 , size)
@@ -104,7 +113,10 @@ impl Blob {
104
113
/// Retrieve the [`Blob`]'s data as a mutable slice of bytes.
105
114
pub fn buffer_mut ( & mut self ) -> Result < & mut [ u8 ] > {
106
115
let mut buffer = Blob :: empty_buffer ( ) ;
107
- try_unsafe ! ( ie_blob_get_buffer( self . instance, & mut buffer as * mut _) ) ?;
116
+ try_unsafe ! ( ie_blob_get_buffer(
117
+ self . instance,
118
+ std:: ptr:: addr_of_mut!( buffer)
119
+ ) ) ?;
108
120
let size = self . byte_len ( ) ?;
109
121
let slice = unsafe {
110
122
std:: slice:: from_raw_parts_mut ( buffer. __bindgen_anon_1 . buffer . cast :: < u8 > ( ) , size)
@@ -122,7 +134,10 @@ impl Blob {
122
134
/// `results.buffer_mut_as_type::<f32>()`.
123
135
pub unsafe fn buffer_mut_as_type < T > ( & mut self ) -> Result < & mut [ T ] > {
124
136
let mut buffer = Blob :: empty_buffer ( ) ;
125
- InferenceError :: from ( ie_blob_get_buffer ( self . instance , & mut buffer as * mut _ ) ) ?;
137
+ InferenceError :: from ( ie_blob_get_buffer (
138
+ self . instance ,
139
+ std:: ptr:: addr_of_mut!( buffer) ,
140
+ ) ) ?;
126
141
// This is very unsafe, but very convenient: by allowing users to specify T, they can
127
142
// retrieve the buffer in whatever shape they prefer. But we must ensure that they cannot
128
143
// read too many bytes, so we manually calculate the resulting slice `size`.
0 commit comments