refact: Add callback_get_vec_u8_data
Make it easier to correctly use the string callbacks. (cherry picked from commit 32db5dfc020053c36b7a4776313ee72d7bc961dd)
This commit is contained in:
parent
7cc9cfbb2b
commit
acb1274c08
2 changed files with 6 additions and 2 deletions
|
|
@ -2,7 +2,7 @@ use anyhow::{bail, Result};
|
|||
use lazy_static::lazy_static;
|
||||
use nix_c_raw as raw;
|
||||
use nix_util::context::Context;
|
||||
use nix_util::string_return::callback_get_vec_u8;
|
||||
use nix_util::string_return::{callback_get_vec_u8, callback_get_vec_u8_data};
|
||||
use std::ffi::CString;
|
||||
use std::ptr::null_mut;
|
||||
use std::ptr::NonNull;
|
||||
|
|
@ -84,7 +84,7 @@ impl Store {
|
|||
self.context.ptr(),
|
||||
self.inner.ptr(),
|
||||
Some(callback_get_vec_u8),
|
||||
&mut raw_buffer as *mut Vec<u8> as *mut std::ffi::c_void,
|
||||
callback_get_vec_u8_data(&mut raw_buffer),
|
||||
)
|
||||
};
|
||||
self.context.check_err()?;
|
||||
|
|
|
|||
|
|
@ -16,6 +16,10 @@ pub unsafe extern "C" fn callback_get_vec_u8(
|
|||
(*ret).extend_from_slice(slice);
|
||||
}
|
||||
|
||||
pub fn callback_get_vec_u8_data(vec: &mut Vec<u8>) -> *mut std::os::raw::c_void {
|
||||
vec as *mut Vec<u8> as *mut std::os::raw::c_void
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue