Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r63696 - trunk/boost/python/converter
From: rwgk_at_[hidden]
Date: 2010-07-06 10:29:26


Author: rwgk
Date: 2010-07-06 10:29:25 EDT (Tue, 06 Jul 2010)
New Revision: 63696
URL: http://svn.boost.org/trac/boost/changeset/63696

Log:
boost/python/converter/builtin_converters.hpp: 64-bit Windows special case to avoid getting a Python long for each std::size_t
Text files modified:
   trunk/boost/python/converter/builtin_converters.hpp | 27 ++++++++++++++++++++++++---
   1 files changed, 24 insertions(+), 3 deletions(-)

Modified: trunk/boost/python/converter/builtin_converters.hpp
==============================================================================
--- trunk/boost/python/converter/builtin_converters.hpp (original)
+++ trunk/boost/python/converter/builtin_converters.hpp 2010-07-06 10:29:25 EDT (Tue, 06 Jul 2010)
@@ -122,9 +122,30 @@
 BOOST_PYTHON_TO_INT(int)
 BOOST_PYTHON_TO_INT(long)
 
-// using Python's macro instead of Boost's - we don't seem to get the
-// config right all the time.
-# ifdef HAVE_LONG_LONG
+# if defined(_MSC_VER) && defined(_WIN64)
+/* Under 64-bit Windows std::size_t is "unsigned long long". To avoid
+ getting a Python long for each std::size_t the value is checked before
+ the conversion. A std::size_t is converted to a simple Python int
+ if possible; a Python long appears only if the value is too small or
+ too large to fit into a simple int. */
+BOOST_PYTHON_TO_PYTHON_BY_VALUE(
+ signed BOOST_PYTHON_LONG_LONG,
+ ( x < static_cast<signed BOOST_PYTHON_LONG_LONG>(
+ (std::numeric_limits<long>::min)())
+ || x > static_cast<signed BOOST_PYTHON_LONG_LONG>(
+ (std::numeric_limits<long>::max)()))
+ ? ::PyLong_FromLongLong(x)
+ : ::PyInt_FromLong(static_cast<long>(x)), &PyInt_Type)
+BOOST_PYTHON_TO_PYTHON_BY_VALUE(
+ unsigned BOOST_PYTHON_LONG_LONG,
+ x > static_cast<unsigned BOOST_PYTHON_LONG_LONG>(
+ (std::numeric_limits<long>::max)())
+ ? ::PyLong_FromUnsignedLongLong(x)
+ : ::PyInt_FromLong(static_cast<long>(x)), &PyInt_Type)
+//
+# elif defined(HAVE_LONG_LONG) // using Python's macro instead of Boost's
+ // - we don't seem to get the config right
+ // all the time.
 BOOST_PYTHON_TO_PYTHON_BY_VALUE(signed BOOST_PYTHON_LONG_LONG, ::PyLong_FromLongLong(x), &PyLong_Type)
 BOOST_PYTHON_TO_PYTHON_BY_VALUE(unsigned BOOST_PYTHON_LONG_LONG, ::PyLong_FromUnsignedLongLong(x), &PyLong_Type)
 # endif


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