Merge branch 'fix_issue_226_author_fixed'

Conflicts:
	include/msgpack/unpack.hpp
This commit is contained in:
Nobuyuki Kubota 2015-03-10 17:21:58 +09:00
commit c1e9f92d7f
22 changed files with 283 additions and 150 deletions

View File

@ -102,6 +102,7 @@ IF (MSGPACK_ENABLE_CXX)
include/msgpack/adaptor/bool_fwd.hpp
include/msgpack/adaptor/char_ptr.hpp
include/msgpack/adaptor/char_ptr_fwd.hpp
include/msgpack/adaptor/check_container_size.hpp
include/msgpack/adaptor/cpp11/array.hpp
include/msgpack/adaptor/cpp11/array_fwd.hpp
include/msgpack/adaptor/cpp11/array_char.hpp

View File

@ -1,7 +1,7 @@
//
// MessagePack for C++ static resolution routine
//
// Copyright (C) 2014 KONDO Takatoshi
// Copyright (C) 2014-2015 KONDO Takatoshi
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@ -20,6 +20,8 @@
#include "msgpack/versioning.hpp"
#include "msgpack/object_fwd.hpp"
#include "msgpack/adaptor/check_container_size.hpp"
#include <cstring>
namespace msgpack {
@ -29,7 +31,7 @@ MSGPACK_API_VERSION_NAMESPACE(v1) {
template <typename Stream>
inline packer<Stream>& operator<< (packer<Stream>& o, const char* v)
{
std::size_t size = std::strlen(v);
uint32_t size = checked_get_container_size(std::strlen(v));
o.pack_str(size);
o.pack_str_body(v, size);
return o;
@ -37,20 +39,20 @@ inline packer<Stream>& operator<< (packer<Stream>& o, const char* v)
inline void operator<< (object::with_zone& o, const char* v)
{
std::size_t size = std::strlen(v);
uint32_t size = checked_get_container_size(std::strlen(v));
o.type = type::STR;
char* ptr = static_cast<char*>(o.zone.allocate_align(size));
o.via.str.ptr = ptr;
o.via.str.size = static_cast<uint32_t>(size);
o.via.str.size = size;
memcpy(ptr, v, size);
}
inline void operator<< (object& o, const char* v)
{
std::size_t size = std::strlen(v);
uint32_t size = checked_get_container_size(std::strlen(v));
o.type = type::STR;
o.via.str.ptr = v;
o.via.str.size = static_cast<uint32_t>(size);
o.via.str.size = size;
}
template <typename Stream>

View File

@ -0,0 +1,61 @@
//
// MessagePack for C++ static resolution routine
//
// Copyright (C) 2015 KONDO Takatoshi
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#ifndef MSGPACK_CHECK_CONTAINER_SIZE_HPP
#define MSGPACK_CHECK_CONTAINER_SIZE_HPP
#include "msgpack/versioning.hpp"
#include <stdexcept>
namespace msgpack {
MSGPACK_API_VERSION_NAMESPACE(v1) {
struct container_size_overflow : public std::runtime_error {
explicit container_size_overflow(const std::string& msg)
:std::runtime_error(msg) {}
#if !defined(MSGPACK_USE_CPP03)
explicit container_size_overflow(const char* msg):
std::runtime_error(msg) {}
#endif // !defined(MSGPACK_USE_CPP03)
};
namespace detail {
template <std::size_t N>
inline void check_container_size(std::size_t size) {
if (size > 0xffffffff) throw container_size_overflow("container size overflow");
}
template <>
inline void check_container_size<4>(std::size_t size) {
}
} // namespace detail
template <typename T>
inline uint32_t checked_get_container_size(T size) {
detail::check_container_size<sizeof(T)>(size);
return static_cast<uint32_t>(size);
}
} // MSGPACK_API_VERSION_NAMESPACE(v1)
} // namespace msgpack
#endif // MSGPACK_CHECK_CONTAINER_SIZE_HPP

View File

@ -1,7 +1,7 @@
//
// MessagePack for C++ static resolution routine
//
// Copyright (C) 2014 KONDO Takatoshi
// Copyright (C) 2014-2015 KONDO Takatoshi
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@ -21,6 +21,7 @@
#include "msgpack/versioning.hpp"
#include "msgpack/object_fwd.hpp"
#include "msgpack/adaptor/check_container_size.hpp"
#include <array>
@ -47,7 +48,8 @@ inline object const& operator>> (object const& o, std::array<T, N>& v) {
template <typename Stream, typename T, std::size_t N>
inline packer<Stream>& operator<< (packer<Stream>& o, const std::array<T, N>& v) {
o.pack_array(v.size());
uint32_t size = checked_get_container_size(v.size());
o.pack_array(size);
for(auto const& e : v) o.pack(e);
return o;
}
@ -59,8 +61,9 @@ inline void operator<< (object::with_zone& o, const std::array<T, N>& v) {
o.via.array.ptr = nullptr;
o.via.array.size = 0;
} else {
object* p = static_cast<object*>(o.zone.allocate_align(sizeof(object)*v.size()));
o.via.array.size = v.size();
uint32_t size = checked_get_container_size(v.size());
object* p = static_cast<object*>(o.zone.allocate_align(sizeof(object)*size));
o.via.array.size = size;
o.via.array.ptr = p;
for (auto const& e : v) *p++ = object(e, o.zone);
}

View File

@ -1,7 +1,7 @@
//
// MessagePack for C++ static resolution routine
//
// Copyright (C) 2014 KONDO Takatoshi
// Copyright (C) 2014-2015 KONDO Takatoshi
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@ -20,6 +20,8 @@
#include "msgpack/versioning.hpp"
#include "msgpack_fwd.hpp"
#include "msgpack/adaptor/check_container_size.hpp"
#include <array>
namespace msgpack {
@ -48,8 +50,9 @@ inline object const& operator>> (object const& o, std::array<char, N>& v)
template <typename Stream, std::size_t N>
inline packer<Stream>& operator<< (packer<Stream>& o, const std::array<char, N>& v)
{
o.pack_bin(v.size());
o.pack_bin_body(v.data(), v.size());
uint32_t size = checked_get_container_size(v.size());
o.pack_bin(size);
o.pack_bin_body(v.data(), size);
return o;
}
@ -57,19 +60,21 @@ inline packer<Stream>& operator<< (packer<Stream>& o, const std::array<char, N>&
template <std::size_t N>
inline void operator<< (object& o, const std::array<char, N>& v)
{
uint32_t size = checked_get_container_size(v.size());
o.type = type::BIN;
o.via.bin.ptr = v.data();
o.via.bin.size = static_cast<uint32_t>(v.size());
o.via.bin.size = size;
}
template <std::size_t N>
inline void operator<< (object::with_zone& o, const std::array<char, N>& v)
{
uint32_t size = checked_get_container_size(v.size());
o.type = type::BIN;
char* ptr = static_cast<char*>(o.zone.allocate_align(v.size()));
char* ptr = static_cast<char*>(o.zone.allocate_align(size));
o.via.bin.ptr = ptr;
o.via.bin.size = static_cast<uint32_t>(v.size());
std::memcpy(ptr, v.data(), v.size());
o.via.bin.size = size;
std::memcpy(ptr, v.data(), size);
}
} // MSGPACK_API_VERSION_NAMESPACE(v1)

View File

@ -1,7 +1,7 @@
//
// MessagePack for C++ static resolution routine
//
// Copyright (C) 2014 KONDO Takatoshi
// Copyright (C) 2014 KONDO-2015 Takatoshi
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@ -21,6 +21,7 @@
#include "msgpack/versioning.hpp"
#include "msgpack/object_fwd.hpp"
#include "msgpack/adaptor/check_container_size.hpp"
#include <forward_list>
@ -44,7 +45,8 @@ inline object const& operator>> (object const& o, std::forward_list<T>& v)
template <typename Stream, typename T>
inline packer<Stream>& operator<< (packer<Stream>& o, const std::forward_list<T>& v)
{
o.pack_array(std::distance(v.begin(), v.end()));
uint32_t size = checked_get_container_size(std::distance(v.begin(), v.end()));
o.pack_array(size);
for(auto const& e : v) o.pack(e);
return o;
}
@ -57,7 +59,7 @@ inline void operator<< (object::with_zone& o, const std::forward_list<T>& v)
o.via.array.ptr = nullptr;
o.via.array.size = 0;
} else {
std::size_t size = std::distance(v.begin(), v.end());
uint32_t size = checked_get_container_size(std::distance(v.begin(), v.end()));
o.via.array.size = size;
object* p = static_cast<object*>(
o.zone.allocate_align(sizeof(object)*size));

View File

@ -1,7 +1,7 @@
//
// MessagePack for C++ static resolution routine
//
// Copyright (C) 2008-2014 FURUHASHI Sadayuki and KONDO Takatoshi
// Copyright (C) 2008-2015 FURUHASHI Sadayuki and KONDO Takatoshi
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@ -20,6 +20,7 @@
#include "msgpack/versioning.hpp"
#include "msgpack/object_fwd.hpp"
#include "msgpack/adaptor/check_container_size.hpp"
#include <tuple>
@ -60,7 +61,8 @@ template <typename Stream, typename... Args>
inline const packer<Stream>& operator<< (
packer<Stream>& o,
const std::tuple<Args...>& v) {
o.pack_array(sizeof...(Args));
uint32_t size = checked_get_container_size(sizeof...(Args));
o.pack_array(size);
StdTuplePacker<Stream, decltype(v), sizeof...(Args)>::pack(o, v);
return o;
}
@ -136,9 +138,10 @@ template <typename... Args>
inline void operator<< (
object::with_zone& o,
std::tuple<Args...> const& v) {
uint32_t size = checked_get_container_size(sizeof...(Args));
o.type = type::ARRAY;
o.via.array.ptr = static_cast<object*>(o.zone.allocate_align(sizeof(object)*sizeof...(Args)));
o.via.array.size = sizeof...(Args);
o.via.array.ptr = static_cast<object*>(o.zone.allocate_align(sizeof(object)*size));
o.via.array.size = size;
StdTupleToObjectWithZone<decltype(v), sizeof...(Args)>::convert(o, v);
}

View File

@ -1,7 +1,7 @@
//
// MessagePack for C++ static resolution routine
//
// Copyright (C) 2014 KONDO Takatoshi
// Copyright (C) 2014-2015 KONDO Takatoshi
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@ -20,6 +20,7 @@
#include "msgpack/versioning.hpp"
#include "msgpack/object_fwd.hpp"
#include "msgpack/adaptor/check_container_size.hpp"
#include <unordered_map>
@ -46,9 +47,10 @@ inline object const& operator>> (object const& o, std::unordered_map<K, V>& v)
template <typename Stream, typename K, typename V>
inline packer<Stream>& operator<< (packer<Stream>& o, const std::unordered_map<K,V>& v)
{
o.pack_map(v.size());
uint32_t size = checked_get_container_size(v.size());
o.pack_map(size);
for(typename std::unordered_map<K,V>::const_iterator it(v.begin()), it_end(v.end());
it != it_end; ++it) {
it != it_end; ++it) {
o.pack(it->first);
o.pack(it->second);
}
@ -63,10 +65,11 @@ inline void operator<< (object::with_zone& o, const std::unordered_map<K,V>& v)
o.via.map.ptr = nullptr;
o.via.map.size = 0;
} else {
object_kv* p = static_cast<object_kv*>(o.zone.allocate_align(sizeof(object_kv)*v.size()));
object_kv* const pend = p + v.size();
uint32_t size = checked_get_container_size(v.size());
object_kv* p = static_cast<object_kv*>(o.zone.allocate_align(sizeof(object_kv)*size));
object_kv* const pend = p + size;
o.via.map.ptr = p;
o.via.map.size = v.size();
o.via.map.size = size;
typename std::unordered_map<K,V>::const_iterator it(v.begin());
do {
p->key = object(it->first, o.zone);
@ -98,9 +101,10 @@ inline object const& operator>> (object const& o, std::unordered_multimap<K, V>&
template <typename Stream, typename K, typename V>
inline packer<Stream>& operator<< (packer<Stream>& o, const std::unordered_multimap<K,V>& v)
{
o.pack_map(v.size());
uint32_t size = checked_get_container_size(v.size());
o.pack_map(size);
for(typename std::unordered_multimap<K,V>::const_iterator it(v.begin()), it_end(v.end());
it != it_end; ++it) {
it != it_end; ++it) {
o.pack(it->first);
o.pack(it->second);
}
@ -115,10 +119,11 @@ inline void operator<< (object::with_zone& o, const std::unordered_multimap<K,V>
o.via.map.ptr = nullptr;
o.via.map.size = 0;
} else {
object_kv* p = static_cast<object_kv*>(o.zone.allocate_align(sizeof(object_kv)*v.size()));
object_kv* const pend = p + v.size();
uint32_t size = checked_get_container_size(v.size());
object_kv* p = static_cast<object_kv*>(o.zone.allocate_align(sizeof(object_kv)*size));
object_kv* const pend = p + size;
o.via.map.ptr = p;
o.via.map.size = v.size();
o.via.map.size = size;
typename std::unordered_multimap<K,V>::const_iterator it(v.begin());
do {
p->key = object(it->first, o.zone);

View File

@ -1,7 +1,7 @@
//
// MessagePack for C++ static resolution routine
//
// Copyright (C) 2014 KONDO Takatoshi
// Copyright (C) 2014-2015 KONDO Takatoshi
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@ -20,6 +20,7 @@
#include "msgpack/versioning.hpp"
#include "msgpack/object_fwd.hpp"
#include "msgpack/adaptor/check_container_size.hpp"
#include <unordered_set>
@ -45,9 +46,10 @@ inline object const& operator>> (object const& o, std::unordered_set<T>& v)
template <typename Stream, typename T>
inline packer<Stream>& operator<< (packer<Stream>& o, const std::unordered_set<T>& v)
{
o.pack_array(v.size());
uint32_t size = checked_get_container_size(v.size());
o.pack_array(size);
for(typename std::unordered_set<T>::const_iterator it(v.begin()), it_end(v.end());
it != it_end; ++it) {
it != it_end; ++it) {
o.pack(*it);
}
return o;
@ -61,10 +63,11 @@ inline void operator<< (object::with_zone& o, const std::unordered_set<T>& v)
o.via.array.ptr = nullptr;
o.via.array.size = 0;
} else {
object* p = static_cast<object*>(o.zone.allocate_align(sizeof(object)*v.size()));
object* const pend = p + v.size();
uint32_t size = checked_get_container_size(v.size());
object* p = static_cast<object*>(o.zone.allocate_align(sizeof(object)*size));
object* const pend = p + size;
o.via.array.ptr = p;
o.via.array.size = v.size();
o.via.array.size = size;
typename std::unordered_set<T>::const_iterator it(v.begin());
do {
*p = object(*it, o.zone);
@ -93,7 +96,8 @@ inline object const& operator>> (object const& o, std::unordered_multiset<T>& v)
template <typename Stream, typename T>
inline packer<Stream>& operator<< (packer<Stream>& o, const std::unordered_multiset<T>& v)
{
o.pack_array(v.size());
uint32_t size = checked_get_container_size(v.size());
o.pack_array(size);
for(typename std::unordered_multiset<T>::const_iterator it(v.begin()), it_end(v.end());
it != it_end; ++it) {
o.pack(*it);
@ -109,10 +113,11 @@ inline void operator<< (object::with_zone& o, const std::unordered_multiset<T>&
o.via.array.ptr = nullptr;
o.via.array.size = 0;
} else {
object* p = static_cast<object*>(o.zone.allocate_align(sizeof(object)*v.size()));
object* const pend = p + v.size();
uint32_t size = checked_get_container_size(v.size());
object* p = static_cast<object*>(o.zone.allocate_align(sizeof(object)*size));
object* const pend = p + size;
o.via.array.ptr = p;
o.via.array.size = v.size();
o.via.array.size = size;
typename std::unordered_multiset<T>::const_iterator it(v.begin());
do {
*p = object(*it, o.zone);

View File

@ -1,7 +1,7 @@
//
// MessagePack for C++ static resolution routine
//
// Copyright (C) 2008-2009 FURUHASHI Sadayuki
// Copyright (C) 2008-2015 FURUHASHI Sadayuki
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@ -20,6 +20,8 @@
#include "msgpack/versioning.hpp"
#include "msgpack/object_fwd.hpp"
#include "msgpack/adaptor/check_container_size.hpp"
#include <deque>
namespace msgpack {
@ -43,7 +45,8 @@ inline object const& operator>> (object const& o, std::deque<T>& v)
template <typename Stream, typename T>
inline packer<Stream>& operator<< (packer<Stream>& o, const std::deque<T>& v)
{
o.pack_array(v.size());
uint32_t size = checked_get_container_size(v.size());
o.pack_array(size);
for(typename std::deque<T>::const_iterator it(v.begin()), it_end(v.end());
it != it_end; ++it) {
o.pack(*it);
@ -59,10 +62,11 @@ inline void operator<< (object::with_zone& o, const std::deque<T>& v)
o.via.array.ptr = nullptr;
o.via.array.size = 0;
} else {
object* p = static_cast<object*>(o.zone.allocate_align(sizeof(object)*v.size()));
object* const pend = p + v.size();
uint32_t size = checked_get_container_size(v.size());
object* p = static_cast<object*>(o.zone.allocate_align(sizeof(object)*size));
object* const pend = p + size;
o.via.array.ptr = p;
o.via.array.size = v.size();
o.via.array.size = size;
typename std::deque<T>::const_iterator it(v.begin());
do {
*p = object(*it, o.zone);

View File

@ -1,7 +1,7 @@
//
// MessagePack for C++ static resolution routine
//
// Copyright (C) 2008-2009 FURUHASHI Sadayuki
// Copyright (C) 2008-2015 FURUHASHI Sadayuki
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@ -20,6 +20,8 @@
#include "msgpack/versioning.hpp"
#include "msgpack/object_fwd.hpp"
#include "msgpack/adaptor/check_container_size.hpp"
#include <list>
namespace msgpack {
@ -43,9 +45,10 @@ inline object const& operator>> (object const& o, std::list<T>& v)
template <typename Stream, typename T>
inline packer<Stream>& operator<< (packer<Stream>& o, const std::list<T>& v)
{
o.pack_array(v.size());
uint32_t size = checked_get_container_size(v.size());
o.pack_array(size);
for(typename std::list<T>::const_iterator it(v.begin()), it_end(v.end());
it != it_end; ++it) {
it != it_end; ++it) {
o.pack(*it);
}
return o;
@ -59,10 +62,11 @@ inline void operator<< (object::with_zone& o, const std::list<T>& v)
o.via.array.ptr = nullptr;
o.via.array.size = 0;
} else {
object* p = static_cast<object*>(o.zone.allocate_align(sizeof(object)*v.size()));
object* const pend = p + v.size();
uint32_t size = checked_get_container_size(v.size());
object* p = static_cast<object*>(o.zone.allocate_align(sizeof(object)*size));
object* const pend = p + size;
o.via.array.ptr = p;
o.via.array.size = v.size();
o.via.array.size = size;
typename std::list<T>::const_iterator it(v.begin());
do {
*p = object(*it, o.zone);

View File

@ -1,7 +1,7 @@
//
// MessagePack for C++ static resolution routine
//
// Copyright (C) 2008-2009 FURUHASHI Sadayuki
// Copyright (C) 2008-2015 FURUHASHI Sadayuki
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@ -20,6 +20,8 @@
#include "msgpack/versioning.hpp"
#include "msgpack/object_fwd.hpp"
#include "msgpack/adaptor/check_container_size.hpp"
#include <map>
#include <vector>
#include <algorithm>
@ -63,9 +65,10 @@ inline object const& operator>> (object const& o, type::assoc_vector<K,V>& v)
template <typename Stream, typename K, typename V>
inline packer<Stream>& operator<< (packer<Stream>& o, const type::assoc_vector<K,V>& v)
{
o.pack_map(v.size());
uint32_t size = checked_get_container_size(v.size());
o.pack_map(size);
for(typename type::assoc_vector<K,V>::const_iterator it(v.begin()), it_end(v.end());
it != it_end; ++it) {
it != it_end; ++it) {
o.pack(it->first);
o.pack(it->second);
}
@ -80,10 +83,11 @@ inline void operator<< (object::with_zone& o, const type::assoc_vector<K,V>& v)
o.via.map.ptr = nullptr;
o.via.map.size = 0;
} else {
object_kv* p = static_cast<object_kv*>(o.zone.allocate_align(sizeof(object_kv)*v.size()));
object_kv* const pend = p + v.size();
uint32_t size = checked_get_container_size(v.size());
object_kv* p = static_cast<object_kv*>(o.zone.allocate_align(sizeof(object_kv)*size));
object_kv* const pend = p + size;
o.via.map.ptr = p;
o.via.map.size = v.size();
o.via.map.size = size;
typename type::assoc_vector<K,V>::const_iterator it(v.begin());
do {
p->key = object(it->first, o.zone);
@ -121,9 +125,10 @@ inline object const& operator>> (object const& o, std::map<K, V>& v)
template <typename Stream, typename K, typename V>
inline packer<Stream>& operator<< (packer<Stream>& o, const std::map<K,V>& v)
{
o.pack_map(v.size());
uint32_t size = checked_get_container_size(v.size());
o.pack_map(size);
for(typename std::map<K,V>::const_iterator it(v.begin()), it_end(v.end());
it != it_end; ++it) {
it != it_end; ++it) {
o.pack(it->first);
o.pack(it->second);
}
@ -138,10 +143,11 @@ inline void operator<< (object::with_zone& o, const std::map<K,V>& v)
o.via.map.ptr = nullptr;
o.via.map.size = 0;
} else {
object_kv* p = static_cast<object_kv*>(o.zone.allocate_align(sizeof(object_kv)*v.size()));
object_kv* const pend = p + v.size();
uint32_t size = checked_get_container_size(v.size());
object_kv* p = static_cast<object_kv*>(o.zone.allocate_align(sizeof(object_kv)*size));
object_kv* const pend = p + size;
o.via.map.ptr = p;
o.via.map.size = v.size();
o.via.map.size = size;
typename std::map<K,V>::const_iterator it(v.begin());
do {
p->key = object(it->first, o.zone);
@ -173,9 +179,10 @@ inline object const& operator>> (object const& o, std::multimap<K, V>& v)
template <typename Stream, typename K, typename V>
inline packer<Stream>& operator<< (packer<Stream>& o, const std::multimap<K,V>& v)
{
o.pack_map(v.size());
uint32_t size = checked_get_container_size(v.size());
o.pack_map(size);
for(typename std::multimap<K,V>::const_iterator it(v.begin()), it_end(v.end());
it != it_end; ++it) {
it != it_end; ++it) {
o.pack(it->first);
o.pack(it->second);
}
@ -190,10 +197,11 @@ inline void operator<< (object::with_zone& o, const std::multimap<K,V>& v)
o.via.map.ptr = nullptr;
o.via.map.size = 0;
} else {
object_kv* p = static_cast<object_kv*>(o.zone.allocate_align(sizeof(object_kv)*v.size()));
object_kv* const pend = p + v.size();
uint32_t size = checked_get_container_size(v.size());
object_kv* p = static_cast<object_kv*>(o.zone.allocate_align(sizeof(object_kv)*size));
object_kv* const pend = p + size;
o.via.map.ptr = p;
o.via.map.size = v.size();
o.via.map.size = size;
typename std::multimap<K,V>::const_iterator it(v.begin());
do {
p->key = object(it->first, o.zone);

View File

@ -1,7 +1,7 @@
//
// MessagePack for C++ static resolution routine
//
// Copyright (C) 2008-2009 FURUHASHI Sadayuki
// Copyright (C) 2008-2015 FURUHASHI Sadayuki
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@ -20,6 +20,7 @@
#include "msgpack/versioning.hpp"
#include "msgpack/object_fwd.hpp"
#include "msgpack/adaptor/check_container_size.hpp"
#include <set>
@ -45,9 +46,10 @@ inline object const& operator>> (object const& o, std::set<T>& v)
template <typename Stream, typename T>
inline packer<Stream>& operator<< (packer<Stream>& o, const std::set<T>& v)
{
o.pack_array(v.size());
uint32_t size = checked_get_container_size(v.size());
o.pack_array(size);
for(typename std::set<T>::const_iterator it(v.begin()), it_end(v.end());
it != it_end; ++it) {
it != it_end; ++it) {
o.pack(*it);
}
return o;
@ -61,10 +63,11 @@ inline void operator<< (object::with_zone& o, const std::set<T>& v)
o.via.array.ptr = nullptr;
o.via.array.size = 0;
} else {
object* p = static_cast<object*>(o.zone.allocate_align(sizeof(object)*v.size()));
object* const pend = p + v.size();
uint32_t size = checked_get_container_size(v.size());
object* p = static_cast<object*>(o.zone.allocate_align(sizeof(object)*size));
object* const pend = p + size;
o.via.array.ptr = p;
o.via.array.size = v.size();
o.via.array.size = size;
typename std::set<T>::const_iterator it(v.begin());
do {
*p = object(*it, o.zone);
@ -93,9 +96,10 @@ inline object const& operator>> (object const& o, std::multiset<T>& v)
template <typename Stream, typename T>
inline packer<Stream>& operator<< (packer<Stream>& o, const std::multiset<T>& v)
{
o.pack_array(v.size());
uint32_t size = checked_get_container_size(v.size());
o.pack_array(size);
for(typename std::multiset<T>::const_iterator it(v.begin()), it_end(v.end());
it != it_end; ++it) {
it != it_end; ++it) {
o.pack(*it);
}
return o;
@ -109,10 +113,11 @@ inline void operator<< (object::with_zone& o, const std::multiset<T>& v)
o.via.array.ptr = nullptr;
o.via.array.size = 0;
} else {
object* p = static_cast<object*>(o.zone.allocate_align(sizeof(object)*v.size()));
object* const pend = p + v.size();
uint32_t size = checked_get_container_size(v.size());
object* p = static_cast<object*>(o.zone.allocate_align(sizeof(object)*size));
object* const pend = p + size;
o.via.array.ptr = p;
o.via.array.size = v.size();
o.via.array.size = size;
typename std::multiset<T>::const_iterator it(v.begin());
do {
*p = object(*it, o.zone);

View File

@ -1,7 +1,7 @@
//
// MessagePack for C++ static resolution routine
//
// Copyright (C) 2008-2009 FURUHASHI Sadayuki
// Copyright (C) 2008-2015 FURUHASHI Sadayuki
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@ -20,6 +20,8 @@
#include "msgpack/versioning.hpp"
#include "msgpack/object_fwd.hpp"
#include "msgpack/adaptor/check_container_size.hpp"
#include <string>
namespace msgpack {
@ -45,25 +47,28 @@ inline object const& operator>> (object const& o, std::string& v)
template <typename Stream>
inline packer<Stream>& operator<< (packer<Stream>& o, const std::string& v)
{
o.pack_str(v.size());
o.pack_str_body(v.data(), v.size());
uint32_t size = checked_get_container_size(v.size());
o.pack_str(size);
o.pack_str_body(v.data(), size);
return o;
}
inline void operator<< (object::with_zone& o, const std::string& v)
{
uint32_t size = checked_get_container_size(v.size());
o.type = type::STR;
char* ptr = static_cast<char*>(o.zone.allocate_align(v.size()));
char* ptr = static_cast<char*>(o.zone.allocate_align(size));
o.via.str.ptr = ptr;
o.via.str.size = static_cast<uint32_t>(v.size());
memcpy(ptr, v.data(), v.size());
o.via.str.size = size;
memcpy(ptr, v.data(), size);
}
inline void operator<< (object& o, const std::string& v)
{
uint32_t size = checked_get_container_size(v.size());
o.type = type::STR;
o.via.str.ptr = v.data();
o.via.str.size = static_cast<uint32_t>(v.size());
o.via.str.size = size;
}
} // MSGPACK_API_VERSION_NAMESPACE(v1)

View File

@ -1,7 +1,7 @@
//
// MessagePack for C++ static resolution routine
//
// Copyright (C) 2008-2009 FURUHASHI Sadayuki
// Copyright (C) 2008-2015 FURUHASHI Sadayuki
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@ -20,6 +20,7 @@
#include "msgpack/versioning.hpp"
#include "msgpack/object_fwd.hpp"
#include "msgpack/adaptor/check_container_size.hpp"
#if defined(_LIBCPP_VERSION) || (_MSC_VER >= 1700)
@ -65,9 +66,10 @@ inline object const& operator>> (object const& o, MSGPACK_STD_TR1::unordered_map
template <typename Stream, typename K, typename V>
inline packer<Stream>& operator<< (packer<Stream>& o, const MSGPACK_STD_TR1::unordered_map<K,V>& v)
{
o.pack_map(v.size());
uint32_t size = checked_get_container_size(v.size());
o.pack_map(size);
for(typename MSGPACK_STD_TR1::unordered_map<K,V>::const_iterator it(v.begin()), it_end(v.end());
it != it_end; ++it) {
it != it_end; ++it) {
o.pack(it->first);
o.pack(it->second);
}
@ -82,10 +84,11 @@ inline void operator<< (object::with_zone& o, const MSGPACK_STD_TR1::unordered_m
o.via.map.ptr = nullptr;
o.via.map.size = 0;
} else {
object_kv* p = static_cast<object_kv*>(o.zone.allocate_align(sizeof(object_kv)*v.size()));
object_kv* const pend = p + v.size();
uint32_t size = checked_get_container_size(v.size());
object_kv* p = static_cast<object_kv*>(o.zone.allocate_align(sizeof(object_kv)*size));
object_kv* const pend = p + size;
o.via.map.ptr = p;
o.via.map.size = v.size();
o.via.map.size = size;
typename MSGPACK_STD_TR1::unordered_map<K,V>::const_iterator it(v.begin());
do {
p->key = object(it->first, o.zone);
@ -117,9 +120,10 @@ inline object const& operator>> (object const& o, MSGPACK_STD_TR1::unordered_mul
template <typename Stream, typename K, typename V>
inline packer<Stream>& operator<< (packer<Stream>& o, const MSGPACK_STD_TR1::unordered_multimap<K,V>& v)
{
o.pack_map(v.size());
uint32_t size = checked_get_container_size(v.size());
o.pack_map(size);
for(typename MSGPACK_STD_TR1::unordered_multimap<K,V>::const_iterator it(v.begin()), it_end(v.end());
it != it_end; ++it) {
it != it_end; ++it) {
o.pack(it->first);
o.pack(it->second);
}
@ -134,10 +138,11 @@ inline void operator<< (object::with_zone& o, const MSGPACK_STD_TR1::unordered_m
o.via.map.ptr = nullptr;
o.via.map.size = 0;
} else {
object_kv* p = static_cast<object_kv*>(o.zone.allocate_align(sizeof(object_kv)*v.size()));
object_kv* const pend = p + v.size();
uint32_t size = checked_get_container_size(v.size());
object_kv* p = static_cast<object_kv*>(o.zone.allocate_align(sizeof(object_kv)*size));
object_kv* const pend = p + size;
o.via.map.ptr = p;
o.via.map.size = v.size();
o.via.map.size = size;
typename MSGPACK_STD_TR1::unordered_multimap<K,V>::const_iterator it(v.begin());
do {
p->key = object(it->first, o.zone);

View File

@ -1,7 +1,7 @@
//
// MessagePack for C++ static resolution routine
//
// Copyright (C) 2008-2009 FURUHASHI Sadayuki
// Copyright (C) 2008-2015 FURUHASHI Sadayuki
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@ -20,6 +20,7 @@
#include "msgpack/versioning.hpp"
#include "msgpack/object_fwd.hpp"
#include "msgpack/adaptor/check_container_size.hpp"
#if defined(_LIBCPP_VERSION) || (_MSC_VER >= 1700)
@ -64,9 +65,10 @@ inline object const& operator>> (object const& o, MSGPACK_STD_TR1::unordered_set
template <typename Stream, typename T>
inline packer<Stream>& operator<< (packer<Stream>& o, const MSGPACK_STD_TR1::unordered_set<T>& v)
{
o.pack_array(v.size());
uint32_t size = checked_get_container_size(v.size());
o.pack_array(size);
for(typename MSGPACK_STD_TR1::unordered_set<T>::const_iterator it(v.begin()), it_end(v.end());
it != it_end; ++it) {
it != it_end; ++it) {
o.pack(*it);
}
return o;
@ -80,10 +82,11 @@ inline void operator<< (object::with_zone& o, const MSGPACK_STD_TR1::unordered_s
o.via.array.ptr = nullptr;
o.via.array.size = 0;
} else {
object* p = static_cast<object*>(o.zone.allocate_align(sizeof(object)*v.size()));
object* const pend = p + v.size();
uint32_t size = checked_get_container_size(v.size());
object* p = static_cast<object*>(o.zone.allocate_align(sizeof(object)*size));
object* const pend = p + size;
o.via.array.ptr = p;
o.via.array.size = v.size();
o.via.array.size = size;
typename MSGPACK_STD_TR1::unordered_set<T>::const_iterator it(v.begin());
do {
*p = object(*it, o.zone);
@ -112,7 +115,8 @@ inline object const& operator>> (object const& o, MSGPACK_STD_TR1::unordered_mul
template <typename Stream, typename T>
inline packer<Stream>& operator<< (packer<Stream>& o, const MSGPACK_STD_TR1::unordered_multiset<T>& v)
{
o.pack_array(v.size());
uint32_t size = checked_get_container_size(v.size());
o.pack_array(size);
for(typename MSGPACK_STD_TR1::unordered_multiset<T>::const_iterator it(v.begin()), it_end(v.end());
it != it_end; ++it) {
o.pack(*it);
@ -128,10 +132,11 @@ inline void operator<< (object::with_zone& o, const MSGPACK_STD_TR1::unordered_m
o.via.array.ptr = nullptr;
o.via.array.size = 0;
} else {
object* p = static_cast<object*>(o.zone.allocate_align(sizeof(object)*v.size()));
object* const pend = p + v.size();
uint32_t size = checked_get_container_size(v.size());
object* p = static_cast<object*>(o.zone.allocate_align(sizeof(object)*size));
object* const pend = p + size;
o.via.array.ptr = p;
o.via.array.size = v.size();
o.via.array.size = size;
typename MSGPACK_STD_TR1::unordered_multiset<T>::const_iterator it(v.begin());
do {
*p = object(*it, o.zone);

View File

@ -20,6 +20,8 @@
#include "msgpack/versioning.hpp"
#include "msgpack/object_fwd.hpp"
#include "msgpack/adaptor/check_container_size.hpp"
#include <vector>
namespace msgpack {
@ -47,7 +49,8 @@ inline object const& operator>> (object const& o, std::vector<T>& v)
template <typename Stream, typename T>
inline packer<Stream>& operator<< (packer<Stream>& o, const std::vector<T>& v)
{
o.pack_array(v.size());
uint32_t size = checked_get_container_size(v.size());
o.pack_array(size);
for(typename std::vector<T>::const_iterator it(v.begin()), it_end(v.end());
it != it_end; ++it) {
o.pack(*it);
@ -63,10 +66,11 @@ inline void operator<< (object::with_zone& o, const std::vector<T>& v)
o.via.array.ptr = nullptr;
o.via.array.size = 0;
} else {
object* p = static_cast<object*>(o.zone.allocate_align(sizeof(object)*v.size()));
object* const pend = p + v.size();
uint32_t size = checked_get_container_size(v.size());
object* p = static_cast<object*>(o.zone.allocate_align(sizeof(object)*size));
object* const pend = p + size;
o.via.array.ptr = p;
o.via.array.size = v.size();
o.via.array.size = size;
typename std::vector<T>::const_iterator it(v.begin());
do {
*p = object(*it, o.zone);

View File

@ -1,7 +1,7 @@
//
// MessagePack for C++ static resolution routine
//
// Copyright (C) 2014 KONDO Takatoshi
// Copyright (C) 2014-2015 KONDO Takatoshi
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@ -20,6 +20,8 @@
#include "msgpack/versioning.hpp"
#include "msgpack/object_fwd.hpp"
#include "msgpack/adaptor/check_container_size.hpp"
#include <vector>
namespace msgpack {
@ -47,26 +49,29 @@ inline object const& operator>> (object const& o, std::vector<char>& v)
template <typename Stream>
inline packer<Stream>& operator<< (packer<Stream>& o, const std::vector<char>& v)
{
o.pack_bin(v.size());
o.pack_bin_body(&v.front(), v.size());
uint32_t size = checked_get_container_size(v.size());
o.pack_bin(size);
o.pack_bin_body(&v.front(), size);
return o;
}
inline void operator<< (object& o, const std::vector<char>& v)
{
uint32_t size = checked_get_container_size(v.size());
o.type = type::BIN;
o.via.bin.ptr = &v.front();
o.via.bin.size = static_cast<uint32_t>(v.size());
o.via.bin.size = size;
}
inline void operator<< (object::with_zone& o, const std::vector<char>& v)
{
uint32_t size = checked_get_container_size(v.size());
o.type = type::BIN;
char* ptr = static_cast<char*>(o.zone.allocate_align(v.size()));
char* ptr = static_cast<char*>(o.zone.allocate_align(size));
o.via.bin.ptr = ptr;
o.via.bin.size = static_cast<uint32_t>(v.size());
std::memcpy(ptr, &v.front(), v.size());
o.via.bin.size = size;
std::memcpy(ptr, &v.front(), size);
}
} // MSGPACK_API_VERSION_NAMESPACE(v1)

View File

@ -78,18 +78,18 @@ public:
packer<Stream>& pack_true();
packer<Stream>& pack_false();
packer<Stream>& pack_array(size_t n);
packer<Stream>& pack_array(uint32_t n);
packer<Stream>& pack_map(size_t n);
packer<Stream>& pack_map(uint32_t n);
packer<Stream>& pack_str(size_t l);
packer<Stream>& pack_str_body(const char* b, size_t l);
packer<Stream>& pack_str(uint32_t l);
packer<Stream>& pack_str_body(const char* b, uint32_t l);
packer<Stream>& pack_bin(size_t l);
packer<Stream>& pack_bin_body(const char* b, size_t l);
packer<Stream>& pack_bin(uint32_t l);
packer<Stream>& pack_bin_body(const char* b, uint32_t l);
packer<Stream>& pack_ext(size_t l, int8_t type);
packer<Stream>& pack_ext_body(const char* b, size_t l);
packer<Stream>& pack_ext_body(const char* b, uint32_t l);
private:
template <typename T>
@ -638,7 +638,7 @@ inline packer<Stream>& packer<Stream>::pack_false()
template <typename Stream>
inline packer<Stream>& packer<Stream>::pack_array(size_t n)
inline packer<Stream>& packer<Stream>::pack_array(uint32_t n)
{
if(n < 16) {
char d = static_cast<char>(0x90u | n);
@ -656,10 +656,10 @@ inline packer<Stream>& packer<Stream>::pack_array(size_t n)
}
template <typename Stream>
inline packer<Stream>& packer<Stream>::pack_map(size_t n)
inline packer<Stream>& packer<Stream>::pack_map(uint32_t n)
{
if(n < 16) {
unsigned char d = 0x80u | n;
unsigned char d = static_cast<unsigned char>(0x80u | n);
char buf = take8_8(d);
append_buffer(&buf, 1);
} else if(n < 65536) {
@ -675,7 +675,7 @@ inline packer<Stream>& packer<Stream>::pack_map(size_t n)
}
template <typename Stream>
inline packer<Stream>& packer<Stream>::pack_str(size_t l)
inline packer<Stream>& packer<Stream>::pack_str(uint32_t l)
{
if(l < 32) {
unsigned char d = 0xa0u | static_cast<uint8_t>(l);
@ -698,14 +698,14 @@ inline packer<Stream>& packer<Stream>::pack_str(size_t l)
}
template <typename Stream>
inline packer<Stream>& packer<Stream>::pack_str_body(const char* b, size_t l)
inline packer<Stream>& packer<Stream>::pack_str_body(const char* b, uint32_t l)
{
append_buffer(b, l);
return *this;
}
template <typename Stream>
inline packer<Stream>& packer<Stream>::pack_bin(size_t l)
inline packer<Stream>& packer<Stream>::pack_bin(uint32_t l)
{
if(l < 256) {
char buf[2];
@ -724,7 +724,7 @@ inline packer<Stream>& packer<Stream>::pack_bin(size_t l)
}
template <typename Stream>
inline packer<Stream>& packer<Stream>::pack_bin_body(const char* b, size_t l)
inline packer<Stream>& packer<Stream>::pack_bin_body(const char* b, uint32_t l)
{
append_buffer(b, l);
return *this;
@ -790,7 +790,7 @@ inline packer<Stream>& packer<Stream>::pack_ext(size_t l, int8_t type)
}
template <typename Stream>
inline packer<Stream>& packer<Stream>::pack_ext_body(const char* b, size_t l)
inline packer<Stream>& packer<Stream>::pack_ext_body(const char* b, uint32_t l)
{
append_buffer(b, l);
return *this;

View File

@ -1,7 +1,7 @@
//
// MessagePack for C++ deserializing routine
//
// Copyright (C) 2008-2013 FURUHASHI Sadayuki and KONDO Takatoshi
// Copyright (C) 2008-2015 FURUHASHI Sadayuki and KONDO Takatoshi
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@ -324,7 +324,7 @@ inline void unpack_ext(unpack_user& u, const char* p, std::size_t l, object& o)
std::memcpy(tmp, p, l);
o.via.ext.ptr = tmp;
}
o.via.ext.size = l - 1;
o.via.ext.size = static_cast<uint32_t>(l - 1);
}
@ -616,7 +616,7 @@ inline int context::execute(const char* data, std::size_t len, std::size_t& off)
} else if(0xa0 <= selector && selector <= 0xbf) { // FixStr
m_trail = static_cast<uint32_t>(*m_current) & 0x1f;
if(m_trail == 0) {
unpack_str(m_user, n, m_trail, obj);
unpack_str(m_user, n, static_cast<uint32_t>(m_trail), obj);
int ret = push_proc(obj, off);
if (ret != 0) return ret;
}
@ -769,7 +769,7 @@ inline int context::execute(const char* data, std::size_t len, std::size_t& off)
load<uint8_t>(tmp, n);
m_trail = tmp;
if(m_trail == 0) {
unpack_str(m_user, n, m_trail, obj);
unpack_str(m_user, n, static_cast<uint32_t>(m_trail), obj);
int ret = push_proc(obj, off);
if (ret != 0) return ret;
}
@ -783,7 +783,7 @@ inline int context::execute(const char* data, std::size_t len, std::size_t& off)
load<uint8_t>(tmp, n);
m_trail = tmp;
if(m_trail == 0) {
unpack_bin(m_user, n, m_trail, obj);
unpack_bin(m_user, n, static_cast<uint32_t>(m_trail), obj);
int ret = push_proc(obj, off);
if (ret != 0) return ret;
}
@ -811,7 +811,7 @@ inline int context::execute(const char* data, std::size_t len, std::size_t& off)
load<uint16_t>(tmp, n);
m_trail = tmp;
if(m_trail == 0) {
unpack_str(m_user, n, m_trail, obj);
unpack_str(m_user, n, static_cast<uint32_t>(m_trail), obj);
int ret = push_proc(obj, off);
if (ret != 0) return ret;
}
@ -825,7 +825,7 @@ inline int context::execute(const char* data, std::size_t len, std::size_t& off)
load<uint16_t>(tmp, n);
m_trail = tmp;
if(m_trail == 0) {
unpack_bin(m_user, n, m_trail, obj);
unpack_bin(m_user, n, static_cast<uint32_t>(m_trail), obj);
int ret = push_proc(obj, off);
if (ret != 0) return ret;
}
@ -853,7 +853,7 @@ inline int context::execute(const char* data, std::size_t len, std::size_t& off)
load<uint32_t>(tmp, n);
m_trail = tmp;
if(m_trail == 0) {
unpack_str(m_user, n, m_trail, obj);
unpack_str(m_user, n, static_cast<uint32_t>(m_trail), obj);
int ret = push_proc(obj, off);
if (ret != 0) return ret;
}
@ -867,7 +867,7 @@ inline int context::execute(const char* data, std::size_t len, std::size_t& off)
load<uint32_t>(tmp, n);
m_trail = tmp;
if(m_trail == 0) {
unpack_bin(m_user, n, m_trail, obj);
unpack_bin(m_user, n, static_cast<uint32_t>(m_trail), obj);
int ret = push_proc(obj, off);
if (ret != 0) return ret;
}
@ -893,12 +893,12 @@ inline int context::execute(const char* data, std::size_t len, std::size_t& off)
}
} break;
case MSGPACK_ACS_STR_VALUE: {
unpack_str(m_user, n, m_trail, obj);
unpack_str(m_user, n, static_cast<uint32_t>(m_trail), obj);
int ret = push_proc(obj, off);
if (ret != 0) return ret;
} break;
case MSGPACK_ACS_BIN_VALUE: {
unpack_bin(m_user, n, m_trail, obj);
unpack_bin(m_user, n, static_cast<uint32_t>(m_trail), obj);
int ret = push_proc(obj, off);
if (ret != 0) return ret;
} break;

View File

@ -58,6 +58,7 @@ nobase_include_HEADERS += \
../include/msgpack/adaptor/bool_fwd.hpp \
../include/msgpack/adaptor/char_ptr.hpp \
../include/msgpack/adaptor/char_ptr_fwd.hpp \
../include/msgpack/adaptor/check_container_size.hpp \
../include/msgpack/adaptor/cpp11/array.hpp \
../include/msgpack/adaptor/cpp11/array_fwd.hpp \
../include/msgpack/adaptor/cpp11/array_char.hpp \

View File

@ -322,7 +322,7 @@ TEST(object_without_zone, char_ptr)
TEST(object_with_zone, raw_ref)
{
string s = "abc";
msgpack::type::raw_ref v(s.data(), s.size());
msgpack::type::raw_ref v(s.data(), static_cast<uint32_t>(s.size()));
msgpack::zone z;
msgpack::object obj(v, z);
EXPECT_EQ(obj.as<msgpack::type::raw_ref>(), v);
@ -336,7 +336,7 @@ TEST(object_with_zone, raw_ref)
TEST(object_without_zone, raw_ref)
{
string s = "abc";
msgpack::type::raw_ref v(s.data(), s.size());
msgpack::type::raw_ref v(s.data(), static_cast<uint32_t>(s.size()));
msgpack::zone z;
msgpack::object obj(v);
EXPECT_EQ(obj.as<msgpack::type::raw_ref>(), v);