Skip to content

Commit b1ac318

Browse files
authored
[RSDK-11058] provide a means to free vector/quaterion/ov components (#151)
1 parent 2af84ae commit b1ac318

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-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+
109+
let ptr = ptr as *mut [c_double; 4];
110+
let _: Box<[c_double; 4]> = Box::from_raw(ptr);
111+
}

src/ffi/spatialmath/quaternion.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,3 +448,18 @@ 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 ptr = ptr as *mut [c_double; 4];
464+
let _: Box<[c_double; 4]> = Box::from_raw(ptr);
465+
}

src/ffi/spatialmath/vector3.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,3 +219,18 @@ 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 ptr = ptr as *mut [c_double; 3];
235+
let _: Box<[c_double; 3]> = Box::from_raw(ptr);
236+
}

0 commit comments

Comments
 (0)