Repository: arrow Updated Branches: refs/heads/master f7ab7270b -> 53c093b52
ARROW-914 [C++/Python] Fix Decimal ToBytes Author: Phillip Cloud <[email protected]> Closes #613 from cpcloud/ARROW-914 and squashes the following commits: b0f3c10 [Phillip Cloud] Use a more appropriate name 418fc9c [Phillip Cloud] ARROW-914 [C++/Python] Fix Decimal ToBytes Project: http://git-wip-us.apache.org/repos/asf/arrow/repo Commit: http://git-wip-us.apache.org/repos/asf/arrow/commit/53c093b5 Tree: http://git-wip-us.apache.org/repos/asf/arrow/tree/53c093b5 Diff: http://git-wip-us.apache.org/repos/asf/arrow/diff/53c093b5 Branch: refs/heads/master Commit: 53c093b521d87794cba066032e827788c75d42fe Parents: f7ab727 Author: Phillip Cloud <[email protected]> Authored: Sat Apr 29 20:53:19 2017 -0400 Committer: Wes McKinney <[email protected]> Committed: Sat Apr 29 20:53:19 2017 -0400 ---------------------------------------------------------------------- ci/msvc-build.bat | 3 +-- cpp/src/arrow/util/decimal.cc | 8 ++++---- 2 files changed, 5 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/arrow/blob/53c093b5/ci/msvc-build.bat ---------------------------------------------------------------------- diff --git a/ci/msvc-build.bat b/ci/msvc-build.bat index 08c5033..aca1f8c 100644 --- a/ci/msvc-build.bat +++ b/ci/msvc-build.bat @@ -53,5 +53,4 @@ cd ..\..\python python setup.py build_ext --inplace || exit /B python -c "import pyarrow" || exit /B -@rem TODO: re-enable when last tests are fixed -@rem py.test pyarrow -v -s || exit /B +py.test pyarrow -v -s || exit /B http://git-wip-us.apache.org/repos/asf/arrow/blob/53c093b5/cpp/src/arrow/util/decimal.cc ---------------------------------------------------------------------- diff --git a/cpp/src/arrow/util/decimal.cc b/cpp/src/arrow/util/decimal.cc index 2fe9da4..3d9fbd3 100644 --- a/cpp/src/arrow/util/decimal.cc +++ b/cpp/src/arrow/util/decimal.cc @@ -147,7 +147,7 @@ void FromBytes(const uint8_t* bytes, Decimal64* decimal) { constexpr static const size_t BYTES_IN_128_BITS = 128 / CHAR_BIT; constexpr static const size_t LIMB_SIZE = sizeof(std::remove_pointer<int128_t::backend_type::limb_pointer>::type); -constexpr static const size_t BYTES_PER_LIMB = BYTES_IN_128_BITS / LIMB_SIZE; +constexpr static const size_t LIMBS_IN_INT128 = BYTES_IN_128_BITS / LIMB_SIZE; void FromBytes(const uint8_t* bytes, bool is_negative, Decimal128* decimal) { DCHECK_NE(bytes, nullptr); @@ -155,7 +155,7 @@ void FromBytes(const uint8_t* bytes, bool is_negative, Decimal128* decimal) { auto& decimal_value(decimal->value); int128_t::backend_type& backend(decimal_value.backend()); - backend.resize(BYTES_PER_LIMB, BYTES_PER_LIMB); + backend.resize(LIMBS_IN_INT128, LIMBS_IN_INT128); std::memcpy(backend.limbs(), bytes, BYTES_IN_128_BITS); if (is_negative) { decimal->value = -decimal->value; } } @@ -177,8 +177,8 @@ void ToBytes(const Decimal128& decimal, uint8_t** bytes, bool* is_negative) { /// TODO(phillipc): boost multiprecision is unreliable here, int128_t can't be /// roundtripped const auto& backend(decimal.value.backend()); - auto boost_bytes = reinterpret_cast<const uint8_t*>(backend.limbs()); - std::memcpy(*bytes, boost_bytes, BYTES_IN_128_BITS); + const size_t bytes_in_use = LIMB_SIZE * backend.size(); + std::memcpy(*bytes, backend.limbs(), bytes_in_use); *is_negative = backend.isneg(); }
