-
Notifications
You must be signed in to change notification settings - Fork 446
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
[Code health] Perform cppcheck cleanup #3150
Changes from all commits
9375819
b89fbde
558560e
67ed142
e8e1b85
d79e186
207c3e3
9305c6c
7e1e9ca
f706996
f1b18df
86ddede
e9b2252
6c062f8
48099c2
869f157
21e6d74
f22a295
4f2c120
d8151b3
4a75894
6c6925b
fabee6a
72fba18
3e01c95
e745948
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,16 +29,14 @@ class Context | |
// hold a shared_ptr to the head of the DataList linked list | ||
template <class T> | ||
Context(const T &keys_and_values) noexcept | ||
{ | ||
head_ = nostd::shared_ptr<DataList>{new DataList(keys_and_values)}; | ||
} | ||
: head_{nostd::shared_ptr<DataList>{new DataList(keys_and_values)}} | ||
{} | ||
Comment on lines
+32
to
+33
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Approved as ABI safe, implementation change only. |
||
|
||
// Creates a context object from a key and value, this will | ||
// hold a shared_ptr to the head of the DataList linked list | ||
Context(nostd::string_view key, ContextValue value) noexcept | ||
{ | ||
head_ = nostd::shared_ptr<DataList>{new DataList(key, value)}; | ||
} | ||
: head_{nostd::shared_ptr<DataList>{new DataList(key, value)}} | ||
{} | ||
Comment on lines
+38
to
+39
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Approved as ABI safe, implementation change only. |
||
|
||
// Accepts a new iterable and then returns a new context that | ||
// contains the new key and value data. It attaches the | ||
|
@@ -92,22 +90,21 @@ class Context | |
|
||
private: | ||
// A linked list to contain the keys and values of this context node | ||
class DataList | ||
struct DataList | ||
{ | ||
public: | ||
char *key_; | ||
char *key_ = nullptr; | ||
|
||
nostd::shared_ptr<DataList> next_; | ||
nostd::shared_ptr<DataList> next_{nullptr}; | ||
|
||
size_t key_length_; | ||
size_t key_length_ = 0UL; | ||
|
||
ContextValue value_; | ||
|
||
DataList() { next_ = nullptr; } | ||
DataList() = default; | ||
|
||
// Builds a data list off of a key and value iterable and returns the head | ||
template <class T> | ||
DataList(const T &keys_and_vals) : key_{nullptr}, next_(nostd::shared_ptr<DataList>{nullptr}) | ||
DataList(const T &keys_and_vals) | ||
{ | ||
bool first = true; | ||
auto *node = this; | ||
|
@@ -132,9 +129,18 @@ class Context | |
{ | ||
key_ = new char[key.size()]; | ||
key_length_ = key.size(); | ||
memcpy(key_, key.data(), key.size() * sizeof(char)); | ||
value_ = value; | ||
std::memcpy(key_, key.data(), key.size() * sizeof(char)); | ||
next_ = nostd::shared_ptr<DataList>{nullptr}; | ||
value_ = value; | ||
} | ||
|
||
DataList(const DataList &other) | ||
marcalff marked this conversation as resolved.
Show resolved
Hide resolved
|
||
: key_(new char[other.key_length_]), | ||
next_(other.next_), | ||
key_length_(other.key_length_), | ||
value_(other.value_) | ||
{ | ||
std::memcpy(key_, other.key_, other.key_length_ * sizeof(char)); | ||
} | ||
|
||
DataList &operator=(DataList &&other) noexcept | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,7 +32,7 @@ class OPENTELEMETRY_EXPORT GlobalTextMapPropagator | |
return nostd::shared_ptr<TextMapPropagator>(GetPropagator()); | ||
} | ||
|
||
static void SetGlobalPropagator(nostd::shared_ptr<TextMapPropagator> prop) noexcept | ||
static void SetGlobalPropagator(const nostd::shared_ptr<TextMapPropagator> &prop) noexcept | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Helper inlined. |
||
{ | ||
std::lock_guard<common::SpinLockMutex> guard(GetLock()); | ||
GetPropagator() = prop; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -152,7 +152,8 @@ class OPENTELEMETRY_EXPORT RuntimeContext | |
* | ||
* @param storage a custom runtime context storage | ||
*/ | ||
static void SetRuntimeContextStorage(nostd::shared_ptr<RuntimeContextStorage> storage) noexcept | ||
static void SetRuntimeContextStorage( | ||
const nostd::shared_ptr<RuntimeContextStorage> &storage) noexcept | ||
Comment on lines
+155
to
+156
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Helper inlined. |
||
{ | ||
GetStorage() = storage; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,9 +19,9 @@ namespace logs | |
class EventId | ||
{ | ||
public: | ||
EventId(int64_t id, nostd::string_view name) noexcept : id_{id} | ||
EventId(int64_t id, nostd::string_view name) noexcept | ||
: id_{id}, name_{nostd::unique_ptr<char[]>{new char[name.length() + 1]}} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ABI safe, internal implementation change. |
||
{ | ||
name_ = nostd::unique_ptr<char[]>{new char[name.length() + 1]}; | ||
std::copy(name.begin(), name.end(), name_.get()); | ||
name_.get()[name.length()] = 0; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,7 +39,7 @@ class OPENTELEMETRY_EXPORT Provider | |
/** | ||
* Changes the singleton LoggerProvider. | ||
*/ | ||
static void SetLoggerProvider(nostd::shared_ptr<LoggerProvider> tp) noexcept | ||
static void SetLoggerProvider(const nostd::shared_ptr<LoggerProvider> &tp) noexcept | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Helper inlined. |
||
{ | ||
std::lock_guard<common::SpinLockMutex> guard(GetLock()); | ||
GetProvider() = tp; | ||
|
@@ -60,7 +60,7 @@ class OPENTELEMETRY_EXPORT Provider | |
/** | ||
* Changes the singleton EventLoggerProvider. | ||
*/ | ||
static void SetEventLoggerProvider(nostd::shared_ptr<EventLoggerProvider> tp) noexcept | ||
static void SetEventLoggerProvider(const nostd::shared_ptr<EventLoggerProvider> &tp) noexcept | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Helper inlined. |
||
{ | ||
std::lock_guard<common::SpinLockMutex> guard(GetLock()); | ||
GetEventProvider() = tp; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,7 +38,7 @@ class Provider | |
/** | ||
* Changes the singleton MeterProvider. | ||
*/ | ||
static void SetMeterProvider(nostd::shared_ptr<MeterProvider> tp) noexcept | ||
static void SetMeterProvider(const nostd::shared_ptr<MeterProvider> &tp) noexcept | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Helper inlined. |
||
{ | ||
std::lock_guard<common::SpinLockMutex> guard(GetLock()); | ||
GetProvider() = tp; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,7 @@ class DynamicLibraryHandle; | |
class Span final : public trace::Span | ||
{ | ||
public: | ||
Span(std::shared_ptr<trace::Tracer> &&tracer, nostd::shared_ptr<trace::Span> span) noexcept | ||
Span(std::shared_ptr<trace::Tracer> &&tracer, const nostd::shared_ptr<trace::Span> &span) noexcept | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here changing the span constructor does not change the object layout or virtual table, should be ok. This plugin class in particular is not inherited from in the SDK, changing the constructor is ok. Approved as ABI safe. Beside, plugin/tracer.h is not used as far as I know. |
||
: tracer_{std::move(tracer)}, span_{span} | ||
{} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,7 +34,8 @@ inline bool IsRootSpan(const context::Context &context) noexcept | |
} | ||
|
||
// Set Span into explicit context | ||
inline context::Context SetSpan(context::Context &context, nostd::shared_ptr<Span> span) noexcept | ||
inline context::Context SetSpan(context::Context &context, | ||
const nostd::shared_ptr<Span> &span) noexcept | ||
Comment on lines
+37
to
+38
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Helper inlined. |
||
{ | ||
return context.SetValue(kSpanKey, span); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Providing details because this is not trivial, as justification, for all reviewers:
Hence:
Approved, this is safe IMO.