allow getting the function pointer / lazy import struct
This commit is contained in:
@@ -21,29 +21,39 @@ pub use make_seed;
|
||||
#[macro_export]
|
||||
macro_rules! link {
|
||||
($library:literal $abi:literal $($link_name:literal)? fn $fname:ident ($($name:ident : $arg:ty),*)) => (
|
||||
|
||||
#[allow(non_snake_case)]
|
||||
pub mod $fname {
|
||||
pub const SEED: u64 = $crate::lazy_importer::make_seed!();
|
||||
pub static IMPORT: $crate::lazy_importer::LazyImport<
|
||||
{ $crate::lazy_importer::hash_utf8::<SEED>($library.as_bytes()) },
|
||||
{ $crate::lazy_importer::hash_utf8::<SEED>(stringify!($fname).as_bytes()) },
|
||||
SEED, ()
|
||||
> = $crate::lazy_importer::LazyImport::new();
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
#[allow(non_snake_case)]
|
||||
pub fn $fname ($($name: $arg),*) {
|
||||
const SEED: u64 = $crate::lazy_importer::make_seed!();
|
||||
static LI: $crate::lazy_importer::LazyImport<
|
||||
{ $crate::lazy_importer::hash_utf8::<SEED>($library.as_bytes()) },
|
||||
{ $crate::lazy_importer::hash_utf8::<SEED>(stringify!($fname).as_bytes()) },
|
||||
SEED, ()
|
||||
> = $crate::lazy_importer::LazyImport::new();
|
||||
unsafe { core::mem::transmute::<_,extern $abi fn($($arg),*)>(LI.resolve())($($name),*) }
|
||||
unsafe { core::mem::transmute::<_,extern $abi fn($($arg),*)>($fname::IMPORT.resolve())($($name),*) }
|
||||
}
|
||||
);
|
||||
($library:literal $abi:literal $($link_name:literal)? fn $fname:ident ($($name:ident : $arg:ty),*) -> $ret:ty) => (
|
||||
#[inline(always)]
|
||||
|
||||
#[allow(non_snake_case)]
|
||||
pub fn $fname ($($name: $arg),*) -> $ret {
|
||||
const SEED: u64 = $crate::lazy_importer::make_seed!();
|
||||
static LI: $crate::lazy_importer::LazyImport<
|
||||
pub mod $fname {
|
||||
pub const SEED: u64 = $crate::lazy_importer::make_seed!();
|
||||
pub static IMPORT: $crate::lazy_importer::LazyImport<
|
||||
{ $crate::lazy_importer::hash_utf8::<SEED>($library.as_bytes()) },
|
||||
{ $crate::lazy_importer::hash_utf8::<SEED>(stringify!($fname).as_bytes()) },
|
||||
SEED, ()
|
||||
> = $crate::lazy_importer::LazyImport::new();
|
||||
unsafe { core::mem::transmute::<_,extern $abi fn($($arg),*) -> $ret>(LI.resolve())($($name),*) }
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
#[allow(non_snake_case)]
|
||||
pub fn $fname ($($name: $arg),*) -> $ret {
|
||||
unsafe { core::mem::transmute::<_,extern $abi fn($($arg),*) -> $ret>($fname::IMPORT.resolve())($($name),*) }
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user