Skip to content

Commit

Permalink
message! fixed, too.
Browse files Browse the repository at this point in the history
  • Loading branch information
den-mentiei committed Jan 17, 2024
1 parent fcd4cd3 commit d4f5d31
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 15 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
### Removed

## [0.0.5] - 2024-01-17

### Fixed

- `message!` behaviour with `enabled` is now correct, too.

## [0.0.4] - 2024-01-17

### Changed
Expand Down Expand Up @@ -51,3 +57,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
[0.0.2]: https://github.com/den-mentiei/tracy-gizmos/releases/tag/v0.0.1..v0.0.2
[0.0.3]: https://github.com/den-mentiei/tracy-gizmos/releases/tag/v0.0.2..v0.0.3
[0.0.4]: https://github.com/den-mentiei/tracy-gizmos/releases/tag/v0.0.3..v0.0.4
[0.0.5]: https://github.com/den-mentiei/tracy-gizmos/releases/tag/v0.0.4..v0.0.5
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "tracy-gizmos"
version = "0.0.4"
version = "0.0.5"
authors = ["Denys Mentiei <[email protected]>"]
description = "Bindings for the client library of the Tracy profiler"
repository = "https://github.com/den-mentiei/tracy-gizmos"
Expand Down
1 change: 1 addition & 0 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# TODO

- [ ] add examples in a workspace with a separate cargo to test better
- [ ] callstacks! depth is at most 62
- [ ] auto-function proc-macro attributes:
- [ ] #[zone]
Expand Down
51 changes: 37 additions & 14 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,30 +210,25 @@ macro_rules! set_thread_name {
/// message!(Color::GREEN, "{} is good!", file_path);
/// ```
#[macro_export]
#[cfg(any(doc, feature = "enabled"))]
macro_rules! message {
($text:literal) => {
#[cfg(feature = "enabled")]
// SAFETY: We null-terminate the string.
unsafe {
$crate::details::message(concat!($text, '\0').as_ptr());
}
};

($text:expr) => {
#[cfg(feature = "enabled")]
$crate::details::message_size($text);
};

($format:literal, $($args:expr),*) => {
#[cfg(feature = "enabled")]
{
let _text = format!($format, $($args),*);
$crate::details::message_size(&_text);
}
let _text = format!($format, $($args),*);
$crate::details::message_size(&_text);
};

($color:expr, $text:literal) => {
#[cfg(feature = "enabled")]
// SAFETY: We null-terminate the string.
unsafe {
$crate::details::message_color(
Expand All @@ -244,19 +239,47 @@ macro_rules! message {
};

($color:expr, $text:expr) => {
#[cfg(feature = "enabled")]
$crate::details::message_size_color(
$text,
$color,
);
};

($color:expr, $format:literal, $($args:expr),*) => {
#[cfg(feature = "enabled")]
{
let _text = format!($format, $($args),*);
$crate::details::message_size_color(&_text, $color);
}
let _text = format!($format, $($args),*);
$crate::details::message_size_color(&_text, $color);
};
}

#[macro_export]
#[cfg(all(not(doc), not(feature = "enabled")))]
macro_rules! message {
($text:literal) => {};

($whatever:expr $(, $text:literal)?) => {
// Silences unused expression warning.
_ = $whatever;
};

($format:literal, $($args:expr),*) => {
// Silence unused expression warnings.
$(
_ = $args;
)*
};

($color:expr, $text:expr) => {
// Silence unused expression warnings.
_ = $color;
_ = $text;
};

($color:expr, $format:literal, $($args:expr),*) => {
// Silence unused expression warnings.
_ = $color;
$(
_ = $args;
)*
};
}

Expand Down

0 comments on commit d4f5d31

Please sign in to comment.