diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2019-12-13 18:29:16 +0100 |
---|---|---|
committer | Eelco Dolstra <edolstra@gmail.com> | 2019-12-13 19:05:26 +0100 |
commit | ca87707c90c05289d0c7c1015f5750f6dd93708b (patch) | |
tree | 4364240709b658c599e12b79bff040b72c9afc3e /nix-rust/src | |
parent | 5a6d6da7aea23a48126a77f98612518af66bc203 (diff) |
Get rid of CBox
Diffstat (limited to 'nix-rust/src')
-rw-r--r-- | nix-rust/src/c.rs | 11 | ||||
-rw-r--r-- | nix-rust/src/foreign.rs | 19 |
2 files changed, 6 insertions, 24 deletions
diff --git a/nix-rust/src/c.rs b/nix-rust/src/c.rs index 3feeb71a3..e0462742f 100644 --- a/nix-rust/src/c.rs +++ b/nix-rust/src/c.rs @@ -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] diff --git a/nix-rust/src/foreign.rs b/nix-rust/src/foreign.rs index 8e04280f3..7bce7753c 100644 --- a/nix-rust/src/foreign.rs +++ b/nix-rust/src/foreign.rs @@ -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, - } - } - } -} |