mirror of
https://github.com/chatmail/core.git
synced 2026-04-17 21:46:35 +03:00
Add a trait for str.strdup() to replace to_cstring() which avoid the signature ambiguity with .to_string(). Also instruduce CString::yolo() as a shortcut to CString::new().unwrap() and use it whenever the variable does can be deallocated by going out of scope. This is less error prone. Use some Path.to_c_string() functions where possible.
60 lines
2.1 KiB
Rust
60 lines
2.1 KiB
Rust
#[macro_export]
|
|
macro_rules! info {
|
|
($ctx:expr, $data1:expr, $msg:expr) => {
|
|
info!($ctx, $data1, $msg,)
|
|
};
|
|
($ctx:expr, $data1:expr, $msg:expr, $($args:expr),* $(,)?) => {
|
|
#[allow(unused_unsafe)]
|
|
unsafe {
|
|
let formatted = format!($msg, $($args),*);
|
|
let formatted_c = std::ffi::CString::new(formatted).unwrap();
|
|
$ctx.call_cb($crate::constants::Event::INFO, $data1 as libc::uintptr_t,
|
|
formatted_c.as_ptr() as libc::uintptr_t);
|
|
}};
|
|
}
|
|
|
|
#[macro_export]
|
|
macro_rules! warn {
|
|
($ctx:expr, $data1:expr, $msg:expr) => {
|
|
warn!($ctx, $data1, $msg,)
|
|
};
|
|
($ctx:expr, $data1:expr, $msg:expr, $($args:expr),* $(,)?) => {
|
|
#[allow(unused_unsafe)]
|
|
unsafe {
|
|
let formatted = format!($msg, $($args),*);
|
|
let formatted_c = std::ffi::CString::new(formatted).unwrap();
|
|
$ctx.call_cb($crate::constants::Event::WARNING, $data1 as libc::uintptr_t,
|
|
formatted_c.as_ptr() as libc::uintptr_t);
|
|
}};
|
|
}
|
|
|
|
#[macro_export]
|
|
macro_rules! error {
|
|
($ctx:expr, $data1:expr, $msg:expr) => {
|
|
error!($ctx, $data1, $msg,)
|
|
};
|
|
($ctx:expr, $data1:expr, $msg:expr, $($args:expr),* $(,)?) => {
|
|
#[allow(unused_unsafe)]
|
|
unsafe {
|
|
let formatted = format!($msg, $($args),*);
|
|
let formatted_c = std::ffi::CString::new(formatted).unwrap();
|
|
$ctx.call_cb($crate::constants::Event::ERROR, $data1 as libc::uintptr_t,
|
|
formatted_c.as_ptr() as libc::uintptr_t);
|
|
}};
|
|
}
|
|
|
|
#[macro_export]
|
|
macro_rules! log_event {
|
|
($ctx:expr, $data1:expr, $msg:expr) => {
|
|
log_event!($ctx, $data1, $msg,)
|
|
};
|
|
($ctx:expr, $event:expr, $data1:expr, $msg:expr, $($args:expr),* $(,)?) => {
|
|
#[allow(unused_unsafe)]
|
|
unsafe {
|
|
let formatted = format!($msg, $($args),*);
|
|
let formatted_c = std::ffi::CString::new(formatted).unwrap();
|
|
$ctx.call_cb($event, $data1 as libc::uintptr_t,
|
|
formatted_c.as_ptr() as libc::uintptr_t);
|
|
}};
|
|
}
|