This is an automated email from the ASF dual-hosted git repository.
leander pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/brpc.git
The following commit(s) were added to refs/heads/master by this push:
new d5ea0068 Refactor: Use static_cast for safer downcasting in brpc::Span
(#3075)
d5ea0068 is described below
commit d5ea0068eb154086f7d3489f37484c718445ff44
Author: none <[email protected]>
AuthorDate: Thu Aug 28 13:24:11 2025 +0800
Refactor: Use static_cast for safer downcasting in brpc::Span (#3075)
---
src/brpc/span.cpp | 10 ++++++----
src/brpc/span.h | 4 ++--
2 files changed, 8 insertions(+), 6 deletions(-)
diff --git a/src/brpc/span.cpp b/src/brpc/span.cpp
index cee13576..8e9af46c 100644
--- a/src/brpc/span.cpp
+++ b/src/brpc/span.cpp
@@ -130,7 +130,7 @@ Span* Span::CreateClientSpan(const std::string&
full_method_name,
span->_tls_next = NULL;
span->_full_method_name = full_method_name;
span->_info.clear();
- Span* parent = (Span*)bthread::tls_bls.rpcz_parent_span;
+ Span* parent = static_cast<Span*>(bthread::tls_bls.rpcz_parent_span);
if (parent) {
span->_trace_id = parent->trace_id();
span->_parent_span_id = parent->span_id();
@@ -148,7 +148,7 @@ Span* Span::CreateClientSpan(const std::string&
full_method_name,
Span* Span::CreateBthreadSpan(const std::string& full_method_name,
int64_t base_real_us) {
- Span* parent = (Span*)bthread::tls_bls.rpcz_parent_span;
+ Span* parent = static_cast<Span*>(bthread::tls_bls.rpcz_parent_span);
if (parent == NULL) {
return NULL;
}
@@ -349,7 +349,7 @@ bool CanAnnotateSpan() {
}
void AnnotateSpan(const char* fmt, ...) {
- Span* span = (Span*)bthread::tls_bls.rpcz_parent_span;
+ Span* span = static_cast<Span*>(bthread::tls_bls.rpcz_parent_span);
va_list ap;
va_start(ap, fmt);
span->Annotate(fmt, ap);
@@ -406,7 +406,9 @@ static bvar::DisplaySamplingRatio s_display_sampling_ratio(
struct SpanEarlier {
bool operator()(bvar::Collected* c1, bvar::Collected* c2) const {
- return ((Span*)c1)->GetStartRealTimeUs() <
((Span*)c2)->GetStartRealTimeUs();
+ const Span* span1 = static_cast<const Span*>(c1);
+ const Span* span2 = static_cast<const Span*>(c2);
+ return span1->GetStartRealTimeUs() < span2->GetStartRealTimeUs();
}
};
class SpanPreprocessor : public bvar::CollectorPreprocessor {
diff --git a/src/brpc/span.h b/src/brpc/span.h
index 1ef3d03c..75d8e7fc 100644
--- a/src/brpc/span.h
+++ b/src/brpc/span.h
@@ -117,7 +117,7 @@ public:
Span* local_parent() const { return _local_parent; }
static Span* tls_parent() {
- return (Span*)bthread::tls_bls.rpcz_parent_span;
+ return static_cast<Span*>(bthread::tls_bls.rpcz_parent_span);
}
uint64_t trace_id() const { return _trace_id; }
@@ -151,7 +151,7 @@ private:
bvar::CollectorPreprocessor* preprocessor();
void EndAsParent() {
- if (this == (Span*)bthread::tls_bls.rpcz_parent_span) {
+ if (this == static_cast<Span*>(bthread::tls_bls.rpcz_parent_span)) {
bthread::tls_bls.rpcz_parent_span = NULL;
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]