Skip to content

Commit

Permalink
Fix Visual Studio build
Browse files Browse the repository at this point in the history
  • Loading branch information
ruslo committed Apr 17, 2018
1 parent 46db687 commit 445225f
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 22 deletions.
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
4 changes: 3 additions & 1 deletion src/google/protobuf/io/zero_copy_stream_impl_lite.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
#include <google/protobuf/stubs/common.h>
#include <google/protobuf/stubs/stl_util-inl.h>

#include <algorithm> // std::min

namespace google {
namespace protobuf {
namespace io {
Expand Down Expand Up @@ -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_;
Expand Down
4 changes: 3 additions & 1 deletion src/google/protobuf/repeated_field.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
#include <google/protobuf/stubs/common.h>
#include <google/protobuf/message_lite.h>

#include <algorithm> // std::max

namespace google {

namespace protobuf {
Expand Down Expand Up @@ -600,7 +602,7 @@ void RepeatedField<Element>::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_) {
Expand Down
3 changes: 2 additions & 1 deletion src/google/protobuf/wire_format_lite_inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#include <google/protobuf/generated_message_util.h>
#include <google/protobuf/io/coded_stream.h>

#include <algorithm> // std::min

namespace google {
namespace protobuf {
Expand Down Expand Up @@ -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 &&
Expand Down
38 changes: 19 additions & 19 deletions vsprojects/config.h
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
/* protobuf config.h for MSVC. On other platforms, this is generated
* automatically by autoheader / autoconf / configure. */

/* the location of <hash_map> */
#define HASH_MAP_H <unordered_map>
#if defined(_MSC_VER)
# define HASH_MAP_H <hash_map>
#else
# define HASH_MAP_H <unordered_map>
#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 <hash_set> */
#define HASH_SET_H <unordered_set>
#if defined(_MSC_VER)
# define HASH_SET_H <hash_set>
#else
# define HASH_SET_H <unordered_set>
#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. */
Expand Down

0 comments on commit 445225f

Please sign in to comment.