From e6f82cf2bbf36f0a5f491444eb064f0a3d25a83e Mon Sep 17 00:00:00 2001 From: Takatoshi Kondo Date: Fri, 13 May 2016 18:51:53 +0900 Subject: [PATCH] Fixed #463. Added lacked include files. Added a test. Added MSVC build settings on appveyor. Added old MSVC workaround. Fixed a variable definition point to meet ANSI-C. --- appveyor.yml | 44 ++++++++++++------- erb/v1/cpp03_define_map.hpp.erb | 2 + example/c/lib_buffer_unpack.c | 5 ++- .../msgpack/v1/adaptor/adaptor_base_decl.hpp | 1 + .../v1/adaptor/boost/msgpack_variant.hpp | 41 ++++++++++------- .../v1/adaptor/detail/cpp03_define_map.hpp | 2 + include/msgpack/v1/adaptor/int.hpp | 2 + test/CMakeLists.txt | 1 + test/Makefile.am | 2 + test/inc_adaptor_define.cpp | 3 ++ test/msgpack_basic.cpp | 8 ++++ test/msgpack_c.cpp | 4 ++ 12 files changed, 82 insertions(+), 33 deletions(-) create mode 100644 test/inc_adaptor_define.cpp diff --git a/appveyor.yml b/appveyor.yml index c74798d7..10a3a665 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,11 +1,35 @@ version: 1.1.0.{build} -before_build: + +environment: + matrix: + - cpp11: -DMSGPACK_CXX11=OFF + boost: -DMSGPACK_BOOST=ON + msvc: '"Visual Studio 10 2010"' + - cpp11: -DMSGPACK_CXX11=OFF + boost: -DMSGPACK_BOOST=ON + msvc: '"Visual Studio 11 2012"' + - cpp11: -DMSGPACK_CXX11=OFF + boost: -DMSGPACK_BOOST=ON + msvc: '"Visual Studio 12 2013"' + - cpp11: -DMSGPACK_CXX11=ON + boost: -DMSGPACK_BOOST=ON + msvc: '"Visual Studio 14 2015"' + - cpp11: -DMSGPACK_CXX11=OFF + boost: -DMSGPACK_BOOST=ON + msvc: '"Visual Studio 14 2015"' + - cpp11: -DMSGPACK_CXX11=ON + boost: -DMSGPACK_BOOST=OFF + msvc: '"Visual Studio 14 2015"' + - cpp11: -DMSGPACK_CXX11=OFF + boost: -DMSGPACK_BOOST=OFF + msvc: '"Visual Studio 14 2015"' +build_script: - appveyor DownloadFile http://googletest.googlecode.com/files/gtest-1.7.0.zip -FileName gtest-1.7.0.zip - 7z x gtest-1.7.0.zip > NUL - cd gtest-1.7.0 - md build - cd build -- cmake -DBUILD_SHARED_LIBS=ON .. +- cmake -G %msvc% -DBUILD_SHARED_LIBS=ON -DCMAKE_CXX_FLAGS=/D_VARIADIC_MAX=10 .. - cmake --build . --config Release - cd .. - cd .. @@ -15,26 +39,14 @@ before_build: - cd zlib-1.2.8 - md build - cd build -- cmake .. +- cmake -G %msvc% .. - cmake --build . --config Release - copy zconf.h .. - cd .. - cd .. - -environment: - matrix: - - cpp11: -DMSGPACK_CXX11=ON - boost: -DMSGPACK_BOOST=ON - - cpp11: -DMSGPACK_CXX11=OFF - boost: -DMSGPACK_BOOST=ON - - cpp11: -DMSGPACK_CXX11=ON - boost: -DMSGPACK_BOOST=OFF - - cpp11: -DMSGPACK_CXX11=OFF - boost: -DMSGPACK_BOOST=OFF -build_script: - md build - cd build -- cmake %cpp11% %boost% -DMSGPACK_BOOST_DIR=C:\Libraries\\boost_1_58_0 -DGTEST_LIBRARY=%APPVEYOR_BUILD_FOLDER%\gtest-1.7.0\build\Release\gtest.lib -DGTEST_MAIN_LIBRARY=%APPVEYOR_BUILD_FOLDER%\gtest-1.7.0\build\Release\gtest_main.lib -DGTEST_INCLUDE_DIR=%APPVEYOR_BUILD_FOLDER%\gtest-1.7.0\include -DZLIB_LIBRARY=%APPVEYOR_BUILD_FOLDER%\zlib-1.2.8\build\Release\zlib.lib -DZLIB_INCLUDE_DIR=%APPVEYOR_BUILD_FOLDER%\zlib-1.2.8 .. +- cmake -G %msvc% %cpp11% %boost% -DMSGPACK_BOOST_DIR=C:\Libraries\\boost_1_60_0 -DGTEST_LIBRARY=%APPVEYOR_BUILD_FOLDER%\gtest-1.7.0\build\Release\gtest.lib -DGTEST_MAIN_LIBRARY=%APPVEYOR_BUILD_FOLDER%\gtest-1.7.0\build\Release\gtest_main.lib -DGTEST_INCLUDE_DIR=%APPVEYOR_BUILD_FOLDER%\gtest-1.7.0\include -DZLIB_LIBRARY=%APPVEYOR_BUILD_FOLDER%\zlib-1.2.8\build\Release\zlib.lib -DZLIB_INCLUDE_DIR=%APPVEYOR_BUILD_FOLDER%\zlib-1.2.8 -DCMAKE_CXX_FLAGS='"/D_VARIADIC_MAX=10 /EHsc"' .. - cmake --build . --config Release test_script: diff --git a/erb/v1/cpp03_define_map.hpp.erb b/erb/v1/cpp03_define_map.hpp.erb index b00c028a..9becd940 100644 --- a/erb/v1/cpp03_define_map.hpp.erb +++ b/erb/v1/cpp03_define_map.hpp.erb @@ -15,6 +15,8 @@ #include "msgpack/adaptor/adaptor_base.hpp" #include "msgpack/object_fwd.hpp" +#include + namespace msgpack { /// @cond MSGPACK_API_VERSION_NAMESPACE(v1) { diff --git a/example/c/lib_buffer_unpack.c b/example/c/lib_buffer_unpack.c index 8abce921..4a4c6a6b 100644 --- a/example/c/lib_buffer_unpack.c +++ b/example/c/lib_buffer_unpack.c @@ -44,13 +44,14 @@ size_t receiver_recv(receiver *r, char* buf, size_t try_size) { size_t receiver_to_unpacker(receiver* r, size_t request_size, msgpack_unpacker *unpacker) { + size_t recv_len; // make sure there's enough room, or expand the unpacker accordingly if (msgpack_unpacker_buffer_capacity(unpacker) < request_size) { msgpack_unpacker_reserve_buffer(unpacker, request_size); assert(msgpack_unpacker_buffer_capacity(unpacker) >= request_size); } - size_t recv_len = receiver_recv(r, msgpack_unpacker_buffer(unpacker), - request_size); + recv_len = receiver_recv(r, msgpack_unpacker_buffer(unpacker), + request_size); msgpack_unpacker_buffer_consumed(unpacker, recv_len); return recv_len; } diff --git a/include/msgpack/v1/adaptor/adaptor_base_decl.hpp b/include/msgpack/v1/adaptor/adaptor_base_decl.hpp index 13bef574..62203d08 100644 --- a/include/msgpack/v1/adaptor/adaptor_base_decl.hpp +++ b/include/msgpack/v1/adaptor/adaptor_base_decl.hpp @@ -12,6 +12,7 @@ #include "msgpack/versioning.hpp" #include "msgpack/object_fwd.hpp" +#include "msgpack/pack.hpp" namespace msgpack { diff --git a/include/msgpack/v1/adaptor/boost/msgpack_variant.hpp b/include/msgpack/v1/adaptor/boost/msgpack_variant.hpp index f662583e..e1d86346 100644 --- a/include/msgpack/v1/adaptor/boost/msgpack_variant.hpp +++ b/include/msgpack/v1/adaptor/boost/msgpack_variant.hpp @@ -82,6 +82,17 @@ struct basic_variant : basic_variant() {} template basic_variant(T const& t):base(t) {} + +#if defined(_MSC_VER) && _MSC_VER < 1700 + // The following redundant functions are required to avoid MSVC + // See https://svn.boost.org/trac/boost/ticket/592 + basic_variant(basic_variant const& other):base(static_cast(other)) {} + basic_variant& operator=(basic_variant const& other) { + *static_cast(this) = static_cast(other); + return *this; + } +#endif // defined(_MSC_VER) && _MSC_VER < 1700 + basic_variant(char const* p):base(std::string(p)) {} basic_variant(char v) { int_init(v); @@ -104,51 +115,51 @@ struct basic_variant : basic_variant(unsigned long long v):base(uint64_t(v)) {} bool is_nil() const { - return boost::get(this); + return boost::get(this) != nullptr; } bool is_bool() const { - return boost::get(this); + return boost::get(this) != nullptr; } bool is_int64_t() const { - return boost::get(this); + return boost::get(this) != nullptr; } bool is_uint64_t() const { - return boost::get(this); + return boost::get(this) != nullptr; } bool is_double() const { - return boost::get(this); + return boost::get(this) != nullptr; } bool is_string() const { - return boost::get(this); + return boost::get(this) != nullptr; } #if (BOOST_VERSION / 100000) >= 1 && ((BOOST_VERSION / 100) % 1000) >= 53 bool is_boost_string_ref() const { - return boost::get(this); + return boost::get(this) != nullptr; } #endif // (BOOST_VERSION / 100000) >= 1 && ((BOOST_VERSION / 100) % 1000) >= 53 bool is_vector_char() const { - return boost::get >(this); + return boost::get >(this) != nullptr; } bool is_vector_char() { - return boost::get >(this); + return boost::get >(this) != nullptr; } bool is_raw_ref() const { - return boost::get(this); + return boost::get(this) != nullptr; } bool is_ext() const { - return boost::get(this); + return boost::get(this) != nullptr; } bool is_ext_ref() const { - return boost::get(this); + return boost::get(this) != nullptr; } bool is_vector() const { - return boost::get > >(this); + return boost::get > >(this) != nullptr; } bool is_map() const { - return boost::get, basic_variant > >(this); + return boost::get, basic_variant > >(this) != nullptr; } bool is_multimap() const { - return boost::get, basic_variant > >(this); + return boost::get, basic_variant > >(this) != nullptr; } bool as_bool() const { diff --git a/include/msgpack/v1/adaptor/detail/cpp03_define_map.hpp b/include/msgpack/v1/adaptor/detail/cpp03_define_map.hpp index 279d5a3a..071ac565 100644 --- a/include/msgpack/v1/adaptor/detail/cpp03_define_map.hpp +++ b/include/msgpack/v1/adaptor/detail/cpp03_define_map.hpp @@ -15,6 +15,8 @@ #include "msgpack/adaptor/adaptor_base.hpp" #include "msgpack/object_fwd.hpp" +#include + namespace msgpack { /// @cond MSGPACK_API_VERSION_NAMESPACE(v1) { diff --git a/include/msgpack/v1/adaptor/int.hpp b/include/msgpack/v1/adaptor/int.hpp index 1a1dd4d6..45d90586 100644 --- a/include/msgpack/v1/adaptor/int.hpp +++ b/include/msgpack/v1/adaptor/int.hpp @@ -11,6 +11,8 @@ #define MSGPACK_V1_TYPE_INT_HPP #include "msgpack/v1/adaptor/int_decl.hpp" +#include "msgpack/object.hpp" + #include namespace msgpack { diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 5dfbbe44..edf4f2ef 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -14,6 +14,7 @@ LIST (APPEND check_PROGRAMS convert.cpp fixint.cpp fixint_c.cpp + inc_adaptor_define.cpp json.cpp limit.cpp msgpack_basic.cpp diff --git a/test/Makefile.am b/test/Makefile.am index 5f451d02..f6cf8280 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -9,6 +9,7 @@ check_PROGRAMS = \ convert \ fixint \ fixint_c \ + inc_adaptor_define \ json \ limit \ msgpack_basic \ @@ -54,6 +55,7 @@ cases_SOURCES = cases.cpp convert_SOURCES = convert.cpp fixint_SOURCES = fixint.cpp fixint_c_SOURCES = fixint_c.cpp +inc_adaptor_define_SOURCES = inc_adaptor_define.cpp json_SOURCES = json.cpp limit_SOURCES = limit.cpp msgpack_basic_SOURCES = msgpack_basic.cpp diff --git a/test/inc_adaptor_define.cpp b/test/inc_adaptor_define.cpp new file mode 100644 index 00000000..e55b0bd7 --- /dev/null +++ b/test/inc_adaptor_define.cpp @@ -0,0 +1,3 @@ +#include + +int main() {} diff --git a/test/msgpack_basic.cpp b/test/msgpack_basic.cpp index dad92cab..a50f7944 100644 --- a/test/msgpack_basic.cpp +++ b/test/msgpack_basic.cpp @@ -143,6 +143,8 @@ TEST(MSGPACK, simple_buffer_int64) GEN_TEST(int64_t); } +#if !defined(_MSC_VER) || _MSC_VER >=1800 + TEST(MSGPACK, simple_buffer_float) { vector v; @@ -185,6 +187,8 @@ TEST(MSGPACK, simple_buffer_float) } } +#endif // !defined(_MSC_VER) || _MSC_VER >=1800 + namespace { template struct TypePair { @@ -232,6 +236,8 @@ INSTANTIATE_TYPED_TEST_CASE_P(IntegerToFloatingPointTestInstance, IntegerToFloatingPointTest, IntegerToFloatingPointTestTypes); +#if !defined(_MSC_VER) || _MSC_VER >=1800 + TEST(MSGPACK, simple_buffer_double) { vector v; @@ -278,6 +284,8 @@ TEST(MSGPACK, simple_buffer_double) } } +#endif // !defined(_MSC_VER) || _MSC_VER >=1800 + TEST(MSGPACK, simple_buffer_nil) { msgpack::sbuffer sbuf; diff --git a/test/msgpack_c.cpp b/test/msgpack_c.cpp index 65595fe1..6eb05254 100644 --- a/test/msgpack_c.cpp +++ b/test/msgpack_c.cpp @@ -185,6 +185,8 @@ TEST(MSGPACKC, simple_buffer_int64) GEN_TEST_SIGNED(int64_t, int64); } +#if !defined(_MSC_VER) || _MSC_VER >=1800 + TEST(MSGPACKC, simple_buffer_float) { vector v; @@ -315,6 +317,8 @@ TEST(MSGPACKC, simple_buffer_double) } } +#endif // !defined(_MSC_VER) || _MSC_VER >=1800 + TEST(MSGPACKC, simple_buffer_nil) { msgpack_sbuffer sbuf;