mirror of
https://git.intege.rs/xlib/x.git
synced 2025-12-05 20:35:01 +00:00
40 lines
1.1 KiB
Rust
40 lines
1.1 KiB
Rust
|
|
/// appends zeroes to the end of the string and converts it into a pointer
|
|
/// useful for quick ffi
|
|
#[macro_export]
|
|
macro_rules! cstr {
|
|
($str:expr) => {
|
|
concat!($str,"\0\0").as_ptr() as *const i8
|
|
}
|
|
}
|
|
|
|
|
|
/// utility macro for inline c functions
|
|
///
|
|
/// | macro | rust |
|
|
/// |-----------|----------|
|
|
/// | ```cfn!( () -> usize )``` | ``` extern "C" fn() -> usize``` |
|
|
/// | ```cfn!( (usize) -> usize )``` | ``` extern "C" fn(usize) -> usize``` |
|
|
/// | ```cfn!( (usize) )``` | ``` extern "C" fn(usize)``` |
|
|
/// | ```cfn!( (u32, usize, usize) -> u32 )``` | ``` extern "C" fn(u32, usize, usize) -> u32``` |
|
|
#[macro_export]
|
|
macro_rules! cfn {
|
|
( ($($t:ty),*)) => {
|
|
extern "C" fn($( $t ),* )
|
|
};
|
|
( ($($t:ty),*) -> $r:ty) => {
|
|
extern "C" fn($( $t ),* ) -> $r
|
|
}
|
|
}
|
|
|
|
/// utility macro for pointer chains
|
|
#[macro_export]
|
|
macro_rules! ptr_chain {
|
|
($x: expr, $y:expr) => {{
|
|
(*core::mem::transmute::<_,*const usize>(core::mem::transmute::<_,usize>($x) + $y))
|
|
}};
|
|
|
|
($x: expr, $y:expr, $( $z:expr ),+ ) => {{
|
|
$crate::ptr_chain!( $crate::ptr_chain!($x, $y), $( $z ),+ )
|
|
}};
|
|
} |