Update in-tree libosmium dependency to 2.5.4

The latest releases have some critical fixes, see the changelog:
https://github.com/osmcode/libosmium/blob/v2.5.4/CHANGELOG.md

Merge commit 'afdf8e7b21fbaf597e91d9d8a7542635e60ee9a1' into use_libosmium_2_5_4
This commit is contained in:
Daniel J. Hofmann
2016-01-05 12:00:40 +01:00
171 changed files with 7150 additions and 3988 deletions
+28 -6
View File
@@ -10,30 +10,51 @@ documentation.
*****************************************************************************/
/**
* @file byteswap.hpp
*
* @brief Contains functions to swap bytes in values (for different endianness).
*/
#include <cstdint>
#include <cassert>
#include <protozero/config.hpp>
namespace protozero {
/**
* Swap N byte value between endianness formats. This template function must
* be specialized to actually work.
*/
template <int N>
inline void byteswap(const char* /*data*/, char* /*result*/) {
assert(false);
}
template <>
inline void byteswap<1>(const char* data, char* result) {
result[0] = data[0];
static_assert(N == 1, "Can only swap 4 or 8 byte values");
}
/**
* Swap 4 byte value (int32_t, uint32_t, float) between endianness formats.
*/
template <>
inline void byteswap<4>(const char* data, char* result) {
#ifdef PROTOZERO_USE_BUILTIN_BSWAP
*reinterpret_cast<uint32_t*>(result) = __builtin_bswap32(*reinterpret_cast<const uint32_t*>(data));
#else
result[3] = data[0];
result[2] = data[1];
result[1] = data[2];
result[0] = data[3];
#endif
}
/**
* Swap 8 byte value (int64_t, uint64_t, double) between endianness formats.
*/
template <>
inline void byteswap<8>(const char* data, char* result) {
#ifdef PROTOZERO_USE_BUILTIN_BSWAP
*reinterpret_cast<uint64_t*>(result) = __builtin_bswap64(*reinterpret_cast<const uint64_t*>(data));
#else
result[7] = data[0];
result[6] = data[1];
result[5] = data[2];
@@ -42,6 +63,7 @@ inline void byteswap<8>(const char* data, char* result) {
result[2] = data[5];
result[1] = data[6];
result[0] = data[7];
#endif
}
} // end namespace protozero
+57
View File
@@ -0,0 +1,57 @@
#ifndef PROTOZERO_CONFIG_HPP
#define PROTOZERO_CONFIG_HPP
/*****************************************************************************
protozero - Minimalistic protocol buffer decoder and encoder in C++.
This file is from https://github.com/mapbox/protozero where you can find more
documentation.
*****************************************************************************/
#include <cassert>
/**
* @file config.hpp
*
* @brief Contains macro checks for different configurations.
*/
#define PROTOZERO_LITTLE_ENDIAN 1234
#define PROTOZERO_BIG_ENDIAN 4321
// Find out which byte order the machine has.
#if defined(__BYTE_ORDER)
# if (__BYTE_ORDER == __LITTLE_ENDIAN)
# define PROTOZERO_BYTE_ORDER PROTOZERO_LITTLE_ENDIAN
# endif
# if (__BYTE_ORDER == __BIG_ENDIAN)
# define PROTOZERO_BYTE_ORDER PROTOZERO_BIG_ENDIAN
# endif
#else
// This probably isn't a very good default, but might do until we figure
// out something better.
# define PROTOZERO_BYTE_ORDER PROTOZERO_LITTLE_ENDIAN
#endif
// On some ARM machines and depending on compiler settings access to unaligned
// floating point values will result in a SIGBUS. Do not use the bare pointers
// in this case.
#if PROTOZERO_BYTE_ORDER == PROTOZERO_LITTLE_ENDIAN
# if !defined(__arm__) && !defined(_M_ARM)
# define PROTOZERO_USE_BARE_POINTER_FOR_PACKED_FIXED
# endif
#endif
// Check whether __builtin_bswap is available
#if defined(__GNUC__) || defined(__clang__)
# define PROTOZERO_USE_BUILTIN_BSWAP
#endif
// Wrapper for assert() used for testing
#ifndef protozero_assert
# define protozero_assert(x) assert(x)
#endif
#endif // PROTOZERO_CONFIG_HPP
+27 -1
View File
@@ -10,6 +10,12 @@ documentation.
*****************************************************************************/
/**
* @file pbf_builder.hpp
*
* @brief Contains the pbf_builder template class.
*/
#include <type_traits>
#include <protozero/pbf_types.hpp>
@@ -17,10 +23,22 @@ documentation.
namespace protozero {
/**
* The pbf_builder is used to write PBF formatted messages into a buffer. It
* is based on the pbf_writer class and has all the same methods. The
* difference is that whereever the pbf_writer class takes an integer tag,
* this template class takes a tag of the template type T.
*
* Almost all methods in this class can throw an std::bad_alloc exception if
* the std::string used as a buffer wants to resize.
*
* Read the tutorial to understand how this class is used.
*/
template <typename T>
class pbf_builder : public pbf_writer {
static_assert(std::is_same<pbf_tag_type, typename std::underlying_type<T>::type>::value, "T must be enum with underlying type protozero::pbf_tag_type");
static_assert(std::is_same<pbf_tag_type, typename std::underlying_type<T>::type>::value,
"T must be enum with underlying type protozero::pbf_tag_type");
public:
@@ -35,6 +53,7 @@ public:
pbf_writer(parent_writer, pbf_tag_type(tag)) {
}
/// @cond INTERNAL
#define PROTOZERO_WRITER_WRAP_ADD_SCALAR(name, type) \
inline void add_##name(T tag, type value) { \
pbf_writer::add_##name(pbf_tag_type(tag), value); \
@@ -55,6 +74,9 @@ public:
PROTOZERO_WRITER_WRAP_ADD_SCALAR(float, float)
PROTOZERO_WRITER_WRAP_ADD_SCALAR(double, double)
#undef PROTOZERO_WRITER_WRAP_ADD_SCALAR
/// @endcond
inline void add_bytes(T tag, const char* value, size_t size) {
pbf_writer::add_bytes(pbf_tag_type(tag), value, size);
}
@@ -83,6 +105,7 @@ public:
pbf_writer::add_message(pbf_tag_type(tag), value);
}
/// @cond INTERNAL
#define PROTOZERO_WRITER_WRAP_ADD_PACKED(name) \
template <typename InputIterator> \
inline void add_packed_##name(T tag, InputIterator first, InputIterator last) { \
@@ -104,6 +127,9 @@ public:
PROTOZERO_WRITER_WRAP_ADD_PACKED(float)
PROTOZERO_WRITER_WRAP_ADD_PACKED(double)
#undef PROTOZERO_WRITER_WRAP_ADD_PACKED
/// @endcond
};
} // end namespace protozero
+44
View File
@@ -10,6 +10,12 @@ documentation.
*****************************************************************************/
/**
* @file pbf_message.hpp
*
* @brief Contains the pbf_message class.
*/
#include <type_traits>
#include <protozero/pbf_reader.hpp>
@@ -17,6 +23,44 @@ documentation.
namespace protozero {
/**
* This class represents a protobuf message. Either a top-level message or
* a nested sub-message. Top-level messages can be created from any buffer
* with a pointer and length:
*
* @code
* enum class Message : protozero::pbf_tag_type {
* ...
* };
*
* std::string buffer;
* // fill buffer...
* pbf_message<Message> message(buffer.data(), buffer.size());
* @endcode
*
* Sub-messages are created using get_message():
*
* @code
* enum class SubMessage : protozero::pbf_tag_type {
* ...
* };
*
* pbf_message<Message> message(...);
* message.next();
* pbf_message<SubMessage> submessage = message.get_message();
* @endcode
*
* All methods of the pbf_message class except get_bytes() and get_string()
* provide the strong exception guarantee, ie they either succeed or do not
* change the pbf_message object they are called on. Use the get_data() method
* instead of get_bytes() or get_string(), if you need this guarantee.
*
* This template class is based on the pbf_reader class and has all the same
* methods. The difference is that whereever the pbf_reader class takes an
* integer tag, this template class takes a tag of the template type T.
*
* Read the tutorial to understand how this class is used.
*/
template <typename T>
class pbf_message : public pbf_reader {
+29 -17
View File
@@ -16,7 +16,6 @@ documentation.
* @brief Contains the pbf_reader class.
*/
#include <cassert>
#include <cstddef>
#include <cstdint>
#include <cstring>
@@ -24,19 +23,15 @@ documentation.
#include <string>
#include <utility>
#include <protozero/pbf_types.hpp>
#include <protozero/config.hpp>
#include <protozero/exception.hpp>
#include <protozero/pbf_types.hpp>
#include <protozero/varint.hpp>
#if __BYTE_ORDER != __LITTLE_ENDIAN
#if PROTOZERO_BYTE_ORDER != PROTOZERO_LITTLE_ENDIAN
# include <protozero/byteswap.hpp>
#endif
/// Wrapper for assert() used for testing
#ifndef protozero_assert
# define protozero_assert(x) assert(x)
#endif
namespace protozero {
/**
@@ -77,19 +72,27 @@ class pbf_reader {
// The tag of the current field.
pbf_tag_type m_tag = 0;
// Copy N bytes from src to dest on little endian machines, on big endian
// swap the bytes in the process.
template <int N>
static void copy_or_byteswap(const char* src, void* dest) noexcept {
#if PROTOZERO_BYTE_ORDER == PROTOZERO_LITTLE_ENDIAN
memcpy(dest, src, N);
#else
byteswap<N>(src, reinterpret_cast<char*>(dest));
#endif
}
template <typename T>
inline T get_fixed() {
T result;
skip_bytes(sizeof(T));
#if __BYTE_ORDER == __LITTLE_ENDIAN
memcpy(&result, m_data - sizeof(T), sizeof(T));
#else
byteswap<sizeof(T)>(m_data - sizeof(T), reinterpret_cast<char*>(&result));
#endif
copy_or_byteswap<sizeof(T)>(m_data - sizeof(T), &result);
return result;
}
#if __BYTE_ORDER == __LITTLE_ENDIAN
#ifdef PROTOZERO_USE_BARE_POINTER_FOR_PACKED_FIXED
template <typename T>
inline std::pair<const T*, const T*> packed_fixed() {
protozero_assert(tag() != 0 && "call next() before accessing field value");
@@ -128,7 +131,7 @@ class pbf_reader {
T operator*() {
T result;
byteswap<sizeof(T)>(m_data, reinterpret_cast<char*>(&result));
copy_or_byteswap<sizeof(T)>(m_data , &result);
return result;
}
@@ -161,6 +164,7 @@ class pbf_reader {
return std::make_pair(const_fixed_iterator<T>(m_data-len, m_data),
const_fixed_iterator<T>(m_data, m_data));
}
#endif
template <typename T> inline T get_varint();
@@ -866,8 +870,16 @@ bool pbf_reader::next() {
protozero_assert(((m_tag > 0 && m_tag < 19000) || (m_tag > 19999 && m_tag <= ((1 << 29) - 1))) && "tag out of range");
m_wire_type = pbf_wire_type(value & 0x07);
// XXX do we want this check? or should it throw an exception?
// protozero_assert((m_wire_type <=2 || m_wire_type == 5) && "illegal wire type");
switch (m_wire_type) {
case pbf_wire_type::varint:
case pbf_wire_type::fixed64:
case pbf_wire_type::length_delimited:
case pbf_wire_type::fixed32:
break;
default:
throw unknown_pbf_wire_type_exception();
}
return true;
}
+7 -10
View File
@@ -16,7 +16,6 @@ documentation.
* @brief Contains the pbf_writer class.
*/
#include <cassert>
#include <cstddef>
#include <cstdint>
#include <cstring>
@@ -24,18 +23,14 @@ documentation.
#include <limits>
#include <string>
#include <protozero/config.hpp>
#include <protozero/pbf_types.hpp>
#include <protozero/varint.hpp>
#if __BYTE_ORDER != __LITTLE_ENDIAN
#if PROTOZERO_BYTE_ORDER != PROTOZERO_LITTLE_ENDIAN
# include <protozero/byteswap.hpp>
#endif
/// Wrapper for assert() used for testing
#ifndef protozero_assert
# define protozero_assert(x) assert(x)
#endif
namespace protozero {
/**
@@ -71,7 +66,7 @@ class pbf_writer {
inline void add_fixed(T value) {
protozero_assert(m_pos == 0 && "you can't add fields to a parent pbf_writer if there is an existing pbf_writer for a submessage");
protozero_assert(m_data);
#if __BYTE_ORDER == __LITTLE_ENDIAN
#if PROTOZERO_BYTE_ORDER == PROTOZERO_LITTLE_ENDIAN
m_data->append(reinterpret_cast<const char*>(&value), sizeof(T));
#else
auto size = m_data->size();
@@ -229,7 +224,9 @@ public:
*/
inline void add_bool(pbf_tag_type tag, bool value) {
add_field(tag, pbf_wire_type::varint);
add_fixed<char>(value);
protozero_assert(m_pos == 0 && "you can't add fields to a parent pbf_writer if there is an existing pbf_writer for a submessage");
protozero_assert(m_data);
m_data->append(1, value);
}
/**
@@ -378,7 +375,7 @@ public:
inline void add_bytes(pbf_tag_type tag, const char* value, size_t size) {
protozero_assert(m_pos == 0 && "you can't add fields to a parent pbf_writer if there is an existing pbf_writer for a submessage");
protozero_assert(m_data);
assert(size <= std::numeric_limits<pbf_length_type>::max());
protozero_assert(size <= std::numeric_limits<pbf_length_type>::max());
add_length_varint(tag, pbf_length_type(size));
m_data->append(value, size);
}
-4
View File
@@ -16,10 +16,6 @@ documentation.
* @brief Contains low-level varint and zigzag encoding and decoding functions.
*/
#if __BYTE_ORDER != __LITTLE_ENDIAN
# error "This code only works on little endian machines."
#endif
#include <cstdint>
#include <protozero/exception.hpp>
+22
View File
@@ -0,0 +1,22 @@
#ifndef PROTOZERO_VERSION_HPP
#define PROTOZERO_VERSION_HPP
/*****************************************************************************
protozero - Minimalistic protocol buffer decoder and encoder in C++.
This file is from https://github.com/mapbox/protozero where you can find more
documentation.
*****************************************************************************/
#define PROTOZERO_VERSION_MAJOR 1
#define PROTOZERO_VERSION_MINOR 2
#define PROTOZERO_VERSION_PATCH 3
#define PROTOZERO_VERSION_CODE (PROTOZERO_VERSION_MAJOR * 10000 + PROTOZERO_VERSION_MINOR * 100 + PROTOZERO_VERSION_PATCH)
#define PROTOZERO_VERSION_STRING "1.2.3"
#endif // PROTOZERO_VERSION_HPP