impl-x86-sysv.rs 1.65 KB
Newer Older
1 2 3 4 5 6 7 8 9
/*
 *
 */
#[cfg(nightly)] use core::prelude::*;
#[cfg(nightly)] use core::{mem,ptr};
#[cfg(not(nightly))] use std::{mem,ptr};
use super::VaPrimitive;

#[allow(non_camel_case_types)]
10
pub struct VaList(*const u8);
11

12
impl VaList
13 14 15 16 17 18 19
{
	pub unsafe fn get<T: VaPrimitive>(&mut self) -> T {
		T::get(self)
	}
	
	// Read a raw value from the list
	unsafe fn get_raw<T: 'static>(&mut self) -> T {
John Hodge's avatar
John Hodge committed
20
		assert_eq!(self.0 as usize % mem::align_of::<T>(), 0);
21 22 23 24 25 26 27 28
		let rv = ptr::read(self.0 as *const T);
		self.0 = self.0.offset( mem::size_of::<T>() as isize );
		rv
	}
}

impl<T: 'static> VaPrimitive for *const T
{
29
	unsafe fn get(list: &mut VaList) -> Self {
30 31 32
		<usize>::get(list) as *const T
	}
}
33 34 35 36 37 38 39 40 41 42 43 44
impl VaPrimitive for usize { unsafe fn get(l: &mut VaList) -> Self { l.get_raw() } }
impl VaPrimitive for isize { unsafe fn get(l: &mut VaList) -> Self { l.get_raw() } }
impl VaPrimitive for u64 { unsafe fn get(l: &mut VaList) -> Self { l.get_raw() } }
impl VaPrimitive for i64 { unsafe fn get(l: &mut VaList) -> Self { l.get_raw() } }
impl VaPrimitive for u32 { unsafe fn get(l: &mut VaList) -> Self { l.get_raw() } }
impl VaPrimitive for i32 { unsafe fn get(l: &mut VaList) -> Self { l.get_raw() } }
//impl VaPrimitive for u16 { unsafe fn get(l: &mut VaList) -> Self { l.get_raw() } }
//impl VaPrimitive for i16 { unsafe fn get(l: &mut VaList) -> Self { l.get_raw() } }
//impl VaPrimitive for u8 { unsafe fn get(l: &mut VaList) -> Self { l.get_raw() } }
//impl VaPrimitive for i8 { unsafe fn get(l: &mut VaList) -> Self { l.get_raw() } }
impl VaPrimitive for f64 { unsafe fn get(l: &mut VaList) -> Self { l.get_raw() } }
impl VaPrimitive for f32 { unsafe fn get(l: &mut VaList) -> Self { l.get_raw() } }
45