Boost logo

Boost-Commit :

From: zeux_at_[hidden]
Date: 2007-05-21 12:16:01


Author: zeux
Date: 2007-05-21 12:16:00 EDT (Mon, 21 May 2007)
New Revision: 4157
URL: http://svn.boost.org/trac/boost/changeset/4157

Log:
Warnings fixed, added config + setting the best implementation as default, completed other pending tasks, todo.txt fixed

Added:
   sandbox/SOC/2007/bigint/boost/bigint/bigint_config.hpp
Text files modified:
   sandbox/SOC/2007/bigint/boost/bigint/bigint.hpp | 11 +++++++++++
   sandbox/SOC/2007/bigint/boost/bigint/bigint_gmp.hpp | 4 ++--
   sandbox/SOC/2007/bigint/libs/bigint/test/bigint_simple_test.cpp | 4 ++--
   sandbox/SOC/2007/bigint/libs/bigint/todo.txt | 35 +++++++++++++++++++++++++----------
   4 files changed, 40 insertions(+), 14 deletions(-)

Modified: sandbox/SOC/2007/bigint/boost/bigint/bigint.hpp
==============================================================================
--- sandbox/SOC/2007/bigint/boost/bigint/bigint.hpp (original)
+++ sandbox/SOC/2007/bigint/boost/bigint/bigint.hpp 2007-05-21 12:16:00 EDT (Mon, 21 May 2007)
@@ -14,6 +14,7 @@
 
 #include <boost/cstdint.hpp>
 
+#include <boost/bigint/bigint_config.hpp>
 #include <boost/bigint/bigint_util.hpp>
 
 namespace boost {
@@ -406,6 +407,9 @@
 
 } // namespace boost
 
+// Do we have GMP?
+#ifdef BOOST_BIGINT_HAS_GMP_SUPPORT
+
 #include <boost/bigint/bigint_gmp.hpp>
 
 namespace boost {
@@ -414,4 +418,11 @@
 
 } // namespace boost
 
+#else
+
+// The default implementation should be here, but there's none yet
+#error "No default implementation for now"
+
+#endif
+
 #endif // BOOST_BIGINT_BIGINT_HPP

Added: sandbox/SOC/2007/bigint/boost/bigint/bigint_config.hpp
==============================================================================
--- (empty file)
+++ sandbox/SOC/2007/bigint/boost/bigint/bigint_config.hpp 2007-05-21 12:16:00 EDT (Mon, 21 May 2007)
@@ -0,0 +1,16 @@
+/* Boost bigint_config.hpp header file
+ *
+ * Copyright 2007 Arseny Kapoulkine
+ *
+ * Distributed under the Boost Software License, Version 1.0.
+ * (See accompanying file LICENSE_1_0.txt or
+ * copy at http://www.boost.org/LICENSE_1_0.txt)
+ */
+
+#ifndef BOOST_BIGINT_BIGINT_CONFIG_HPP
+#define BOOST_BIGINT_BIGINT_CONFIG_HPP
+
+// Define it if GMP implementation is present
+#define BOOST_BIGINT_HAS_GMP_SUPPORT
+
+#endif // BOOST_BIGINT_BIGINT_CONFIG_HPP

Modified: sandbox/SOC/2007/bigint/boost/bigint/bigint_gmp.hpp
==============================================================================
--- sandbox/SOC/2007/bigint/boost/bigint/bigint_gmp.hpp (original)
+++ sandbox/SOC/2007/bigint/boost/bigint/bigint_gmp.hpp 2007-05-21 12:16:00 EDT (Mon, 21 May 2007)
@@ -134,13 +134,13 @@
                         
                         for (size_t i = 0; i < d_size; ++i)
                         {
- if (*str < 0 || *str > 127 || digit_value_tab[*str] >= base)
+ if (*str < 0 || *str > 127 || digit_value_tab[static_cast<unsigned int>(*str)] >= base)
                                 {
                                         d_size = i;
                                         break;
                                 }
                                 
- d[i] = digit_value_tab[*str++];
+ d[i] = digit_value_tab[static_cast<unsigned int>(*str++)];
                         }
                         
                         if (d_size == 0)

Modified: sandbox/SOC/2007/bigint/libs/bigint/test/bigint_simple_test.cpp
==============================================================================
--- sandbox/SOC/2007/bigint/libs/bigint/test/bigint_simple_test.cpp (original)
+++ sandbox/SOC/2007/bigint/libs/bigint/test/bigint_simple_test.cpp 2007-05-21 12:16:00 EDT (Mon, 21 May 2007)
@@ -39,7 +39,7 @@
         BOOST_CHECK(a);
 
         BOOST_CHECK_EQUAL(a * b, bigint("42258228219342334666689684483132205000478474"));
- BOOST_CHECK_EQUAL(!(a / b), 0);
+ BOOST_CHECK_EQUAL(!(a / b), false);
         BOOST_CHECK_EQUAL(a % b, bigint("1645142448812923432790"));
 
         BOOST_CHECK_EQUAL(a | b, bigint("13870766920526448295931"));
@@ -114,7 +114,7 @@
 
         BOOST_CHECK_EQUAL(bigint("ffffffff", 16).to_number<unsigned int>(), 0xffffffff);
         BOOST_CHECK_EQUAL(bigint("7fffffff", 16).to_number<int>(), 0x7fffffff);
- BOOST_CHECK_EQUAL(bigint("-80000000", 16).to_number<int>(), -0x80000000);
+ BOOST_CHECK_EQUAL(bigint("-80000000", 16).to_number<int>(), -static_cast<boost::int64_t>(0x80000000));
         
         // 3 == 11
         // -3 = 1....1101

Modified: sandbox/SOC/2007/bigint/libs/bigint/todo.txt
==============================================================================
--- sandbox/SOC/2007/bigint/libs/bigint/todo.txt (original)
+++ sandbox/SOC/2007/bigint/libs/bigint/todo.txt 2007-05-21 12:16:00 EDT (Mon, 21 May 2007)
@@ -10,7 +10,7 @@
 
 Feature name Deadline Status
 ------------ -------- ------
-1. Bigint interface (header) 21 May Draft completed, waiting for input from the community
+1. Bigint interface (header) 21 May Awaiting resolution
 2. GMP implementation 21 May In progress
 3. Correctness tests 7 June N/A
 4. Documentation 21 June N/A
@@ -48,14 +48,16 @@
 * make sure it works on a wide range of compilers (test framework setup is needed)
 Status: made some setup, it works for me but: 1. linking gmp is done via a hack, 2. not sure it works for others :/
 
-- converting to/from string - there was a suggestion to use static functions
++ converting to/from string - there was a suggestion to use static functions
 My opinion: performance wise it is the same if compiler has NRVO support, and ctors/member functions are more convenient
-Status: get Jeffs opinion, wait for further community feedback
+Status: leaving it as is for now. Changing it later it trivial anyway.
 
-- make the bigint typedef depend on the available implementations (choose the most advanced instead of default one)
++ make the bigint typedef depend on the available implementations (choose the most advanced instead of default one)
 My opinion: seems worthwhile
-Status: get Jeffs opinion, wait for further community feedback
-Comments: some set of defines is probably needed, like BOOST_BIGINT_HAS_GMP_SUPPORT, etc.
+Status: implemented
+
++ remove warnings for both MSVC and GCC
+Status: all non-GMP-implementation-specific warnings were fixed
 
 2. GMP implementation
 
@@ -83,11 +85,24 @@
 + check semantics of bitwise and shift operations for negative numbers
 Status: investigated, bitwise and shift operations behave as if numbers were 2-complement (as expected).
 
-- what if there is not enough memory for the request - what happens then? Investigate.
-Status: needs investigation
++ what if there is not enough memory for the request - what happens then? Investigate.
+Status: investigated. abort() is called in this case. The solution for this is complex - read below.
+
+- remove warnings for both MSVC and GCC
+Status: needs fixing
+
+-----------------------------------------------
+
+Problem: GMP calls abort() when failing to allocate memory.
+
+Solution: GMP allocates memory in various places - mainly temporary storage and limb allocation. I don't know for now if limb
+allocation will be a problem (because if an extra feature "make GMP work with arbitrary storage strategy" is implemented,
+all limb allocation will be done by bigint library). Temporary storage allocation is a problem. Just providing own allocation
+functions to GMP and having them throw an exception is not a generic solution, because GMP is not exception safe. However, it
+may be a solution IF own allocation is performed - depends on where allocations are done - needs further investigation.
 
-- more changes according to interface updates
-Status: waiting for updates
+Alternatively, only parts of GMP that actually are thread safe may be rewritten (if they do not include system layer (mpn), of
+course).
 
 -----------------------------------------------
 Extra features:


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