From 395372461752a28ff8d9fff14a2fa8b254fe7974 Mon Sep 17 00:00:00 2001 From: Dave Abrahams Date: Tue, 17 Oct 2000 23:35:58 +0000 Subject: [PATCH] Drop requirement for [SVN r7982] --- py.cpp | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/py.cpp b/py.cpp index a64e27c5..9ac2490d 100644 --- a/py.cpp +++ b/py.cpp @@ -7,7 +7,11 @@ // producing this work. #include "py.h" -#include +#include +#include +#ifndef BOOST_NO_LIMITS +# include +#endif namespace py { @@ -82,11 +86,19 @@ T integer_from_python(PyObject* p, py::Type) { const long long_result = from_python(p, py::Type()); +#ifndef BOOST_NO_LIMITS try { return boost::numeric_cast(long_result); } catch(const boost::bad_numeric_cast&) +#else + if (static_cast(long_result) == long_result) + { + return static_cast(long_result); + } + else +#endif { char buffer[256]; const char message[] = "%ld out of range for %s"; @@ -103,12 +115,17 @@ template PyObject* integer_to_python(T value) { long value_as_long; - + +#ifndef BOOST_NO_LIMITS try { - value_as_long = boost::numeric_cast(value); + value_as_long = boost::numeric_cast(value); } catch(const boost::bad_numeric_cast&) +#else + value_as_long = static_cast(value); + if (value_as_long != value) +#endif { const char message[] = "value out of range for Python int"; PyErr_SetString(PyExc_ValueError, message);