mirror of
https://github.com/NixOS/nix
synced 2025-06-25 06:31:14 +02:00
Get rid of CBox
This commit is contained in:
parent
5a6d6da7ae
commit
ca87707c90
4 changed files with 10 additions and 46 deletions
|
@ -1,20 +1,21 @@
|
|||
use super::{
|
||||
error,
|
||||
foreign::{self, CBox},
|
||||
foreign::{self},
|
||||
store::path,
|
||||
store::StorePath,
|
||||
util,
|
||||
};
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn unpack_tarfile(
|
||||
pub unsafe extern "C" fn unpack_tarfile(
|
||||
source: foreign::Source,
|
||||
dest_dir: &str,
|
||||
) -> CBox<Result<(), error::CppException>> {
|
||||
CBox::new(
|
||||
out: *mut Result<(), error::CppException>,
|
||||
) {
|
||||
out.write(
|
||||
util::tarfile::unpack_tarfile(source, std::path::Path::new(dest_dir))
|
||||
.map_err(|err| err.into()),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
|
|
|
@ -12,22 +12,3 @@ impl std::io::Read for Source {
|
|||
Ok(n)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct CBox<T> {
|
||||
pub ptr: *mut libc::c_void,
|
||||
phantom: std::marker::PhantomData<T>,
|
||||
}
|
||||
|
||||
impl<T> CBox<T> {
|
||||
pub fn new(t: T) -> Self {
|
||||
unsafe {
|
||||
let size = std::mem::size_of::<T>();
|
||||
let ptr = libc::malloc(size);
|
||||
*(ptr as *mut T) = t; // FIXME: probably UB
|
||||
Self {
|
||||
ptr,
|
||||
phantom: std::marker::PhantomData,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue