From 445225f11df75bed742a1b979c6d833c9252e002 Mon Sep 17 00:00:00 2001 From: Ruslan Baratov Date: Tue, 17 Apr 2018 22:06:39 +0300 Subject: [PATCH] Fix Visual Studio build --- CMakeLists.txt | 4 ++ .../protobuf/io/zero_copy_stream_impl_lite.cc | 4 +- src/google/protobuf/repeated_field.h | 4 +- src/google/protobuf/wire_format_lite_inl.h | 3 +- vsprojects/config.h | 38 +++++++++---------- 5 files changed, 31 insertions(+), 22 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 67a76259b7840..b0753544a7fa3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,4 +11,8 @@ project(protobuf C CXX) hunter_add_package(ZLIB) +if(MSVC) + add_definitions(-D_SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS) +endif() + add_subdirectory(cmake) diff --git a/src/google/protobuf/io/zero_copy_stream_impl_lite.cc b/src/google/protobuf/io/zero_copy_stream_impl_lite.cc index e80125109fca4..7ac0d107c9a54 100644 --- a/src/google/protobuf/io/zero_copy_stream_impl_lite.cc +++ b/src/google/protobuf/io/zero_copy_stream_impl_lite.cc @@ -36,6 +36,8 @@ #include #include +#include // std::min + namespace google { namespace protobuf { namespace io { @@ -63,7 +65,7 @@ ArrayInputStream::~ArrayInputStream() { bool ArrayInputStream::Next(const void** data, int* size) { if (position_ < size_) { - last_returned_size_ = min(block_size_, size_ - position_); + last_returned_size_ = std::min(block_size_, size_ - position_); *data = data_ + position_; *size = last_returned_size_; position_ += last_returned_size_; diff --git a/src/google/protobuf/repeated_field.h b/src/google/protobuf/repeated_field.h index 6080ddccce320..87a51102d8072 100644 --- a/src/google/protobuf/repeated_field.h +++ b/src/google/protobuf/repeated_field.h @@ -51,6 +51,8 @@ #include #include +#include // std::max + namespace google { namespace protobuf { @@ -600,7 +602,7 @@ void RepeatedField::Reserve(int new_size) { if (total_size_ >= new_size) return; Element* old_elements = elements_; - total_size_ = max(total_size_ * 2, new_size); + total_size_ = std::max(total_size_ * 2, new_size); elements_ = new Element[total_size_]; MoveArray(elements_, old_elements, current_size_); if (old_elements != initial_space_) { diff --git a/src/google/protobuf/wire_format_lite_inl.h b/src/google/protobuf/wire_format_lite_inl.h index 103b0bd0ca682..c49285051861f 100644 --- a/src/google/protobuf/wire_format_lite_inl.h +++ b/src/google/protobuf/wire_format_lite_inl.h @@ -44,6 +44,7 @@ #include #include +#include // std::min namespace google { namespace protobuf { @@ -267,7 +268,7 @@ inline bool WireFormatLite::ReadRepeatedFixedSizePrimitive( // The number of bytes each type occupies on the wire. const int per_value_size = tag_size + sizeof(value); - int elements_available = min(values->Capacity() - values->size(), + int elements_available = std::min(values->Capacity() - values->size(), size / per_value_size); int num_read = 0; while (num_read < elements_available && diff --git a/vsprojects/config.h b/vsprojects/config.h index fd49120a01914..9bec14692ba83 100644 --- a/vsprojects/config.h +++ b/vsprojects/config.h @@ -1,31 +1,31 @@ -/* protobuf config.h for MSVC. On other platforms, this is generated - * automatically by autoheader / autoconf / configure. */ - -/* the location of */ -#define HASH_MAP_H +#if defined(_MSC_VER) +# define HASH_MAP_H +#else +# define HASH_MAP_H +#endif -/* the namespace of hash_map/hash_set */ -// Apparently Microsoft decided to move hash_map *back* to the std namespace -// in MSVC 2010: -// http://blogs.msdn.com/vcblog/archive/2009/05/25/stl-breaking-changes-in-visual-studio-2010-beta-1.aspx -// TODO(kenton): Use unordered_map instead, which is available in MSVC 2010. -#if _MSC_VER < 1310 || _MSC_VER >= 1600 -#define HASH_NAMESPACE std +#if defined(_MSC_VER) +# define HASH_NAMESPACE stdext #else -#define HASH_NAMESPACE std +# define HASH_NAMESPACE std #endif -/* the location of */ -#define HASH_SET_H +#if defined(_MSC_VER) +# define HASH_SET_H +#else +# define HASH_SET_H +#endif /* define if the compiler has hash_map */ -#define HAVE_HASH_MAP 1 +#define HAVE_HASH_MAP /* define if the compiler has hash_set */ -#define HAVE_HASH_SET 1 +#define HAVE_HASH_SET -#define HASH_MAP_CLASS unordered_map -#define HASH_SET_CLASS unordered_set +#if !defined(_MSC_VER) +# define HASH_MAP_CLASS unordered_map +# define HASH_SET_CLASS unordered_set +#endif /* define if you want to use zlib. See readme.txt for additional * requirements. */