@@ -122,9 +122,30 @@ BOOST_PYTHON_TO_INT(short)
122122BOOST_PYTHON_TO_INT (int )
123123BOOST_PYTHON_TO_INT (long )
124124
125- // using Python's macro instead of Boost's - we don't seem to get the
126- // config right all the time.
127- # ifdef HAVE_LONG_LONG
125+ # if defined(_MSC_VER) && defined(_WIN64)
126+ /* Under 64-bit Windows std::size_t is "unsigned long long". To avoid
127+ getting a Python long for each std::size_t the value is checked before
128+ the conversion. A std::size_t is converted to a simple Python int
129+ if possible; a Python long appears only if the value is too small or
130+ too large to fit into a simple int. */
131+ BOOST_PYTHON_TO_PYTHON_BY_VALUE (
132+ signed BOOST_PYTHON_LONG_LONG,
133+ ( x < static_cast <signed BOOST_PYTHON_LONG_LONG>(
134+ (std::numeric_limits<long >::min)())
135+ || x > static_cast<signed BOOST_PYTHON_LONG_LONG>(
136+ (std::numeric_limits<long >::max)()))
137+ ? ::PyLong_FromLongLong(x)
138+ : ::PyInt_FromLong(static_cast <long >(x)), &PyInt_Type)
139+ BOOST_PYTHON_TO_PYTHON_BY_VALUE(
140+ unsigned BOOST_PYTHON_LONG_LONG,
141+ x > static_cast <unsigned BOOST_PYTHON_LONG_LONG>(
142+ (std::numeric_limits<long >::max)())
143+ ? ::PyLong_FromUnsignedLongLong(x)
144+ : ::PyInt_FromLong(static_cast <long >(x)), &PyInt_Type)
145+ //
146+ # elif defined(HAVE_LONG_LONG) // using Python's macro instead of Boost's
147+ // - we don't seem to get the config right
148+ // all the time.
128149BOOST_PYTHON_TO_PYTHON_BY_VALUE (signed BOOST_PYTHON_LONG_LONG, ::PyLong_FromLongLong(x), &PyLong_Type)
129150BOOST_PYTHON_TO_PYTHON_BY_VALUE(unsigned BOOST_PYTHON_LONG_LONG, ::PyLong_FromUnsignedLongLong(x), &PyLong_Type)
130151# endif
0 commit comments