# HG changeset patch # User Mike Miller # Date 1471912066 25200 # Node ID 8cdc94b83e9806fc9581917d3428de58ed4de60d # Parent eec3ed1c0578bf488c6991c2ac29c0c6bf12e290 Fix int64 value extraction from long to work on 32-bit, use Octave saturation * oct-py-types.cc (pytave::extract_py_int64): Extract value to appropriately sized integer type for platform architecture. Saturate value on overflow. diff -r eec3ed1c0578 -r 8cdc94b83e98 oct-py-types.cc --- a/oct-py-types.cc Mon Aug 22 17:24:13 2016 -0700 +++ b/oct-py-types.cc Mon Aug 22 17:27:46 2016 -0700 @@ -24,6 +24,7 @@ # include #endif +#include #include #include #include @@ -386,7 +387,20 @@ throw object_convert_exception ("failed to extract integer: null object"); if (PyLong_Check (obj)) - return PyLong_AsLong (obj); + { + int overflow = 0; +#if (defined (HAVE_LONG_LONG) && (SIZEOF_LONG_LONG == 8)) + PY_LONG_LONG value = PyLong_AsLongLongAndOverflow (obj, &overflow); +#else + long value = PyLong_AsLongAndOverflow (obj, &overflow); +#endif + if (overflow) + if (overflow > 0) + value = std::numeric_limits::max (); + else + value = std::numeric_limits::min (); + return static_cast (value); + } #if PY_VERSION_HEX < 0x03000000 else if (PyInt_Check (obj)) return PyInt_AsLong (obj);