Skip to content

Commit 407ffc5

Browse files
committed
cleanup
1 parent 277cf79 commit 407ffc5

File tree

1 file changed

+8
-17
lines changed

1 file changed

+8
-17
lines changed

rclrs/src/arguments.rs

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ pub fn extract_non_ros_args(
2727
) -> Result<Vec<String>, RclrsError> {
2828
// SAFETY: Getting a zero-initialized value is always safe.
2929
let mut rcl_arguments = unsafe { rcl_get_zero_initialized_arguments() };
30-
// SAFETY: No preconditions for this function
31-
let allocator = unsafe { rcutils_get_default_allocator() };
3230

3331
let (args, cstring_args): (Vec<String>, Vec<Result<CString, RclrsError>>) = args
3432
.into_iter()
@@ -52,17 +50,12 @@ pub fn extract_non_ros_args(
5250
} else {
5351
c_args.as_ptr()
5452
};
55-
// SAFETY: No preconditions for this function
56-
let ret = unsafe {
57-
rcl_parse_arguments(c_args.len() as i32, argv, allocator, &mut rcl_arguments).ok()
58-
};
5953

60-
if let Err(err) = ret {
61-
// SAFETY: No preconditions for this function
62-
unsafe {
63-
rcl_arguments_fini(&mut rcl_arguments).ok()?;
64-
}
65-
return Err(err);
54+
unsafe {
55+
// SAFETY: Getting a default value is always safe.
56+
let allocator = rcutils_get_default_allocator();
57+
// SAFETY: No preconditions for this function.
58+
rcl_parse_arguments(c_args.len() as i32, argv, allocator, &mut rcl_arguments).ok()?;
6659
}
6760

6861
let ret = get_rcl_arguments(
@@ -72,7 +65,7 @@ pub fn extract_non_ros_args(
7265
&args,
7366
);
7467
unsafe {
75-
// SAFETY: No preconditions for this function
68+
// SAFETY: No preconditions for this function.
7669
rcl_arguments_fini(&mut rcl_arguments).ok()?;
7770
}
7871
ret
@@ -85,17 +78,15 @@ mod tests {
8578
#[test]
8679
fn test_non_ros_arguments() -> Result<(), String> {
8780
// ROS args are expected to be between '--ros-args' and '--'. Everything beside that is 'non-ROS'.
88-
let input_args: Vec<String> = vec![
81+
let input_args: [String; 6] = [
8982
"non-ros1",
9083
"--ros-args",
9184
"ros-args",
9285
"--",
9386
"non-ros2",
9487
"non-ros3",
9588
]
96-
.into_iter()
97-
.map(|x| x.to_string())
98-
.collect();
89+
.map(|x| x.to_string());
9990

10091
let non_ros_args: Vec<String> = extract_non_ros_args(input_args).unwrap();
10192
let expected = vec!["non-ros1", "non-ros2", "non-ros3"];

0 commit comments

Comments
 (0)