# HG changeset patch # User Abhinav Tripathi # Date 1469731829 25200 # Node ID 0a4f620da178be50d1c104fc21dd3f00b0b486d2 # Parent c8da556b679321ae06f51d0d91a0d04b66310d72 Convert numeric value to long instead of int to avoid overflow (fixes issue #40) * python_to_octave.cc: Try conversion of py_object to 'long' instead of 'int' * pyeval.cc: Add tests to verify no positive/negative overflow diff -r c8da556b6793 -r 0a4f620da178 pyeval.cc --- a/pyeval.cc Wed Jul 27 20:30:35 2016 -0700 +++ b/pyeval.cc Thu Jul 28 11:50:29 2016 -0700 @@ -141,6 +141,11 @@ %!assert (isa (pyeval ("object()"), "pyobject")) +%!assert (isnumeric (pyeval ("sys.maxsize"))) +%!assert (isnumeric (pyeval ("-sys.maxsize"))) +%!assert (pyeval ("99999999999999"), 99999999999999) +%!assert (pyeval ("-99999999999999"), -99999999999999) + ## FIXME: these will change when dict, list, and tuple are not converted %!assert (pyeval ("{'x': 1, 'y': 2}"), struct ("x", 1, "y", 2)) %!assert (pyeval ("[1, 2, 3]"), {1, 2, 3}) diff -r c8da556b6793 -r 0a4f620da178 python_to_octave.cc --- a/python_to_octave.cc Wed Jul 27 20:30:35 2016 -0700 +++ b/python_to_octave.cc Thu Jul 28 11:50:29 2016 -0700 @@ -477,7 +477,7 @@ void pyobj_to_octvalue (octave_value& oct_value, const boost::python::object& py_object) { - extract intx (py_object); + extract longx (py_object); extract boolx (py_object); extract doublex (py_object); extract complexx (py_object); @@ -490,8 +490,8 @@ if (boolx.check () && PyBool_Check ((PyArrayObject*)py_object.ptr ())) oct_value = boolx (); - else if (intx.check ()) - oct_value = intx (); + else if (longx.check ()) + oct_value = longx (); else if (doublex.check ()) oct_value = doublex (); else if (complexx.check ())