Skip to content

cortex-m-semihosting: make semihosting macros compatible with 1-arg format strings #591

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions cortex-m-semihosting/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ macro_rules! syscall1 {
#[macro_export]
macro_rules! hprint {
($s:expr) => {
$crate::export::hstdout_str($s)
$crate::export::hstdout_fmt(format_args!($s))
};
($($tt:tt)*) => {
$crate::export::hstdout_fmt(format_args!($($tt)*))
Expand All @@ -53,10 +53,10 @@ macro_rules! hprintln {
$crate::export::hstdout_str("\n")
};
($s:expr) => {
$crate::export::hstdout_str(concat!($s, "\n"))
$crate::export::hstdout_fmt(format_args!("{}\n", format_args!($s)))
};
($s:expr, $($tt:tt)*) => {
$crate::export::hstdout_fmt(format_args!(concat!($s, "\n"), $($tt)*))
$crate::export::hstdout_fmt(format_args!("{}\n", format_args!($s, $($tt)*)))
};
}

Expand All @@ -67,7 +67,7 @@ macro_rules! hprintln {
#[macro_export]
macro_rules! heprint {
($s:expr) => {
$crate::export::hstderr_str($s)
$crate::export::hstderr_fmt(format_args!($s))
};
($($tt:tt)*) => {
$crate::export::hstderr_fmt(format_args!($($tt)*))
Expand All @@ -84,10 +84,10 @@ macro_rules! heprintln {
$crate::export::hstderr_str("\n")
};
($s:expr) => {
$crate::export::hstderr_str(concat!($s, "\n"))
$crate::export::hstderr_fmt(format_args!("{}\n", format_args!($s)))
};
($s:expr, $($tt:tt)*) => {
$crate::export::hstderr_fmt(format_args!(concat!($s, "\n"), $($tt)*))
$crate::export::hstderr_fmt(format_args!("{}\n", format_args!($s, $($tt)*)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the double nested format_args! required here? Was there some use case that didn't work with the previous method of using concat!?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, sorry I meant to take a note of it - format_args! doesn't expand captures in the format string literal if it is generated by a macro:

Playground link

From rust-lang/rust#106824, it should get flattened into a single format_args!/Arguments call.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yikes - thanks for the clarification.

};
}

Expand Down