From 14ea71e201c1eef207cfa2b1793fed2c6d0f5095 Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Tue, 6 Jul 2010 14:29:25 +0000 Subject: [PATCH] boost/python/converter/builtin_converters.hpp: 64-bit Windows special case to avoid getting a Python long for each std::size_t [SVN r63696] --- .../python/converter/builtin_converters.hpp | 27 ++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/include/boost/python/converter/builtin_converters.hpp b/include/boost/python/converter/builtin_converters.hpp index 63ae1e1a..978f4f1f 100644 --- a/include/boost/python/converter/builtin_converters.hpp +++ b/include/boost/python/converter/builtin_converters.hpp @@ -122,9 +122,30 @@ BOOST_PYTHON_TO_INT(short) 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( + (std::numeric_limits::min)()) + || x > static_cast( + (std::numeric_limits::max)())) + ? ::PyLong_FromLongLong(x) + : ::PyInt_FromLong(static_cast(x)), &PyInt_Type) +BOOST_PYTHON_TO_PYTHON_BY_VALUE( + unsigned BOOST_PYTHON_LONG_LONG, + x > static_cast( + (std::numeric_limits::max)()) + ? ::PyLong_FromUnsignedLongLong(x) + : ::PyInt_FromLong(static_cast(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