Skip to content

Commit

Permalink
Patches to enable Visual Studio 2015 - Update 2 support (#565)
Browse files Browse the repository at this point in the history
  • Loading branch information
maxgolov authored Feb 10, 2021
1 parent 25a7178 commit 18e8d9f
Show file tree
Hide file tree
Showing 20 changed files with 6,151 additions and 12 deletions.
2 changes: 1 addition & 1 deletion api/include/opentelemetry/context/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ class Context

// Builds a data list with just a key and value, so it will just be the head
// and returns that head.
DataList(nostd::string_view key, ContextValue value)
DataList(nostd::string_view key, const ContextValue &value)
{
key_ = new char[key.size()];
key_length_ = key.size();
Expand Down
23 changes: 15 additions & 8 deletions api/include/opentelemetry/context/runtime_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Token

// A constructor that sets the token's Context object to the
// one that was passed in.
Token(Context context) : context_(context) {}
Token(const Context &context) : context_(context) {}

const Context context_;
};
Expand All @@ -49,7 +49,7 @@ class RuntimeContextStorage
* @param the new current context
* @return a token for the new current context. This never returns a nullptr.
*/
virtual nostd::unique_ptr<Token> Attach(Context context) noexcept = 0;
virtual nostd::unique_ptr<Token> Attach(const Context &context) noexcept = 0;

/**
* Detach the context related to the given token.
Expand All @@ -59,7 +59,7 @@ class RuntimeContextStorage
virtual bool Detach(Token &token) noexcept = 0;

protected:
nostd::unique_ptr<Token> CreateToken(Context context) noexcept
nostd::unique_ptr<Token> CreateToken(const Context &context) noexcept
{
return nostd::unique_ptr<Token>(new Token(context));
}
Expand All @@ -82,7 +82,7 @@ class RuntimeContext

// Sets the current 'Context' object. Returns a token
// that can be used to reset to the previous Context.
static nostd::unique_ptr<Token> Attach(Context context) noexcept
static nostd::unique_ptr<Token> Attach(const Context &context) noexcept
{
return GetRuntimeContextStorage()->Attach(context);
}
Expand All @@ -98,7 +98,7 @@ class RuntimeContext
// mind that the current RuntimeContext will not be changed, and the new
// context will be returned.
static Context SetValue(nostd::string_view key,
ContextValue value,
const ContextValue &value,
Context *context = nullptr) noexcept
{
Context temp_context;
Expand Down Expand Up @@ -204,7 +204,7 @@ class ThreadLocalContextStorage : public RuntimeContextStorage

// Sets the current 'Context' object. Returns a token
// that can be used to reset to the previous Context.
nostd::unique_ptr<Token> Attach(Context context) noexcept override
nostd::unique_ptr<Token> Attach(const Context &context) noexcept override
{
GetStack().Push(context);
return CreateToken(context);
Expand Down Expand Up @@ -254,7 +254,7 @@ class ThreadLocalContextStorage : public RuntimeContextStorage

// Pushes the passed in context pointer to the top of the stack
// and resizes if necessary.
void Push(Context context) noexcept
void Push(const Context &context) noexcept
{
size_++;
if (size_ > capacity_)
Expand All @@ -275,7 +275,14 @@ class ThreadLocalContextStorage : public RuntimeContextStorage
Context *temp = new Context[new_capacity];
if (base_ != nullptr)
{
std::copy(base_, base_ + old_size, temp);
// vs2015 does not like this construct considering it unsafe:
// - std::copy(base_, base_ + old_size, temp);
// Ref.
// https://stackoverflow.com/questions/12270224/xutility2227-warning-c4996-std-copy-impl
for (size_t i = 0; i < (std::min)(old_size, new_capacity); i++)
{
temp[i] = base_[i];
}
delete[] base_;
}
base_ = temp;
Expand Down
3 changes: 3 additions & 0 deletions api/include/opentelemetry/nostd/absl/.clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Disable formatting for Google Abseil library snapshot
DisableFormat: true
SortIncludes: false
9 changes: 9 additions & 0 deletions api/include/opentelemetry/nostd/absl/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Notes on Abseil Variant implementation

This is a snapshot of Abseil Variant `absl::variant` from Abseil `v2020-03-03#8`.

This code is required to compile OpenTelemetry code in vs2015 because MPark Variant implementation is not compatible with vs2015.

Build option `HAVE_ABSEIL_VARIANT` allows to enable the build with `absl::variant`, `absl::get` and `absl::visit` as defalt implementation for `nostd::` classes.

Going forward it makes sense to use `absl::variant` as default implementation for Windows OS and vs2015, vs2017, vs2019 and newer compilers.
Loading

0 comments on commit 18e8d9f

Please sign in to comment.