Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r85214 - in trunk: boost/multiprecision/cpp_int libs/multiprecision/test
From: john_at_[hidden]
Date: 2013-08-05 11:03:07


Author: johnmaddock
Date: 2013-08-05 11:03:07 EDT (Mon, 05 Aug 2013)
New Revision: 85214
URL: http://svn.boost.org/trac/boost/changeset/85214

Log:
Fix gcc serialization code, and improve binary serialization.

Text files modified:
   trunk/boost/multiprecision/cpp_int/serialize.hpp | 23 ++++++++++-------------
   trunk/libs/multiprecision/test/test_cpp_int_serial.cpp | 4 +---
   2 files changed, 11 insertions(+), 16 deletions(-)

Modified: trunk/boost/multiprecision/cpp_int/serialize.hpp
==============================================================================
--- trunk/boost/multiprecision/cpp_int/serialize.hpp Mon Aug 5 08:22:53 2013 (r85213)
+++ trunk/boost/multiprecision/cpp_int/serialize.hpp 2013-08-05 11:03:07 EDT (Mon, 05 Aug 2013) (r85214)
@@ -57,10 +57,9 @@
       pl[i] = 0;
       for(std::size_t j = 0; j < sizeof(limb_type); ++j)
       {
- limb_type byte;
+ unsigned char byte;
          ar & byte;
- byte <<= (j * CHAR_BIT);
- pl[i] |= byte;
+ pl[i] |= static_cast<limb_type>(byte) << (j * CHAR_BIT);
       }
    }
    if(s != val.sign())
@@ -86,7 +85,7 @@
       limb_type l = pl[i];
       for(std::size_t j = 0; j < sizeof(limb_type); ++j)
       {
- unsigned byte = (l >> (j * CHAR_BIT)) & ((1u << CHAR_BIT) - 1);
+ unsigned char byte = static_cast<unsigned char>((l >> (j * CHAR_BIT)) & ((1u << CHAR_BIT) - 1));
          ar & byte;
       }
    }
@@ -104,9 +103,9 @@
    ar & limb_count;
    for(std::size_t i = 0; i < limb_count; ++i)
    {
- typename Int::local_limb_type b;
+ unsigned char b;
       ar & b;
- l |= b << (i * CHAR_BIT);
+ l |= static_cast<typename Int::local_limb_type>(b) << (i * CHAR_BIT);
    }
    *val.limbs() = l;
    if(s != val.sign())
@@ -125,7 +124,7 @@
    ar & limb_count;
    for(std::size_t i = 0; i < limb_count; ++i)
    {
- typename Int::local_limb_type b = static_cast<typename Int::local_limb_type>(l >> (i * CHAR_BIT)) & static_cast<typename Int::local_limb_type>((1u << CHAR_BIT) - 1);
+ unsigned char b = static_cast<unsigned char>(static_cast<typename Int::local_limb_type>(l >> (i * CHAR_BIT)) & static_cast<typename Int::local_limb_type>((1u << CHAR_BIT) - 1));
       ar & b;
    }
 }
@@ -140,8 +139,7 @@
    ar & s;
    ar & c;
    val.resize(c, c);
- for(unsigned i = 0; i < c; ++i)
- ar & val.limbs()[i];
+ ar.load_binary(val.limbs(), c);
    if(s != val.sign())
       val.negate();
    val.normalize();
@@ -156,8 +154,7 @@
    std::size_t c = val.size();
    ar & s;
    ar & c;
- for(unsigned i = 0; i < c; ++i)
- ar & val.limbs()[i];
+ ar.save_binary(val.limbs(), c);
 }
 template <class Archive, class Int>
 void do_serialize(Archive& ar, Int& val, mpl::false_ const&, mpl::true_ const&, mpl::true_ const&)
@@ -167,7 +164,7 @@
    // Binary.
    bool s;
    ar & s;
- ar & *val.limbs();
+ ar.load_binary(val.limbs(), sizeof(*val.limbs()));
    if(s != val.sign())
       val.negate();
 }
@@ -179,7 +176,7 @@
    // Binary.
    bool s = val.sign();
    ar & s;
- ar & *val.limbs();
+ ar.save_binary(val.limbs(), sizeof(*val.limbs()));
 }
 
 }

Modified: trunk/libs/multiprecision/test/test_cpp_int_serial.cpp
==============================================================================
--- trunk/libs/multiprecision/test/test_cpp_int_serial.cpp Mon Aug 5 08:22:53 2013 (r85213)
+++ trunk/libs/multiprecision/test/test_cpp_int_serial.cpp 2013-08-05 11:03:07 EDT (Mon, 05 Aug 2013) (r85214)
@@ -75,12 +75,11 @@
    boost::archive::binary_oarchive ob(ss);
    ob << static_cast<const T&>(val);
    boost::archive::binary_iarchive ib(ss);
- val2;
    ib >> val2;
    BOOST_CHECK_EQUAL(val, val2);
 }
 template <class T>
-void test_neg(const T& val, const boost::mpl::false_&){}
+void test_neg(const T& , const boost::mpl::false_&){}
 
 template <class T>
 void test()
@@ -106,7 +105,6 @@
       boost::archive::binary_oarchive ob(ss);
       ob << static_cast<const T&>(val);
       boost::archive::binary_iarchive ib(ss);
- val2;
       ib >> val2;
       BOOST_CHECK_EQUAL(val, val2);
       


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk