Skip to content
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

(Breaking Changes) Re-implement tracing wrapper in a safer way, replacing the use of &str with &[u8]. #1071

Merged
merged 2 commits into from
Jan 4, 2025

Conversation

vcfxb
Copy link
Contributor

@vcfxb vcfxb commented Jul 22, 2024

This changes the type signature of TracingCb to use a &[u8] over an &str, leaving the conversion to the consumer as planned. This is a breaking change and will require a new release.

Internally, this replaces the use of a static AtomicUsize to store the tracing subscriber with a AtomicPtr. This is still unsafe, but lets us avoid the integer to pointer transmutation that was previously happening which is more explicitly a possible violation of Rust's memory model. Now all the casts and transmutations in tracing.rs are between pointer types, which is (relatively) safer.

vcfxb added 2 commits July 22, 2024 15:26
…moke test, update tracing callback to use `&[u8]` instead of `&str`.
// Test that using the above function to set a tracing callback doesn't panic.
#[test]
fn smoke() {
super::trace_set(TraceLevel::Trace, |level, msg| {
Copy link
Contributor

Choose a reason for hiding this comment

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

Just noting that since this is a global, we can't really have multiple tests for this. And this is registering a trace function that triggers for all tests running after this. That might be ok, but something we'll need to be careful of.

Copy link
Contributor

@ehuss ehuss left a comment

Choose a reason for hiding this comment

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

Thanks for the detailed comments!

@ehuss ehuss added this pull request to the merge queue Jan 4, 2025
Merged via the queue into rust-lang:master with commit 8977c0c Jan 4, 2025
7 checks passed
@vcfxb vcfxb deleted the fix-tracing-ub branch January 5, 2025 06:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants