1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-26 15:51:15 +02:00

Move stuff around

This commit is contained in:
Eelco Dolstra 2019-09-15 23:09:30 +02:00
parent ce3c41aef0
commit a1ff43045b
10 changed files with 74 additions and 67 deletions

View file

@ -12,3 +12,22 @@ 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,
}
}
}
}