From 418fc9c85d9532719d95dfc62ed5de9be74f084b Mon Sep 17 00:00:00 2001 From: Phillip Cloud Date: Sat, 29 Apr 2017 17:49:38 -0400 Subject: [PATCH 1/2] ARROW-914 [C++/Python] Fix Decimal ToBytes --- ci/msvc-build.bat | 3 +-- cpp/src/arrow/util/decimal.cc | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/ci/msvc-build.bat b/ci/msvc-build.bat index 08c50338495..aca1f8cc3c0 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 diff --git a/cpp/src/arrow/util/decimal.cc b/cpp/src/arrow/util/decimal.cc index 2fe9da4aba9..7e5f86d6b8b 100644 --- a/cpp/src/arrow/util/decimal.cc +++ b/cpp/src/arrow/util/decimal.cc @@ -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(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(); } From b0f3c10f660867753bc8aac40c0b0879907a14da Mon Sep 17 00:00:00 2001 From: Phillip Cloud Date: Sat, 29 Apr 2017 18:17:36 -0400 Subject: [PATCH 2/2] Use a more appropriate name --- cpp/src/arrow/util/decimal.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cpp/src/arrow/util/decimal.cc b/cpp/src/arrow/util/decimal.cc index 7e5f86d6b8b..3d9fbd31bf2 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::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; } }