Skip to content

Commit c4f7fad

Browse files
committed
[RSDK-11058] provide a means to free vector/quaterion/ov components
1 parent 2af84ae commit c4f7fad

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

src/ffi/spatialmath/orientation_vector.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,19 @@ pub unsafe extern "C" fn orientation_vector_from_quaternion(
9393
let o_vec: OrientationVector = (*quat_ptr).into();
9494
to_raw_pointer(&o_vec)
9595
}
96+
97+
/// Free memory of an array of orientation vector components at the given address.
98+
///
99+
/// # Safety
100+
///
101+
/// Outer processes that request the components of a orientation vector should call this function
102+
/// to free the memory allocated to the array once finished
103+
#[no_mangle]
104+
pub unsafe extern "C" fn free_orientation_vector_components(ptr: *mut c_double) {
105+
if ptr.is_null() {
106+
return;
107+
}
108+
let slice = std::slice::from_raw_parts_mut(ptr, 4);
109+
let arr: [c_double; 4] = slice.try_into().unwrap();
110+
let _ = arr; // technically not necessary but helps to be explicit
111+
}

src/ffi/spatialmath/quaternion.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,3 +448,19 @@ pub unsafe extern "C" fn quaternion_hamiltonian_product(
448448
null_pointer_check!(quat_ptr_2);
449449
to_raw_pointer(&((*quat_ptr_1) * (*quat_ptr_2)))
450450
}
451+
452+
/// Free memory of an array of quaternion components at the given address.
453+
///
454+
/// # Safety
455+
///
456+
/// Outer processes that request the components of a quaternion should call this function
457+
/// to free the memory allocated to the array once finished
458+
#[no_mangle]
459+
pub unsafe extern "C" fn free_quaternion_components(ptr: *mut c_double) {
460+
if ptr.is_null() {
461+
return;
462+
}
463+
let slice = std::slice::from_raw_parts_mut(ptr, 4);
464+
let arr: [c_double; 4] = slice.try_into().unwrap();
465+
let _ = arr; // technically not necessary but helps to be explicit
466+
}

src/ffi/spatialmath/vector3.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,3 +219,19 @@ pub unsafe extern "C" fn vector_cross_product(
219219
let vec = (*vec_ptr_1).cross(&*vec_ptr_2);
220220
to_raw_pointer(vec)
221221
}
222+
223+
/// Free memory of an array of vector components at the given address.
224+
///
225+
/// # Safety
226+
///
227+
/// Outer processes that request the components of a vector should call this function
228+
/// to free the memory allocated to the array once finished
229+
#[no_mangle]
230+
pub unsafe extern "C" fn free_vector_components(ptr: *mut c_double) {
231+
if ptr.is_null() {
232+
return;
233+
}
234+
let slice = std::slice::from_raw_parts_mut(ptr, 3);
235+
let arr: [c_double; 3] = slice.try_into().unwrap();
236+
let _ = arr; // technically not necessary but helps to be explicit
237+
}

0 commit comments

Comments
 (0)