#[macro_export]
macro_rules! export {
($create:expr) => {
fn __pmpx_instance() -> ::std::boxed::Box<dyn $crate::PackageManager> {
let create: fn() -> ::std::boxed::Box<dyn $crate::PackageManager> = $create;
create()
}
#[doc(hidden)]
unsafe extern "C" fn __pmpx_name() -> $crate::abi::PmpxStr {
$crate::shell::guard_str(|| $crate::shell::leak_str(__pmpx_instance().name()))
}
#[doc(hidden)]
unsafe extern "C" fn __pmpx_family() -> $crate::abi::PmpxStr {
$crate::shell::guard_str(|| {
$crate::shell::leak_str(__pmpx_instance().family().as_str())
})
}
#[doc(hidden)]
unsafe extern "C" fn __pmpx_run(
context: *const $crate::abi::PmpxContext,
out: *mut $crate::abi::PmpxCommand,
) -> ::std::primitive::u32 {
$crate::shell::guard(move || {
let plugin = __pmpx_instance();
$crate::shell::remember_name(plugin.name());
unsafe { $crate::shell::dispatch(&*plugin, context, out) }
})
}
#[doc(hidden)]
unsafe extern "C" fn __pmpx_attach(host: *const $crate::abi::PmpxHost) {
if host.is_null() {
return;
}
let lookup = unsafe { (*host).capability };
let key = $crate::abi::PmpxStr::new(
$crate::abi::PMPX_CAP_LOG.as_ptr(),
$crate::abi::PMPX_CAP_LOG.len(),
);
let table = unsafe { lookup(key) };
if table.is_null() {
return;
}
let table = table as *const $crate::abi::PmpxLog;
if unsafe { (*table).size } < ::std::mem::size_of::<$crate::abi::PmpxLog>() {
return;
}
unsafe { $crate::shell::install_log_table(table) };
}
#[doc(hidden)]
unsafe extern "C" fn __pmpx_free_str(s: $crate::abi::PmpxStr) {
unsafe { $crate::shell::dispatch_free_str(s) }
}
#[doc(hidden)]
unsafe extern "C" fn __pmpx_free_command(command: *mut $crate::abi::PmpxCommand) {
unsafe { $crate::shell::dispatch_free_command(command) }
}
#[doc(hidden)]
unsafe extern "C" fn __pmpx_capability(
name: $crate::abi::PmpxStr,
) -> *const ::std::ffi::c_void {
let Some(name) = (unsafe { $crate::shell::read_str(name) }) else {
return ::std::ptr::null();
};
match name {
$crate::abi::PMPX_CAP_IDENTITY => ::std::ptr::from_ref(&__PMPX_IDENTITY).cast(),
$crate::abi::PMPX_CAP_COMMAND => ::std::ptr::from_ref(&__PMPX_COMMAND).cast(),
$crate::abi::PMPX_CAP_ATTACH => ::std::ptr::from_ref(&__PMPX_ATTACH).cast(),
_ => ::std::ptr::null(),
}
}
#[doc(hidden)]
static __PMPX_IDENTITY: $crate::abi::PmpxIdentity = $crate::abi::PmpxIdentity {
size: ::std::mem::size_of::<$crate::abi::PmpxIdentity>(),
name: __pmpx_name,
family: __pmpx_family,
free_str: __pmpx_free_str,
};
#[doc(hidden)]
static __PMPX_COMMAND: $crate::abi::PmpxCommandCap = $crate::abi::PmpxCommandCap {
size: ::std::mem::size_of::<$crate::abi::PmpxCommandCap>(),
run: __pmpx_run,
free_command: __pmpx_free_command,
};
#[doc(hidden)]
static __PMPX_ATTACH: $crate::abi::PmpxAttach = $crate::abi::PmpxAttach {
size: ::std::mem::size_of::<$crate::abi::PmpxAttach>(),
attach: __pmpx_attach,
};
#[doc(hidden)]
static __PMPX_PLUGIN: $crate::abi::PmpxPlugin = $crate::abi::PmpxPlugin {
abi_major: $crate::abi::PMPX_ABI_MAJOR,
rustc_version: $crate::abi::PmpxStr::new(
$crate::shell::BUILD_RUSTC.as_ptr(),
$crate::shell::BUILD_RUSTC.len(),
),
target: $crate::abi::PmpxStr::new(
$crate::shell::BUILD_TARGET.as_ptr(),
$crate::shell::BUILD_TARGET.len(),
),
capability: __pmpx_capability,
};
const _: $crate::abi::RunFn = __pmpx_run;
#[unsafe(no_mangle)]
pub extern "C" fn pmpx_plugin_entry_v3() -> *const $crate::abi::PmpxPlugin {
&__PMPX_PLUGIN
}
};
}