From ca87707c90c05289d0c7c1015f5750f6dd93708b Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 13 Dec 2019 18:29:16 +0100 Subject: Get rid of CBox --- nix-rust/src/c.rs | 11 ++++++----- nix-rust/src/foreign.rs | 19 ------------------- 2 files changed, 6 insertions(+), 24 deletions(-) (limited to 'nix-rust/src') 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> { - 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 { - pub ptr: *mut libc::c_void, - phantom: std::marker::PhantomData, -} - -impl CBox { - pub fn new(t: T) -> Self { - unsafe { - let size = std::mem::size_of::(); - let ptr = libc::malloc(size); - *(ptr as *mut T) = t; // FIXME: probably UB - Self { - ptr, - phantom: std::marker::PhantomData, - } - } - } -} -- cgit v1.2.3