Skip to content

Commit e503f41

Browse files
committed
Mark C FFI handle getters from Structs as unsafe
1 parent 7e68634 commit e503f41

File tree

5 files changed

+14
-16
lines changed

5 files changed

+14
-16
lines changed

src/core/array.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ where
367367
}
368368

369369
/// Returns the native FFI handle for Rust object `Array`
370-
pub fn get(&self) -> af_array {
370+
pub unsafe fn get(&self) -> af_array {
371371
self.handle
372372
}
373373

@@ -529,13 +529,11 @@ where
529529
/// Get the device pointer and lock the buffer in memory manager
530530
///
531531
/// The device pointer is not freed by memory manager until unlock is called.
532-
pub fn device_ptr(&self) -> void_ptr {
533-
unsafe {
534-
let mut temp: void_ptr = std::ptr::null_mut();
535-
let err_val = af_get_device_ptr(&mut temp as *mut void_ptr, self.handle);
536-
HANDLE_ERROR(AfError::from(err_val));
537-
temp
538-
}
532+
pub unsafe fn device_ptr(&self) -> void_ptr {
533+
let mut temp: void_ptr = std::ptr::null_mut();
534+
let err_val = af_get_device_ptr(&mut temp as *mut void_ptr, self.handle);
535+
HANDLE_ERROR(AfError::from(err_val));
536+
temp
539537
}
540538

541539
/// Get the size of physical allocated bytes.

src/core/data.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -458,11 +458,11 @@ pub fn join_many<T>(dim: i32, inputs: Vec<&Array<T>>) -> Array<T>
458458
where
459459
T: HasAfEnum,
460460
{
461-
let mut v = Vec::new();
462-
for i in inputs {
463-
v.push(i.get());
464-
}
465461
unsafe {
462+
let mut v = Vec::new();
463+
for i in inputs {
464+
v.push(i.get());
465+
}
466466
let mut temp: af_array = std::ptr::null_mut();
467467
let err_val = af_join_many(
468468
&mut temp as *mut af_array,

src/core/index.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ impl<'object> Indexer<'object> {
219219
}
220220

221221
/// Get native(ArrayFire) resource handle
222-
pub fn get(&self) -> af_index_t {
222+
pub unsafe fn get(&self) -> af_index_t {
223223
self.handle
224224
}
225225
}

src/core/random.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ impl RandomEngine {
183183
}
184184

185185
/// Returns the native FFI handle for Rust object `RandomEngine`
186-
pub fn get(&self) -> af_random_engine {
186+
pub unsafe fn get(&self) -> af_random_engine {
187187
self.handle
188188
}
189189
}
@@ -219,7 +219,7 @@ pub fn get_default_random_engine() -> RandomEngine {
219219
let mut handle: af_random_engine = std::ptr::null_mut();
220220
err_val = af_retain_random_engine(&mut handle as *mut af_random_engine, temp);
221221
HANDLE_ERROR(AfError::from(err_val));
222-
RandomEngine { handle: handle } // ::from(handle)
222+
RandomEngine { handle: handle }
223223
}
224224
}
225225

src/vision/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ impl Features {
174174
feat_func_def!("Get features size Array", size, af_get_features_size);
175175

176176
/// Get the internal handle for [Features](./struct.Features.html) object
177-
pub fn get(&self) -> af_features {
177+
pub unsafe fn get(&self) -> af_features {
178178
self.feat
179179
}
180180
}

0 commit comments

Comments
 (0)