Skip to content

Commit

Permalink
capi: fix 'unused return value' warnings
Browse files Browse the repository at this point in the history
Somewhat recently, 'CString::from_raw' got a '#[must_use]' slapped
on it. Arguably, writing 'drop' around its return value is indeed much
clearer. So we do that here.

We also do that for 'Box::from_raw' even though it doesn't have a
'#[must_use]' on it. But the same principle applies.

PR #882
  • Loading branch information
rhysd committed Jul 14, 2022
1 parent fc9ee6a commit 5466076
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion regex-capi/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ ffi_fn! {

ffi_fn! {
fn rure_error_free(err: *mut Error) {
unsafe { Box::from_raw(err); }
unsafe { drop(Box::from_raw(err)); }
}
}

Expand Down
18 changes: 9 additions & 9 deletions regex-capi/src/rure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ ffi_fn! {

ffi_fn! {
fn rure_free(re: *const Regex) {
unsafe { Box::from_raw(re as *mut Regex); }
unsafe { drop(Box::from_raw(re as *mut Regex)); }
}
}

Expand Down Expand Up @@ -257,10 +257,10 @@ ffi_fn! {
fn rure_iter_capture_names_free(it: *mut IterCaptureNames) {
unsafe {
let it = &mut *it;
while let Some(ptr) = it.name_ptrs.pop(){
CString::from_raw(ptr);
while let Some(ptr) = it.name_ptrs.pop() {
drop(CString::from_raw(ptr));
}
Box::from_raw(it);
drop(Box::from_raw(it));
}
}
}
Expand Down Expand Up @@ -316,7 +316,7 @@ ffi_fn! {

ffi_fn! {
fn rure_iter_free(it: *mut Iter) {
unsafe { Box::from_raw(it); }
unsafe { drop(Box::from_raw(it)); }
}
}

Expand Down Expand Up @@ -407,7 +407,7 @@ ffi_fn! {

ffi_fn! {
fn rure_captures_free(captures: *const Captures) {
unsafe { Box::from_raw(captures as *mut Captures); }
unsafe { drop(Box::from_raw(captures as *mut Captures)); }
}
}

Expand Down Expand Up @@ -447,7 +447,7 @@ ffi_fn! {

ffi_fn! {
fn rure_options_free(options: *mut Options) {
unsafe { Box::from_raw(options); }
unsafe { drop(Box::from_raw(options)); }
}
}

Expand Down Expand Up @@ -527,7 +527,7 @@ ffi_fn! {

ffi_fn! {
fn rure_set_free(re: *const RegexSet) {
unsafe { Box::from_raw(re as *mut RegexSet); }
unsafe { drop(Box::from_raw(re as *mut RegexSet)); }
}
}

Expand Down Expand Up @@ -624,6 +624,6 @@ fn rure_escape(

ffi_fn! {
fn rure_cstring_free(s: *mut c_char) {
unsafe { CString::from_raw(s); }
unsafe { drop(CString::from_raw(s)); }
}
}

0 comments on commit 5466076

Please sign in to comment.