[protozero] 01/05: Imported Upstream version 1.4.4

Bas Couwenberg sebastic at debian.org
Tue Nov 15 21:22:11 UTC 2016


This is an automated email from the git hooks/post-receive script.

sebastic pushed a commit to branch master
in repository protozero.

commit a927812d87ed1908b3debb782a915ba6135f4565
Author: Bas Couwenberg <sebastic at xs4all.nl>
Date:   Tue Nov 15 22:14:24 2016 +0100

    Imported Upstream version 1.4.4
---
 CHANGELOG.md                     | 10 +++++++++-
 CONTRIBUTING.md                  |  7 +++++--
 include/protozero/byteswap.hpp   | 30 ++++++++++++++++++++++++++----
 include/protozero/iterators.hpp  |  2 +-
 include/protozero/pbf_reader.hpp |  2 +-
 include/protozero/pbf_writer.hpp |  2 +-
 include/protozero/version.hpp    |  4 ++--
 package.json                     |  2 +-
 test/t/endian/test_cases.cpp     | 29 +++++++++++++++++++++++++----
 9 files changed, 71 insertions(+), 17 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 24ef9a8..46af379 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -13,6 +13,13 @@ This project adheres to [Semantic Versioning](http://semver.org/).
 ### Fixed
 
 
+## [1.4.4] - 2016-11-15
+
+### Fixed
+
+- Byteswap implementation.
+
+
 ## [1.4.3] - 2016-11-15
 
 ### Fixed
@@ -116,7 +123,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
 - Make pbf reader and writer code endianess-aware.
 
 
-[unreleased]: https://github.com/osmcode/libosmium/compare/v1.4.3...HEAD
+[unreleased]: https://github.com/osmcode/libosmium/compare/v1.4.4...HEAD
+[1.4.4]: https://github.com/osmcode/libosmium/compare/v1.4.3...v1.4.4
 [1.4.3]: https://github.com/osmcode/libosmium/compare/v1.4.2...v1.4.3
 [1.4.2]: https://github.com/osmcode/libosmium/compare/v1.4.1...v1.4.2
 [1.4.1]: https://github.com/osmcode/libosmium/compare/v1.4.0...v1.4.1
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 8528cdd..089e9d0 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -10,8 +10,11 @@ To release a new protozero version:
    - package.json
  - Update CHANGELOG.md
    (don't forget links at the bottom of the file)
- - Update UPGRADING.md
- - Create a new tag and push to github `git push --tags`
+ - Update UPGRADING.md if necessary
+ - `git commit -m "Release X.Y.Z" include/protozero/version.hpp package.json CHANGELOG.md UPGRADING.md`
+ - `git tag vX.Y.Z`
+ - `git push`
+ - `git push --tags`
  - Go to https://github.com/mapbox/protozero/releases
    and edit the new release. Put "Version x.y.z" in title and
    cut-and-paste entry from CHANGELOG.md.
diff --git a/include/protozero/byteswap.hpp b/include/protozero/byteswap.hpp
index 9de42a2..3afb348 100644
--- a/include/protozero/byteswap.hpp
+++ b/include/protozero/byteswap.hpp
@@ -18,7 +18,6 @@ documentation.
 
 #include <cstdint>
 #include <cassert>
-#include <type_traits>
 
 #include <protozero/config.hpp>
 
@@ -51,9 +50,32 @@ inline uint64_t byteswap_impl(uint64_t value) noexcept {
 #endif
 }
 
-template <typename T>
-inline void byteswap_inplace(T& value) noexcept {
-    value = static_cast<T>(byteswap_impl(static_cast<typename std::make_unsigned<T>::type>(value)));
+inline void byteswap_inplace(uint32_t* ptr) noexcept {
+    *ptr = byteswap_impl(*ptr);
+}
+
+inline void byteswap_inplace(uint64_t* ptr) noexcept {
+    *ptr = byteswap_impl(*ptr);
+}
+
+inline void byteswap_inplace(int32_t* ptr) noexcept {
+    auto bptr = reinterpret_cast<uint32_t*>(ptr);
+    *bptr = byteswap_impl(*bptr);
+}
+
+inline void byteswap_inplace(int64_t* ptr) noexcept {
+    auto bptr = reinterpret_cast<uint64_t*>(ptr);
+    *bptr = byteswap_impl(*bptr);
+}
+
+inline void byteswap_inplace(float* ptr) noexcept {
+    auto bptr = reinterpret_cast<uint32_t*>(ptr);
+    *bptr = byteswap_impl(*bptr);
+}
+
+inline void byteswap_inplace(double* ptr) noexcept {
+    auto bptr = reinterpret_cast<uint64_t*>(ptr);
+    *bptr = byteswap_impl(*bptr);
 }
 
 } // end namespace detail
diff --git a/include/protozero/iterators.hpp b/include/protozero/iterators.hpp
index c3107b5..40259a9 100644
--- a/include/protozero/iterators.hpp
+++ b/include/protozero/iterators.hpp
@@ -200,7 +200,7 @@ public:
         value_type result;
         std::memcpy(&result, m_data, sizeof(value_type));
 #if PROTOZERO_BYTE_ORDER != PROTOZERO_LITTLE_ENDIAN
-        detail::byteswap_inplace(result);
+        detail::byteswap_inplace(&result);
 #endif
         return result;
     }
diff --git a/include/protozero/pbf_reader.hpp b/include/protozero/pbf_reader.hpp
index 6187fc2..69f2d72 100644
--- a/include/protozero/pbf_reader.hpp
+++ b/include/protozero/pbf_reader.hpp
@@ -77,7 +77,7 @@ class pbf_reader {
         skip_bytes(sizeof(T));
         std::memcpy(&result, m_data - sizeof(T), sizeof(T));
 #if PROTOZERO_BYTE_ORDER != PROTOZERO_LITTLE_ENDIAN
-        detail::byteswap_inplace(result);
+        detail::byteswap_inplace(&result);
 #endif
         return result;
     }
diff --git a/include/protozero/pbf_writer.hpp b/include/protozero/pbf_writer.hpp
index 5a9f114..77cc9d0 100644
--- a/include/protozero/pbf_writer.hpp
+++ b/include/protozero/pbf_writer.hpp
@@ -91,7 +91,7 @@ class pbf_writer {
         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 PROTOZERO_BYTE_ORDER != PROTOZERO_LITTLE_ENDIAN
-        detail::byteswap_inplace(value);
+        detail::byteswap_inplace(&value);
 #endif
         m_data->append(reinterpret_cast<const char*>(&value), sizeof(T));
     }
diff --git a/include/protozero/version.hpp b/include/protozero/version.hpp
index fbaaaf1..c3e91a3 100644
--- a/include/protozero/version.hpp
+++ b/include/protozero/version.hpp
@@ -23,13 +23,13 @@ documentation.
 #define PROTOZERO_VERSION_MINOR 4
 
 /// The patch number
-#define PROTOZERO_VERSION_PATCH 3
+#define PROTOZERO_VERSION_PATCH 4
 
 /// The complete version number
 #define PROTOZERO_VERSION_CODE (PROTOZERO_VERSION_MAJOR * 10000 + PROTOZERO_VERSION_MINOR * 100 + PROTOZERO_VERSION_PATCH)
 
 /// Version number as string
-#define PROTOZERO_VERSION_STRING "1.4.3"
+#define PROTOZERO_VERSION_STRING "1.4.4"
 
 
 #endif // PROTOZERO_VERSION_HPP
diff --git a/package.json b/package.json
index 4bb4b21..3208303 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
     "name": "protozero",
-    "version": "1.4.3",
+    "version": "1.4.4",
     "description": "Minimalist protocol buffer decoder and encoder in C++",
     "main": "include_dirs.js",
     "repository"   :  {
diff --git a/test/t/endian/test_cases.cpp b/test/t/endian/test_cases.cpp
index da36f48..6e39c41 100644
--- a/test/t/endian/test_cases.cpp
+++ b/test/t/endian/test_cases.cpp
@@ -1,5 +1,6 @@
 
 #include <cstdint>
+#include <limits>
 
 #include <test.hpp>
 
@@ -8,14 +9,14 @@
 namespace {
 
     int32_t check_swap_4(int32_t data) {
-        protozero::detail::byteswap_inplace(data);
-        protozero::detail::byteswap_inplace(data);
+        protozero::detail::byteswap_inplace(&data);
+        protozero::detail::byteswap_inplace(&data);
         return data;
     }
 
     int64_t check_swap_8(int64_t data) {
-        protozero::detail::byteswap_inplace(data);
-        protozero::detail::byteswap_inplace(data);
+        protozero::detail::byteswap_inplace(&data);
+        protozero::detail::byteswap_inplace(&data);
         return data;
     }
 
@@ -27,6 +28,8 @@ TEST_CASE("byte swapping") {
     REQUIRE(-1 == check_swap_4(-1));
     REQUIRE(395503 == check_swap_4(395503));
     REQUIRE(-804022 == check_swap_4(-804022));
+    REQUIRE(std::numeric_limits<int32_t>::max() == check_swap_4(std::numeric_limits<int32_t>::max()));
+    REQUIRE(std::numeric_limits<int32_t>::min() == check_swap_4(std::numeric_limits<int32_t>::min()));
 
     REQUIRE(0 == check_swap_8(0));
     REQUIRE(1 == check_swap_8(1));
@@ -35,5 +38,23 @@ TEST_CASE("byte swapping") {
     REQUIRE(-804022 == check_swap_8(-804022));
     REQUIRE(3280329805 == check_swap_8(3280329805));
     REQUIRE(-2489204041 == check_swap_8(-2489204041));
+    REQUIRE(std::numeric_limits<int64_t>::max() == check_swap_8(std::numeric_limits<int64_t>::max()));
+    REQUIRE(std::numeric_limits<int64_t>::min() == check_swap_8(std::numeric_limits<int64_t>::min()));
+}
+
+TEST_CASE("byte swap double") {
+    double a = 1.1;
+    protozero::detail::byteswap_inplace(&a);
+    protozero::detail::byteswap_inplace(&a);
+
+    REQUIRE(1.1 == a);
+}
+
+TEST_CASE("byte swap float") {
+    float a = 1.1f;
+    protozero::detail::byteswap_inplace(&a);
+    protozero::detail::byteswap_inplace(&a);
+
+    REQUIRE(1.1f == a);
 }
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-grass/protozero.git



More information about the Pkg-grass-devel mailing list