Compare commits

...

20 Commits

Author SHA1 Message Date
Nobuyuki Kubota
2a349cf418 Merge pull request #337 from redboltz/fix_55
Fixed #55
2015-08-10 11:44:46 -07:00
Takatoshi Kondo
1bac5a2c00 Fixed #55 2015-08-08 09:54:46 +09:00
Nobuyuki Kubota
bf4a57da34 Merge branch 'object-with-zone-copy' 2014-10-06 14:07:06 -07:00
Nobuyuki Kubota
2fcbe6116d Replace C-style casts with C++-style ones 2014-10-06 14:06:21 -07:00
Takatoshi Kondo
0176dd760a Merge pull request #131 from shafik/master
Fixing undefined behavior introduced by the incorrect use of comma
2014-09-20 17:39:44 +09:00
Jakob Petsovits
d30548af3f Add support for copying an object to an object::with_zone.
With test.
2014-09-20 00:13:40 -04:00
Jakob Petsovits
ab12b2b2b9 Specialize operator<<(packer, T) also for object::with_zone.
It already existed for T = object, but if trying to pass an
object::with_zone it would match the generic operator<<() instead.
That operator calls o.msgpack_pack(), which doesn't exist and
causes a compile error.

(Re-)Using the overload for object is a better way to handle this.
2014-09-19 22:48:24 -04:00
Takatoshi Kondo
7ce69a362f Merge pull request #130 from jpetso/master
Support std::unordered_map/set even if using libstdc++ from GCC.
2014-09-20 00:06:51 +09:00
Takatoshi Kondo
cc08146b1c Merge pull request #132 from redboltz/support_travis_ci
Added travis-ci support.
2014-09-19 23:57:40 +09:00
Takatoshi Kondo
6896cc602f Added travis-ci support. 2014-09-19 23:42:07 +09:00
Shafik Yaghmour
d8f366daf2 Fixing undefined behavior introduced by the incorrect use of comma operator with the conditional operator. The middle expression in a conditional operator between the ? and : is implicitly parenthesized but the end expression is not. Since the comma operator as he lowest precendence( http://en.cppreference.com/w/cpp/language/operator_precedence) this means the conditional operator will be evaluated first and then the expression on the right hand side of the comma operator will be evaluated. This leads to undefined behavior because the last member of the union being updated will not be the member that will be used next which is strictly undefined in C++ although gcc and clang aloow this type punning as an extension but is clearly not portable behavior nor was this the intended behavior. instead of parenthesising the end expression I choose to use an if/else which is not subject to such easy to miss precdence issues. This Coliru live code demonstrates the bug with simple example: http://coliru.stacked-crooked.com/a/1041aaa8380feeaa the code also demonstrates the using the right warning flags gcc will generate a warning for this code. 2014-09-18 14:29:11 -04:00
Jakob Petsovits
ef649009e4 Support std::unordered_map/set even if using libstdc++ from GCC.
When passing the appropriate compiler flags, libstdc++ has
supported std::unordered_map and std::unordered_set for a
long time, even without the tr1 namespace. There's no reason to
limit support of non-tr1 containers to libc++ (clang) and MSVC.
2014-09-17 16:52:33 -04:00
Takatoshi Kondo
847a7852e5 Merge branch 'jpetso-master' 2014-09-10 10:59:49 +09:00
Jakob Petsovits
e265beef91 Install version.h even if doing an out-of-source build. 2014-09-09 16:21:38 -04:00
Takatoshi Kondo
dc679a2572 Merge pull request #119 from davidchappelle/master
Amendment to cmake changes for out of source builds
2014-09-09 06:21:38 +09:00
David Chappelle
b6bc7f7ecb Merge remote-tracking branch 'upstream/master'
Conflicts:
	CMakeLists.txt
2014-09-08 15:57:43 -04:00
Jason Newton
501260eb54 correct paths for x86_64/generic installations 2014-09-08 22:27:38 +09:00
David Chappelle
8615358515 Fixed out of source cmake builds to work correctly.
The out of source cmake build was not working correctly. In particular,
the main CMakeLists.txt was not installing from the correct location.
In the case of msgpack.pc, it was trying to install from the top repo
directory instead of from the cmake build directory. So you can now
build as follows:

    $ cd msgpack-c
    $ mkdir build
    $ cd build
    $ cmake ../
    $ make
    $ make install
2014-09-05 19:22:04 +00:00
Nobuyuki Kubota
dd083ca933 Merge pull request #95 from ueno/int-float-test
Fix test failure regarding int->float conversion
2014-07-30 21:25:42 -07:00
Daiki Ueno
c203928fae Fix test failure regarding int->float conversion
Supply only small integers (< 1^23) to int->float conversion tests,
so they can roundtrip without error.
2014-07-17 18:51:59 +09:00
13 changed files with 372 additions and 32 deletions

25
.travis.yml Normal file
View File

@@ -0,0 +1,25 @@
language: cpp
cache:
- apt
compiler:
- clang
- gcc
before_install:
# We need this line to have g++4.8 available in apt
- sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
- sudo apt-get update -qq
- sudo apt-get update
- sudo apt-get install valgrind
- sudo apt-get install libgtest-dev
- "cd /usr/src/gtest && sudo cmake . && sudo cmake --build . && sudo mv libg* /usr/local/lib/ ; cd -"
install:
- sudo apt-get install -qq gcc-4.8 g++-4.8
# We want to compile with g++ 4.8 when rather than the default g++
- sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.8 90
env:
- ACTION="ci/build_autotools.sh" PARAM="cpp03"
- ACTION="ci/build_cmake.sh" PARAM="cpp03"
script:
- git clean -xdf && ${ACTION} ${PARAM}

View File

@@ -155,10 +155,15 @@ IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
ENDIF ()
ENDIF ()
INSTALL (TARGETS msgpack msgpack-static DESTINATION lib)
IF (NOT DEFINED CMAKE_INSTALL_LIBDIR)
SET(CMAKE_INSTALL_LIBDIR lib)
ENDIF ()
INSTALL (TARGETS msgpack msgpack-static DESTINATION ${CMAKE_INSTALL_LIBDIR})
INSTALL (DIRECTORY src/msgpack DESTINATION include)
INSTALL (DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/src/msgpack DESTINATION include)
INSTALL (FILES src/msgpack.h src/msgpack.hpp DESTINATION include)
INSTALL (FILES msgpack.pc DESTINATION lib/pkgconfig)
INSTALL (FILES ${CMAKE_CURRENT_BINARY_DIR}/msgpack.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
# Doxygen
FIND_PACKAGE (Doxygen)

View File

@@ -19,6 +19,8 @@ The source for msgpack-c is held at [msgpack-c](https://github.com/msgpack/msgpa
To report an issue, use the [msgpack-c issue tracker](https://github.com/msgpack/msgpack-c/issues) at github.com.
## Version
0.5.9 [![Build Status](https://travis-ci.org/msgpack/msgpack-c.svg?branch=master)](https://travis-ci.org/msgpack/msgpack-c)
## Using Msgpack
@@ -96,7 +98,7 @@ Clone msgpack-c git repository.
$ git clone https://github.com/msgpack/msgpack-c.git
```
or using GUI git client.
or using GUI git client.
e.g.) tortoise git https://code.google.com/p/tortoisegit/

47
ci/build_autotools.sh Executable file
View File

@@ -0,0 +1,47 @@
#!/bin/sh
./bootstrap
ret=$?
if [ $ret -ne 0 ]
then
exit $ret
fi
if [ $1 = "cpp11" ]
then
./configure CXXFLAGS="-std=c++11"
else
./configure
fi
ret=$?
if [ $ret -ne 0 ]
then
exit $ret
fi
make
ret=$?
if [ $ret -ne 0 ]
then
exit $ret
fi
make check
ret=$?
if [ $ret -ne 0 ]
then
exit $ret
fi
make install DESTDIR=`pwd`/install
ret=$?
if [ $ret -ne 0 ]
then
exit $ret
fi
exit 0

56
ci/build_cmake.sh Executable file
View File

@@ -0,0 +1,56 @@
#!/bin/sh
mkdir build
ret=$?
if [ $ret -ne 0 ]
then
exit $ret
fi
cd build
ret=$?
if [ $ret -ne 0 ]
then
exit $ret
fi
if [ $1 = "cpp11" ]
then
cmake -DMSGPACK_CXX11=ON ..
else
cmake ..
fi
ret=$?
if [ $ret -ne 0 ]
then
exit $ret
fi
make
ret=$?
if [ $ret -ne 0 ]
then
exit $ret
fi
make test
ret=$?
if [ $ret -ne 0 ]
then
exit $ret
fi
make install DESTDIR=`pwd`/install
ret=$?
if [ $ret -ne 0 ]
then
exit $ret
fi
exit 0

View File

@@ -1,4 +1,3 @@
lib_LTLIBRARIES = libmsgpack.la
libmsgpack_la_SOURCES = \
@@ -42,6 +41,7 @@ nobase_include_HEADERS = \
msgpack/unpack_define.h \
msgpack/unpack_template.h \
msgpack/sysdep.h \
gcc_atomic.h \
msgpack.h \
msgpack/sbuffer.h \
msgpack/version.h \
@@ -106,4 +106,3 @@ doxygen_cpp:
doxygen Doxyfile_cpp
doxygen: doxygen_c doxygen_cpp

View File

@@ -234,6 +234,59 @@ void operator<< (object::with_zone& o, const T& v)
v.msgpack_object(static_cast<object*>(&o), o.zone);
}
template <>
inline void operator<< (object::with_zone& o, const object& v)
{
o.type = v.type;
switch(v.type) {
case type::NIL:
case type::BOOLEAN:
case type::POSITIVE_INTEGER:
case type::NEGATIVE_INTEGER:
case type::DOUBLE:
::memcpy(&o.via, &v.via, sizeof(v.via));
return;
case type::RAW:
o.via.raw.ptr = static_cast<const char*>(o.zone->malloc(v.via.raw.size));
o.via.raw.size = v.via.raw.size;
::memcpy(const_cast<char*>(o.via.raw.ptr), v.via.raw.ptr, v.via.raw.size);
return;
case type::ARRAY:
o.via.array.ptr = static_cast<object*>(o.zone->malloc(sizeof(object) * v.via.array.size));
o.via.array.size = v.via.array.size;
for(object* po(o.via.array.ptr), * pv(v.via.array.ptr),
* const pvend(v.via.array.ptr + v.via.array.size);
pv < pvend; ++po, ++pv) {
new (po) object(*pv, o.zone);
}
return;
case type::MAP:
o.via.map.ptr = static_cast<object_kv*>(o.zone->malloc(sizeof(object_kv) * v.via.map.size));
o.via.map.size = v.via.map.size;
for(object_kv* po(o.via.map.ptr), * pv(v.via.map.ptr),
* const pvend(v.via.map.ptr + v.via.map.size);
pv < pvend; ++po, ++pv) {
object_kv* kv = new (po) object_kv;
new (&kv->key) object(pv->key, o.zone);
new (&kv->val) object(pv->val, o.zone);
}
return;
default:
throw type_error();
}
}
template <>
inline void operator<< (object::with_zone& o, const object::with_zone& v)
{
return o << static_cast<object>(v);
}
inline bool operator==(const object x, const object y)
{
@@ -412,6 +465,12 @@ packer<Stream>& operator<< (packer<Stream>& o, const object& v)
}
}
template <typename Stream>
packer<Stream>& operator<< (packer<Stream>& o, const object::with_zone& v)
{
return o << static_cast<object>(v);
}
} // namespace msgpack

View File

@@ -115,16 +115,61 @@ inline packer<Stream>& operator<< (packer<Stream>& o, const type::fix_uint64& v)
inline void operator<< (object& o, type::fix_int8 v)
{ v.get() < 0 ? o.type = type::NEGATIVE_INTEGER, o.via.i64 = v.get() : o.type = type::POSITIVE_INTEGER, o.via.u64 = v.get(); }
{
if ( v.get() < 0 )
{
o.type = type::NEGATIVE_INTEGER ;
o.via.i64 = v.get() ;
}
else
{
o.type = type::POSITIVE_INTEGER ;
o.via.u64 = v.get() ;
}
}
inline void operator<< (object& o, type::fix_int16 v)
{ v.get() < 0 ? o.type = type::NEGATIVE_INTEGER, o.via.i64 = v.get() : o.type = type::POSITIVE_INTEGER, o.via.u64 = v.get(); }
{
if ( v.get() < 0 )
{
o.type = type::NEGATIVE_INTEGER ;
o.via.i64 = v.get() ;
}
else
{
o.type = type::POSITIVE_INTEGER ;
o.via.u64 = v.get() ;
}
}
inline void operator<< (object& o, type::fix_int32 v)
{ v.get() < 0 ? o.type = type::NEGATIVE_INTEGER, o.via.i64 = v.get() : o.type = type::POSITIVE_INTEGER, o.via.u64 = v.get(); }
{
if ( v.get() < 0 )
{
o.type = type::NEGATIVE_INTEGER ;
o.via.i64 = v.get() ;
}
else
{
o.type = type::POSITIVE_INTEGER ;
o.via.u64 = v.get() ;
}
}
inline void operator<< (object& o, type::fix_int64 v)
{ v.get() < 0 ? o.type = type::NEGATIVE_INTEGER, o.via.i64 = v.get() : o.type = type::POSITIVE_INTEGER, o.via.u64 = v.get(); }
{
if( v.get() < 0 )
{
o.type = type::NEGATIVE_INTEGER ;
o.via.i64 = v.get() ;
}
else
{
o.type = type::POSITIVE_INTEGER ;
o.via.u64 = v.get() ;
}
}
inline void operator<< (object& o, type::fix_uint8 v)

View File

@@ -98,8 +98,16 @@ namespace detail {
template <>
struct object_char_sign<true> {
static inline void make(object& o, char v) {
v < 0 ? o.type = type::NEGATIVE_INTEGER, o.via.i64 = v
: o.type = type::POSITIVE_INTEGER, o.via.u64 = v;
if( v < 0 )
{
o.type = type::NEGATIVE_INTEGER ;
o.via.i64 = v ;
}
else
{
o.type = type::POSITIVE_INTEGER ;
o.via.u64 = v ;
}
}
};
@@ -203,19 +211,74 @@ inline void operator<< (object& o, char v)
inline void operator<< (object& o, signed char v)
{ v < 0 ? o.type = type::NEGATIVE_INTEGER, o.via.i64 = v : o.type = type::POSITIVE_INTEGER, o.via.u64 = v; }
{
if( v < 0 )
{
o.type = type::NEGATIVE_INTEGER ;
o.via.i64 = v;
}
else
{
o.type = type::POSITIVE_INTEGER ;
o.via.u64 = v ;
}
}
inline void operator<< (object& o, signed short v)
{ v < 0 ? o.type = type::NEGATIVE_INTEGER, o.via.i64 = v : o.type = type::POSITIVE_INTEGER, o.via.u64 = v; }
{
if(v < 0 )
{
o.type = type::NEGATIVE_INTEGER ;
o.via.i64 = v ;
}
else
{
o.type = type::POSITIVE_INTEGER ;
o.via.u64 = v;
}
}
inline void operator<< (object& o, signed int v)
{ v < 0 ? o.type = type::NEGATIVE_INTEGER, o.via.i64 = v : o.type = type::POSITIVE_INTEGER, o.via.u64 = v; }
{
if( v < 0 )
{
o.type = type::NEGATIVE_INTEGER ;
o.via.i64 = v ;
}
else
{
o.type = type::POSITIVE_INTEGER ;
o.via.u64 = v ;
}
}
inline void operator<< (object& o, signed long v)
{ v < 0 ? o.type = type::NEGATIVE_INTEGER, o.via.i64 = v : o.type = type::POSITIVE_INTEGER, o.via.u64 = v; }
{
if( v < 0 )
{
o.type = type::NEGATIVE_INTEGER ;
o.via.i64 = v ;
}
else
{
o.type = type::POSITIVE_INTEGER ;
o.via.u64 = v ;
}
}
inline void operator<< (object& o, signed long long v)
{ v < 0 ? o.type = type::NEGATIVE_INTEGER, o.via.i64 = v : o.type = type::POSITIVE_INTEGER, o.via.u64 = v; }
{
if( v < 0 )
{
o.type = type::NEGATIVE_INTEGER ;
o.via.i64 = v ;
}
else
{
o.type = type::POSITIVE_INTEGER ;
o.via.u64 = v ;
}
}
inline void operator<< (object& o, unsigned char v)

View File

@@ -20,13 +20,16 @@
#include "msgpack/object.hpp"
#if defined(_LIBCPP_VERSION) || (_MSC_VER >= 1700)
#define LIBSTDCXX_HAS_STD_UNORDERED_MAP defined(__GLIBCXX__) && __GLIBCXX__ >= 20090421 \
&& (__cplusplus >= 201103L || __GXX_EXPERIMENTAL_CXX0X__)
#if LIBSTDCXX_HAS_STD_UNORDERED_MAP || defined(_LIBCPP_VERSION) || (_MSC_VER >= 1700)
#define MSGPACK_HAS_STD_UNOURDERED_MAP
#include <unordered_map>
#define MSGPACK_STD_TR1 std
#else // defined(_LIBCPP_VERSION) || (_MSC_VER >= 1700)
#else // LIBSTDCXX_HAS_STD_UNORDERED_MAP || defined(_LIBCPP_VERSION) || (_MSC_VER >= 1700)
#if __GNUC__ >= 4
@@ -37,8 +40,7 @@
#endif // __GNUC__ >= 4
#endif // defined(_LIBCPP_VERSION) || (_MSC_VER >= 1700)
#endif // LIBSTDCXX_HAS_STD_UNORDERED_MAP || defined(_LIBCPP_VERSION) || (_MSC_VER >= 1700)
namespace msgpack {

View File

@@ -20,13 +20,16 @@
#include "msgpack/object.hpp"
#if defined(_LIBCPP_VERSION) || (_MSC_VER >= 1700)
#define LIBSTDCXX_HAS_STD_UNORDERED_SET defined(__GLIBCXX__) && __GLIBCXX__ >= 20090421 \
&& (__cplusplus >= 201103L || __GXX_EXPERIMENTAL_CXX0X__)
#if LIBSTDCXX_HAS_STD_UNORDERED_SET || defined(_LIBCPP_VERSION) || (_MSC_VER >= 1700)
#define MSGPACK_HAS_STD_UNOURDERED_SET
#include <unordered_set>
#define MSGPACK_STD_TR1 std
#else // defined(_LIBCPP_VERSION) || (_MSC_VER >= 1700)
#else // LIBSTDCXX_HAS_STD_UNORDERED_SET || defined(_LIBCPP_VERSION) || (_MSC_VER >= 1700)
#if __GNUC__ >= 4
@@ -37,7 +40,7 @@
#endif // __GNUC__ >= 4
#endif // defined(_LIBCPP_VERSION) || (_MSC_VER >= 1700)
#endif // LIBSTDCXX_HAS_STD_UNORDERED_SET || defined(_LIBCPP_VERSION) || (_MSC_VER >= 1700)
namespace msgpack {

View File

@@ -201,10 +201,8 @@ TYPED_TEST_P(IntegerToFloatingPointTest, simple_buffer)
v.push_back(1);
if (numeric_limits<integer_type>::is_signed) v.push_back(-1);
else v.push_back(2);
v.push_back(numeric_limits<integer_type>::min());
v.push_back(numeric_limits<integer_type>::max());
for (unsigned int i = 0; i < kLoop; i++) {
v.push_back(rand());
v.push_back(rand() % 0x7FFFFF);
}
for (unsigned int i = 0; i < v.size() ; i++) {
msgpack::sbuffer sbuf;

View File

@@ -1,22 +1,27 @@
#include <msgpack.hpp>
#include <msgpack/type.hpp>
#include <vector>
#include <map>
#include <gtest/gtest.h>
struct myclass {
myclass() : num(0), str("default") { }
myclass(int num, const std::string& str) :
num(0), str("default") { }
myclass(int n, const std::string& s) :
num(n), str(s) { }
~myclass() { }
int num;
std::string str;
std::vector<double> vec;
std::map<std::string, std::string> map;
MSGPACK_DEFINE(num, str);
MSGPACK_DEFINE(num, str, vec, map);
bool operator==(const myclass& o) const
{
return num == o.num && str == o.str;
return num == o.num && str == o.str && vec == o.vec && map == o.map;
}
};
@@ -28,7 +33,7 @@ std::ostream& operator<<(std::ostream& o, const myclass& m)
TEST(object, convert)
{
myclass m1;
myclass m1(1, "custom");
msgpack::sbuffer sbuf;
msgpack::pack(sbuf, m1);
@@ -49,7 +54,7 @@ TEST(object, convert)
TEST(object, as)
{
myclass m1;
myclass m1(1, "custom");
msgpack::sbuffer sbuf;
msgpack::pack(sbuf, m1);
@@ -65,6 +70,37 @@ TEST(object, as)
}
TEST(object, cross_zone_copy)
{
myclass m1(1, "custom");
m1.vec.push_back(1.0);
m1.vec.push_back(0.1);
m1.map["one"] = "two";
msgpack::zone z1;
msgpack::object::with_zone obj1(&z1);
{
msgpack::zone z2;
msgpack::object::with_zone obj2(&z2);
obj2 << m1;
obj1 << obj2;
EXPECT_EQ(obj1.via.array.ptr[2].via.array.ptr[0].via.dec, 1.0);
EXPECT_EQ(obj1.via.array.ptr[3].via.map.ptr[0].val.via.raw.ptr[0], 't');
EXPECT_NE(
obj1.via.array.ptr[2].via.array.ptr,
obj2.via.array.ptr[2].via.array.ptr);
EXPECT_NE(
obj1.via.array.ptr[3].via.map.ptr[0].val.via.raw.ptr,
obj2.via.array.ptr[3].via.map.ptr[0].val.via.raw.ptr);
}
EXPECT_EQ(m1, obj1.as<myclass>());
}
TEST(object, print)
{
msgpack::object obj;