Add support for inline variable names in error/warning/info message creation macros

Simply by removing the special-casing of string literals, which doesn't
really bring any improvements here.

Fixes https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/issues/442

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1218>
This commit is contained in:
Sebastian Dröge 2023-02-12 13:27:59 +02:00
parent 66453fdc02
commit 6bd559f5b5
4 changed files with 0 additions and 387 deletions

View file

@ -152,42 +152,6 @@ impl<O: IsA<AudioDecoder>> AudioDecoderExtManual for O {
#[macro_export] #[macro_export]
macro_rules! audio_decoder_error( macro_rules! audio_decoder_error(
($obj:expr, $weight:expr, $err:expr, ($msg:expr), [$debug:expr]) => { {
use $crate::prelude::AudioDecoderExtManual;
$obj.error(
$weight,
$err,
Some($msg),
Some($debug),
file!(),
$crate::glib::function_name!(),
line!(),
)
}};
($obj:expr, $weight:expr, $err:expr, ($msg:expr)) => { {
use $crate::prelude::AudioDecoderExtManual;
$obj.error(
$weight,
$err,
Some($msg),
None,
file!(),
$crate::glib::function_name!(),
line!(),
)
}};
($obj:expr, $weight:expr, $err:expr, [$debug:expr]) => { {
use $crate::prelude::AudioDecoderExtManual;
$obj.error(
$weight,
$err,
None,
Some($debug),
file!(),
$crate::glib::function_name!(),
line!(),
)
}};
($obj:expr, $weight:expr, $err:expr, ($($msg:tt)*), [$($debug:tt)*]) => { { ($obj:expr, $weight:expr, $err:expr, ($($msg:tt)*), [$($debug:tt)*]) => { {
use $crate::prelude::AudioDecoderExtManual; use $crate::prelude::AudioDecoderExtManual;
$obj.error( $obj.error(

View file

@ -353,42 +353,6 @@ impl HasStreamLock for VideoDecoder {
#[macro_export] #[macro_export]
macro_rules! video_decoder_error( macro_rules! video_decoder_error(
($obj:expr, $weight:expr, $err:expr, ($msg:expr), [$debug:expr]) => { {
use $crate::prelude::VideoDecoderExtManual;
$obj.error(
$weight,
$err,
Some($msg),
Some($debug),
file!(),
$crate::glib::function_name!(),
line!(),
)
}};
($obj:expr, $weight:expr, $err:expr, ($msg:expr)) => { {
use $crate::prelude::VideoDecoderExtManual;
$obj.error(
$weight,
$err,
Some($msg),
None,
file!(),
$crate::glib::function_name!(),
line!(),
)
}};
($obj:expr, $weight:expr, $err:expr, [$debug:expr]) => { {
use $crate::prelude::VideoDecoderExtManual;
$obj.error(
$weight,
$err,
None,
Some($debug),
file!(),
$crate::glib::function_name!(),
line!(),
)
}};
($obj:expr, $weight:expr, $err:expr, ($($msg:tt)*), [$($debug:tt)*]) => { { ($obj:expr, $weight:expr, $err:expr, ($($msg:tt)*), [$($debug:tt)*]) => { {
use $crate::prelude::VideoDecoderExtManual; use $crate::prelude::VideoDecoderExtManual;
$obj.error( $obj.error(

View file

@ -1003,42 +1003,6 @@ pub static ELEMENT_METADATA_LONGNAME: &glib::GStr =
#[doc(alias = "GST_ELEMENT_ERROR_WITH_DETAILS")] #[doc(alias = "GST_ELEMENT_ERROR_WITH_DETAILS")]
#[macro_export] #[macro_export]
macro_rules! element_error( macro_rules! element_error(
($obj:expr, $err:expr, ($msg:expr), [$debug:expr]) => { {
use $crate::prelude::ElementExtManual;
$obj.message_full(
$crate::ElementMessageType::Error,
$err,
Some($msg),
Some($debug),
file!(),
$crate::glib::function_name!(),
line!(),
);
}};
($obj:expr, $err:expr, ($msg:expr)) => { {
use $crate::prelude::ElementExtManual;
$obj.message_full(
$crate::ElementMessageType::Error,
$err,
Some($msg),
None,
file!(),
$crate::glib::function_name!(),
line!(),
);
}};
($obj:expr, $err:expr, [$debug:expr]) => { {
use $crate::prelude::ElementExtManual;
$obj.message_full(
$crate::ElementMessageType::Error,
$err,
None,
Some($debug),
file!(),
$crate::glib::function_name!(),
line!(),
);
}};
($obj:expr, $err:expr, ($($msg:tt)*), [$($debug:tt)*]) => { { ($obj:expr, $err:expr, ($($msg:tt)*), [$($debug:tt)*]) => { {
use $crate::prelude::ElementExtManual; use $crate::prelude::ElementExtManual;
$obj.message_full( $obj.message_full(
@ -1076,45 +1040,6 @@ macro_rules! element_error(
); );
}}; }};
($obj:expr, $err:expr, ($msg:expr), [$debug:expr], details: $details:expr) => { {
use $crate::prelude::ElementExtManual;
$obj.message_full_with_details(
$crate::ElementMessageType::Error,
$err,
Some($msg),
Some($debug),
file!(),
$crate::glib::function_name!(),
line!(),
$details,
);
}};
($obj:expr, $err:expr, ($msg:expr), details: $details:expr) => { {
use $crate::prelude::ElementExtManual;
$obj.message_full_with_details(
$crate::ElementMessageType::Error,
$err,
Some($msg),
None,
file!(),
$crate::glib::function_name!(),
line!(),
$details,
);
}};
($obj:expr, $err:expr, [$debug:expr], details: $details:expr) => { {
use $crate::prelude::ElementExtManual;
$obj.message_full_with_details(
$crate::ElementMessageType::Error,
$err,
None,
Some($debug),
file!(),
$crate::glib::function_name!(),
line!(),
$details,
);
}};
($obj:expr, $err:expr, ($($msg:tt)*), [$($debug:tt)*], details: $details:expr) => { { ($obj:expr, $err:expr, ($($msg:tt)*), [$($debug:tt)*], details: $details:expr) => { {
use $crate::prelude::ElementExtManual; use $crate::prelude::ElementExtManual;
$obj.message_full_with_details( $obj.message_full_with_details(
@ -1160,42 +1085,6 @@ macro_rules! element_error(
#[doc(alias = "GST_ELEMENT_WARNING_WITH_DETAILS")] #[doc(alias = "GST_ELEMENT_WARNING_WITH_DETAILS")]
#[macro_export] #[macro_export]
macro_rules! element_warning( macro_rules! element_warning(
($obj:expr, $err:expr, ($msg:expr), [$debug:expr]) => { {
use $crate::prelude::ElementExtManual;
$obj.message_full(
$crate::ElementMessageType::Warning,
$err,
Some($msg),
Some($debug),
file!(),
$crate::glib::function_name!(),
line!(),
);
}};
($obj:expr, $err:expr, ($msg:expr)) => { {
use $crate::prelude::ElementExtManual;
$obj.message_full(
$crate::ElementMessageType::Warning,
$err,
Some($msg),
None,
file!(),
$crate::glib::function_name!(),
line!(),
);
}};
($obj:expr, $err:expr, [$debug:expr]) => { {
use $crate::prelude::ElementExtManual;
$obj.message_full(
$crate::ElementMessageType::Warning,
$err,
None,
Some($debug),
file!(),
$crate::glib::function_name!(),
line!(),
);
}};
($obj:expr, $err:expr, ($($msg:tt)*), [$($debug:tt)*]) => { { ($obj:expr, $err:expr, ($($msg:tt)*), [$($debug:tt)*]) => { {
use $crate::prelude::ElementExtManual; use $crate::prelude::ElementExtManual;
$obj.message_full( $obj.message_full(
@ -1233,45 +1122,6 @@ macro_rules! element_warning(
); );
}}; }};
($obj:expr, $err:expr, ($msg:expr), [$debug:expr], details: $details:expr) => { {
use $crate::prelude::ElementExtManual;
$obj.message_full_with_details(
$crate::ElementMessageType::Warning,
$err,
Some($msg),
Some($debug),
file!(),
$crate::glib::function_name!(),
line!(),
$details,
);
}};
($obj:expr, $err:expr, ($msg:expr), details: $details:expr) => { {
use $crate::prelude::ElementExtManual;
$obj.message_full_with_details(
$crate::ElementMessageType::Warning,
$err,
Some($msg),
None,
file!(),
$crate::glib::function_name!(),
line!(),
$details,
);
}};
($obj:expr, $err:expr, [$debug:expr], details: $details:expr) => { {
use $crate::prelude::ElementExtManual;
$obj.message_full_with_details(
$crate::ElementMessageType::Warning,
$err,
None,
Some($debug),
file!(),
$crate::glib::function_name!(),
line!(),
$details,
);
}};
($obj:expr, $err:expr, ($($msg:tt)*), [$($debug:tt)*], details: $details:expr) => { { ($obj:expr, $err:expr, ($($msg:tt)*), [$($debug:tt)*], details: $details:expr) => { {
use $crate::prelude::ElementExtManual; use $crate::prelude::ElementExtManual;
$obj.message_full_with_details( $obj.message_full_with_details(
@ -1317,42 +1167,6 @@ macro_rules! element_warning(
#[doc(alias = "GST_ELEMENT_INFO_WITH_DETAILS")] #[doc(alias = "GST_ELEMENT_INFO_WITH_DETAILS")]
#[macro_export] #[macro_export]
macro_rules! element_info( macro_rules! element_info(
($obj:expr, $err:expr, ($msg:expr), [$debug:expr]) => { {
use $crate::prelude::ElementExtManual;
$obj.message_full(
$crate::ElementMessageType::Info,
$err,
Some($msg),
Some($debug),
file!(),
$crate::glib::function_name!(),
line!(),
);
}};
($obj:expr, $err:expr, ($msg:expr)) => { {
use $crate::prelude::ElementExtManual;
$obj.message_full(
$crate::ElementMessageType::Info,
$err,
Some($msg),
None,
file!(),
$crate::glib::function_name!(),
line!(),
);
}};
($obj:expr, $err:expr, [$debug:expr]) => { {
use $crate::prelude::ElementExtManual;
$obj.message_full(
$crate::ElementMessageType::Info,
$err,
None,
Some($debug),
file!(),
$crate::glib::function_name!(),
line!(),
);
}};
($obj:expr, $err:expr, ($($msg:tt)*), [$($debug:tt)*]) => { { ($obj:expr, $err:expr, ($($msg:tt)*), [$($debug:tt)*]) => { {
use $crate::prelude::ElementExtManual; use $crate::prelude::ElementExtManual;
$obj.message_full( $obj.message_full(
@ -1390,45 +1204,6 @@ macro_rules! element_info(
); );
}}; }};
($obj:expr, $err:expr, ($msg:expr), [$debug:expr], details: $details:expr) => { {
use $crate::prelude::ElementExtManual;
$obj.message_full_with_details(
$crate::ElementMessageType::Info,
$err,
Some($msg),
Some($debug),
file!(),
$crate::glib::function_name!(),
line!(),
$details,
);
}};
($obj:expr, $err:expr, ($msg:expr), details: $details:expr) => { {
use $crate::prelude::ElementExtManual;
$obj.message_full_with_details(
$crate::ElementMessageType::Info,
$err,
Some($msg),
None,
file!(),
$crate::glib::function_name!(),
line!(),
$details,
);
}};
($obj:expr, $err:expr, [$debug:expr], details: $details:expr) => { {
use $crate::prelude::ElementExtManual;
$obj.message_full_with_details(
$crate::ElementMessageType::Info,
$err,
None,
Some($debug),
file!(),
$crate::glib::function_name!(),
line!(),
$details,
);
}};
($obj:expr, $err:expr, ($($msg:tt)*), [$($debug:tt)*], details: $details:expr) => { { ($obj:expr, $err:expr, ($($msg:tt)*), [$($debug:tt)*], details: $details:expr) => { {
use $crate::prelude::ElementExtManual; use $crate::prelude::ElementExtManual;
$obj.message_full_with_details( $obj.message_full_with_details(
@ -1474,18 +1249,6 @@ macro_rules! element_info(
#[doc(alias = "GST_ELEMENT_ERROR_WITH_DETAILS")] #[doc(alias = "GST_ELEMENT_ERROR_WITH_DETAILS")]
#[macro_export] #[macro_export]
macro_rules! element_imp_error( macro_rules! element_imp_error(
($imp:expr, $err:expr, ($msg:expr), [$debug:expr]) => { {
let obj = $imp.obj();
$crate::element_error!(obj, $err, ($msg), [$debug]);
}};
($imp:expr, $err:expr, ($msg:expr)) => { {
let obj = $imp.obj();
$crate::element_error!(obj, $err, ($msg));
}};
($imp:expr, $err:expr, [$debug:expr]) => { {
let obj = $imp.obj();
$crate::element_error!(obj, $err, [$debug]);
}};
($imp:expr, $err:expr, ($($msg:tt)*), [$($debug:tt)*]) => { { ($imp:expr, $err:expr, ($($msg:tt)*), [$($debug:tt)*]) => { {
let obj = $imp.obj(); let obj = $imp.obj();
$crate::element_error!(obj, $err, ($($msg)*), [$($debug)*]); $crate::element_error!(obj, $err, ($($msg)*), [$($debug)*]);
@ -1499,18 +1262,6 @@ macro_rules! element_imp_error(
$crate::element_error!(obj, $err, [$($debug)*]); $crate::element_error!(obj, $err, [$($debug)*]);
}}; }};
($imp:expr, $err:expr, ($msg:expr), [$debug:expr], details: $details:expr) => { {
let obj = $imp.obj();
$crate::element_error!(obj, $err, ($msg), [$debug], details: $details);
}};
($imp:expr, $err:expr, ($msg:expr), details: $details:expr) => { {
let obj = $imp.obj();
$crate::element_error!(obj, $err, ($msg), details: $details);
}};
($imp:expr, $err:expr, [$debug:expr], details: $details:expr) => { {
let obj = $imp.obj();
$crate::element_error!(obj, $err, [$debug], details: $details);
}};
($imp:expr, $err:expr, ($($msg:tt)*), [$($debug:tt)*], details: $details:expr) => { { ($imp:expr, $err:expr, ($($msg:tt)*), [$($debug:tt)*], details: $details:expr) => { {
let obj = $imp.obj(); let obj = $imp.obj();
$crate::element_error!(obj, $err, ($($msg)*), [$($debug)*], details: $details); $crate::element_error!(obj, $err, ($($msg)*), [$($debug)*], details: $details);
@ -1529,18 +1280,6 @@ macro_rules! element_imp_error(
#[doc(alias = "GST_ELEMENT_WARNING_WITH_DETAILS")] #[doc(alias = "GST_ELEMENT_WARNING_WITH_DETAILS")]
#[macro_export] #[macro_export]
macro_rules! element_imp_warning( macro_rules! element_imp_warning(
($imp:expr, $err:expr, ($msg:expr), [$debug:expr]) => { {
let obj = $imp.obj();
$crate::element_warning!(obj, $err, ($msg), [$debug]);
}};
($imp:expr, $err:expr, ($msg:expr)) => { {
let obj = $imp.obj();
$crate::element_warning!(obj, $err, ($msg));
}};
($imp:expr, $err:expr, [$debug:expr]) => { {
let obj = $imp.obj();
$crate::element_warning!(obj, $err, [$debug]);
}};
($imp:expr, $err:expr, ($($msg:tt)*), [$($debug:tt)*]) => { { ($imp:expr, $err:expr, ($($msg:tt)*), [$($debug:tt)*]) => { {
let obj = $imp.obj(); let obj = $imp.obj();
$crate::element_warning!(obj, $err, ($($msg)*), [$($debug)*]); $crate::element_warning!(obj, $err, ($($msg)*), [$($debug)*]);
@ -1554,18 +1293,6 @@ macro_rules! element_imp_warning(
$crate::element_warning!(obj, $err, [$($debug)*]); $crate::element_warning!(obj, $err, [$($debug)*]);
}}; }};
($imp:expr, $err:expr, ($msg:expr), [$debug:expr], details: $details:expr) => { {
let obj = $imp.obj();
$crate::element_warning!(obj, $err, ($msg), [$debug], details: $details);
}};
($imp:expr, $err:expr, ($msg:expr), details: $details:expr) => { {
let obj = $imp.obj();
$crate::element_warning!(obj, $err, ($msg), details: $details);
}};
($imp:expr, $err:expr, [$debug:expr], details: $details:expr) => { {
let obj = $imp.obj();
$crate::element_warning!(obj, $err, [$debug], details: $details);
}};
($imp:expr, $err:expr, ($($msg:tt)*), [$($debug:tt)*], details: $details:expr) => { { ($imp:expr, $err:expr, ($($msg:tt)*), [$($debug:tt)*], details: $details:expr) => { {
let obj = $imp.obj(); let obj = $imp.obj();
$crate::element_warning!(obj, $err, ($($msg)*), [$($debug)*], details: $details); $crate::element_warning!(obj, $err, ($($msg)*), [$($debug)*], details: $details);
@ -1584,18 +1311,6 @@ macro_rules! element_imp_warning(
#[doc(alias = "GST_ELEMENT_INFO_WITH_DETAILS")] #[doc(alias = "GST_ELEMENT_INFO_WITH_DETAILS")]
#[macro_export] #[macro_export]
macro_rules! element_imp_info( macro_rules! element_imp_info(
($imp:expr, $err:expr, ($msg:expr), [$debug:expr]) => { {
let obj = $imp.obj();
$crate::element_info!(obj, $err, ($msg), [$debug]);
}};
($imp:expr, $err:expr, ($msg:expr)) => { {
let obj = $imp.obj();
$crate::element_info!(obj, $err, ($msg));
}};
($imp:expr, $err:expr, [$debug:expr]) => { {
let obj = $imp.obj();
$crate::element_info!(obj, $err, [$debug]);
}};
($imp:expr, $err:expr, ($($msg:tt)*), [$($debug:tt)*]) => { { ($imp:expr, $err:expr, ($($msg:tt)*), [$($debug:tt)*]) => { {
let obj = $imp.obj(); let obj = $imp.obj();
$crate::element_info!(obj, $err, ($($msg)*), [$($debug)*]); $crate::element_info!(obj, $err, ($($msg)*), [$($debug)*]);
@ -1609,18 +1324,6 @@ macro_rules! element_imp_info(
$crate::element_info!(obj, $err, [$($debug)*]); $crate::element_info!(obj, $err, [$($debug)*]);
}}; }};
($imp:expr, $err:expr, ($msg:expr), [$debug:expr], details: $details:expr) => { {
let obj = $imp.obj();
$crate::element_info!(obj, $err, ($msg), [$debug], details: $details);
}};
($imp:expr, $err:expr, ($msg:expr), details: $details:expr) => { {
let obj = $imp.obj();
$crate::element_info!(obj, $err, ($msg), details: $details);
}};
($imp:expr, $err:expr, [$debug:expr], details: $details:expr) => { {
let obj = $imp.obj();
$crate::element_info!(obj, $err, [$debug], details: $details);
}};
($imp:expr, $err:expr, ($($msg:tt)*), [$($debug:tt)*], details: $details:expr) => { { ($imp:expr, $err:expr, ($($msg:tt)*), [$($debug:tt)*], details: $details:expr) => { {
let obj = $imp.obj(); let obj = $imp.obj();
$crate::element_info!(obj, $err, ($($msg)*), [$($debug)*], details: $details); $crate::element_info!(obj, $err, ($($msg)*), [$($debug)*], details: $details);

View file

@ -5,24 +5,6 @@ use thiserror::Error;
#[macro_export] #[macro_export]
macro_rules! error_msg( macro_rules! error_msg(
// Plain strings
($err:expr, ($msg:expr), [$dbg:expr]) => {
$crate::ErrorMessage::new(&$err, Some($msg),
Some($dbg),
file!(), $crate::glib::function_name!(), line!())
};
($err:expr, ($msg:expr)) => {
$crate::ErrorMessage::new(&$err, Some($msg),
None,
file!(), $crate::glib::function_name!(), line!())
};
($err:expr, [$dbg:expr]) => {
$crate::ErrorMessage::new(&$err, None,
Some($dbg),
file!(), $crate::glib::function_name!(), line!())
};
// Format strings
($err:expr, ($($msg:tt)*), [$($dbg:tt)*]) => { { ($err:expr, ($($msg:tt)*), [$($dbg:tt)*]) => { {
$crate::ErrorMessage::new(&$err, Some(format!($($msg)*).as_ref()), $crate::ErrorMessage::new(&$err, Some(format!($($msg)*).as_ref()),
Some(format!($($dbg)*).as_ref()), Some(format!($($dbg)*).as_ref()),