Skip to content

Commit

Permalink
Merge pull request #437 from redboltz/bp_435
Browse files Browse the repository at this point in the history
Backported #435 to version 1.4.0.
  • Loading branch information
redboltz committed Mar 6, 2016
2 parents 66a5fcf + 1088aa5 commit 39433e8
Show file tree
Hide file tree
Showing 5 changed files with 440 additions and 21 deletions.
24 changes: 17 additions & 7 deletions include/msgpack/adaptor/map.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,16 @@ struct convert<type::assoc_vector<K, V, Compare, Alloc> > {
msgpack::object const& operator()(msgpack::object const& o, type::assoc_vector<K, V, Compare, Alloc>& v) const {
if (o.type != msgpack::type::MAP) { throw msgpack::type_error(); }
v.resize(o.via.map.size);
msgpack::object_kv* p = o.via.map.ptr;
msgpack::object_kv* const pend = o.via.map.ptr + o.via.map.size;
std::pair<K, V>* it(&v.front());
for (; p < pend; ++p, ++it) {
p->key.convert(it->first);
p->val.convert(it->second);
if (o.via.map.size != 0) {
msgpack::object_kv* p = o.via.map.ptr;
msgpack::object_kv* const pend = o.via.map.ptr + o.via.map.size;
std::pair<K, V>* it(&v.front());
for (; p < pend; ++p, ++it) {
p->key.convert(it->first);
p->val.convert(it->second);
}
std::sort(v.begin(), v.end(), type::detail::pair_first_less<K, V, Compare, Alloc>());
}
std::sort(v.begin(), v.end(), type::detail::pair_first_less<K, V, Compare, Alloc>());
return o;
}
};
Expand Down Expand Up @@ -194,14 +196,22 @@ struct object_with_zone<std::map<K, V, Compare, Alloc> > {
}
else {
uint32_t size = checked_get_container_size(v.size());

msgpack::object_kv* p = static_cast<msgpack::object_kv*>(o.zone.allocate_align(sizeof(msgpack::object_kv)*size));
msgpack::object_kv* const pend = p + size;
o.via.map.ptr = p;
o.via.map.size = size;
typename std::map<K, V, Compare, Alloc>::const_iterator it(v.begin());
do {
#if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && !defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
#endif // (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && !defined(__clang__)
p->key = msgpack::object(it->first, o.zone);
p->val = msgpack::object(it->second, o.zone);
#if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && !defined(__clang__)
#pragma GCC diagnostic pop
#endif // (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && !defined(__clang__)
++p;
++it;
} while(p < pend);
Expand Down
38 changes: 31 additions & 7 deletions include/msgpack/adaptor/vector_char.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,29 @@ struct convert<std::vector<char, Alloc> > {
switch (o.type) {
case msgpack::type::BIN:
v.resize(o.via.bin.size);
std::memcpy(&v.front(), o.via.bin.ptr, o.via.bin.size);
if (o.via.bin.size != 0) {
#if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && !defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
#endif // (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && !defined(__clang__)
std::memcpy(&v.front(), o.via.bin.ptr, o.via.bin.size);
#if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && !defined(__clang__)
#pragma GCC diagnostic pop
#endif // (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && !defined(__clang__)
}
break;
case msgpack::type::STR:
v.resize(o.via.str.size);
std::memcpy(&v.front(), o.via.str.ptr, o.via.str.size);
if (o.via.str.size != 0) {
#if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && !defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
#endif // (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && !defined(__clang__)
std::memcpy(&v.front(), o.via.str.ptr, o.via.str.size);
#if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && !defined(__clang__)
#pragma GCC diagnostic pop
#endif // (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && !defined(__clang__)
}
break;
default:
throw msgpack::type_error();
Expand All @@ -50,7 +68,9 @@ struct pack<std::vector<char, Alloc> > {
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const std::vector<char, Alloc>& v) const {
uint32_t size = checked_get_container_size(v.size());
o.pack_bin(size);
o.pack_bin_body(&v.front(), size);
if (size != 0) {
o.pack_bin_body(&v.front(), size);
}

return o;
}
Expand All @@ -61,7 +81,9 @@ struct object<std::vector<char, Alloc> > {
void operator()(msgpack::object& o, const std::vector<char, Alloc>& v) const {
uint32_t size = checked_get_container_size(v.size());
o.type = msgpack::type::BIN;
o.via.bin.ptr = &v.front();
if (size != 0) {
o.via.bin.ptr = &v.front();
}
o.via.bin.size = size;
}
};
Expand All @@ -71,10 +93,12 @@ struct object_with_zone<std::vector<char, Alloc> > {
void operator()(msgpack::object::with_zone& o, const std::vector<char, Alloc>& v) const {
uint32_t size = checked_get_container_size(v.size());
o.type = msgpack::type::BIN;
char* ptr = static_cast<char*>(o.zone.allocate_align(size));
o.via.bin.ptr = ptr;
o.via.bin.size = size;
std::memcpy(ptr, &v.front(), size);
if (size != 0) {
char* ptr = static_cast<char*>(o.zone.allocate_align(size));
o.via.bin.ptr = ptr;
std::memcpy(ptr, &v.front(), size);
}
}
};

Expand Down
38 changes: 31 additions & 7 deletions include/msgpack/adaptor/vector_unsigned_char.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,29 @@ struct convert<std::vector<unsigned char, Alloc> > {
switch (o.type) {
case msgpack::type::BIN:
v.resize(o.via.bin.size);
std::memcpy(&v.front(), o.via.bin.ptr, o.via.bin.size);
if (o.via.bin.size != 0) {
#if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && !defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
#endif // (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && !defined(__clang__)
std::memcpy(&v.front(), o.via.bin.ptr, o.via.bin.size);
#if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && !defined(__clang__)
#pragma GCC diagnostic pop
#endif // (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && !defined(__clang__)
}
break;
case msgpack::type::STR:
v.resize(o.via.str.size);
std::memcpy(&v.front(), o.via.str.ptr, o.via.str.size);
if (o.via.str.size != 0) {
#if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && !defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
#endif // (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && !defined(__clang__)
std::memcpy(&v.front(), o.via.str.ptr, o.via.str.size);
#if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && !defined(__clang__)
#pragma GCC diagnostic pop
#endif // (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && !defined(__clang__)
}
break;
default:
throw msgpack::type_error();
Expand All @@ -50,7 +68,9 @@ struct pack<std::vector<unsigned char, Alloc> > {
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const std::vector<unsigned char, Alloc>& v) const {
uint32_t size = checked_get_container_size(v.size());
o.pack_bin(size);
o.pack_bin_body(reinterpret_cast<char const*>(&v.front()), size);
if (size != 0) {
o.pack_bin_body(reinterpret_cast<char const*>(&v.front()), size);
}

return o;
}
Expand All @@ -61,7 +81,9 @@ struct object<std::vector<unsigned char, Alloc> > {
void operator()(msgpack::object& o, const std::vector<unsigned char, Alloc>& v) const {
uint32_t size = checked_get_container_size(v.size());
o.type = msgpack::type::BIN;
o.via.bin.ptr = reinterpret_cast<char const*>(&v.front());
if (size != 0) {
o.via.bin.ptr = reinterpret_cast<char const*>(&v.front());
}
o.via.bin.size = size;
}
};
Expand All @@ -71,10 +93,12 @@ struct object_with_zone<std::vector<unsigned char, Alloc> > {
void operator()(msgpack::object::with_zone& o, const std::vector<unsigned char, Alloc>& v) const {
uint32_t size = checked_get_container_size(v.size());
o.type = msgpack::type::BIN;
char* ptr = static_cast<char*>(o.zone.allocate_align(size));
o.via.bin.ptr = ptr;
o.via.bin.size = size;
std::memcpy(ptr, &v.front(), size);
if (size != 0) {
char* ptr = static_cast<char*>(o.zone.allocate_align(size));
o.via.bin.ptr = ptr;
std::memcpy(ptr, &v.front(), size);
}
}
};

Expand Down
Loading

0 comments on commit 39433e8

Please sign in to comment.