Skip to content

Commit 640a74c

Browse files
committed
Add generic pointer implementation for VaArg and VaArgGet
1 parent ba065d8 commit 640a74c

1 file changed

Lines changed: 29 additions & 23 deletions

File tree

libcc2rs/src/va_args.rs

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,23 @@ macro_rules! impl_va_arg_from {
2727
fn from(v: $ty) -> Self { VaArg::$variant(v as $cast) }
2828
}
2929
)*};
30-
(ptr: $($ty:ty),*) => {$(
31-
impl From<*mut $ty> for VaArg {
32-
fn from(v: *mut $ty) -> Self { VaArg::RawPtr(v as *mut c_void) }
33-
}
34-
impl From<*const $ty> for VaArg {
35-
fn from(v: *const $ty) -> Self { VaArg::RawPtr(v as *mut c_void) }
36-
}
37-
)*};
3830
}
3931

4032
impl_va_arg_from!(direct: i32 => Int, u32 => UInt, i64 => Long, u64 => ULong, f64 => Double, AnyPtr => Ptr);
4133
impl_va_arg_from!(promote: i8 => Int as i32, i16 => Int as i32, u8 => UInt as u32, u16 => UInt as u32, f32 => Double as f64);
42-
impl_va_arg_from!(ptr: c_void, i8, u8, i16, u16, i32, u32, i64, u64, f32, f64, usize, isize);
4334

44-
impl<T: Clone + crate::reinterpret::ByteRepr + 'static> From<crate::rc::Ptr<T>> for VaArg {
35+
impl<T> From<*mut T> for VaArg {
36+
fn from(v: *mut T) -> Self {
37+
VaArg::RawPtr(v as *mut c_void)
38+
}
39+
}
40+
impl<T> From<*const T> for VaArg {
41+
fn from(v: *const T) -> Self {
42+
VaArg::RawPtr(v as *mut c_void)
43+
}
44+
}
45+
46+
impl<T: crate::reinterpret::ByteRepr + 'static> From<crate::rc::Ptr<T>> for VaArg {
4547
fn from(v: crate::rc::Ptr<T>) -> Self {
4648
VaArg::Ptr(v.to_any())
4749
}
@@ -95,23 +97,27 @@ macro_rules! impl_va_arg_get {
9597
}
9698
}
9799
)*};
98-
(ptr: $($ty:ty),*) => {$(
99-
impl VaArgGet for *mut $ty {
100-
fn get(v: &VaArg) -> Self {
101-
match v { VaArg::RawPtr(p) => *p as Self, _ => panic!("VaArgGet: expected pointer") }
102-
}
103-
}
104-
impl VaArgGet for *const $ty {
105-
fn get(v: &VaArg) -> Self {
106-
match v { VaArg::RawPtr(p) => *p as Self, _ => panic!("VaArgGet: expected pointer") }
107-
}
108-
}
109-
)*};
110100
}
111101

112102
impl_va_arg_get!(int: i8, i16, i32, i64, u8, u16, u32, u64);
113103
impl_va_arg_get!(float: f32, f64);
114-
impl_va_arg_get!(ptr: c_void, i8, u8, i16, u16, i32, u32, i64, u64, f32, f64, usize, isize);
104+
105+
impl<T> VaArgGet for *mut T {
106+
fn get(v: &VaArg) -> Self {
107+
match v {
108+
VaArg::RawPtr(p) => *p as Self,
109+
_ => panic!("VaArgGet: expected pointer"),
110+
}
111+
}
112+
}
113+
impl<T> VaArgGet for *const T {
114+
fn get(v: &VaArg) -> Self {
115+
match v {
116+
VaArg::RawPtr(p) => *p as Self,
117+
_ => panic!("VaArgGet: expected pointer"),
118+
}
119+
}
120+
}
115121

116122
impl<T: 'static> VaArgGet for crate::rc::Ptr<T> {
117123
fn get(v: &VaArg) -> Self {

0 commit comments

Comments
 (0)