# HG changeset patch # User Mike Miller # Date 1471377427 25200 # Node ID 6bd8f5e3542a9934e2433855fb0418c8b613138a # Parent b0d012e9975fb9967861438c24516848a920152b Convert Octave cell array into Python tuple instead of list * oct-py-types.cc, oct-py-types.h (pytave::make_py_tuple): Rename from pytave::make_py_list, construct a tuple instead of list. * octave_to_python.cc (pytave::octvalue_to_pyobj): Call make_py_tuple. diff -r b0d012e9975f -r 6bd8f5e3542a oct-py-types.cc --- a/oct-py-types.cc Tue Aug 16 00:31:22 2016 -0700 +++ b/oct-py-types.cc Tue Aug 16 12:57:07 2016 -0700 @@ -219,25 +219,24 @@ } PyObject * -make_py_list (const Cell& cell) +make_py_tuple (const Cell& cell) { if (! (cell.is_empty () || cell.is_vector ())) throw value_convert_exception ( - "unable to convert multidimensional cell array into Python sequence"); + "unable to convert multidimensional cell array into Python tuple"); - PyObject *list = PyList_New (0); - if (! list) + octave_idx_type size = cell.numel (); + PyObject *tuple = PyTuple_New (size); + if (! tuple) octave_throw_bad_alloc (); - for (octave_idx_type i = 0; i < cell.numel (); i++) + for (octave_idx_type i = 0; i < size; ++i) { PyObject *item = wrap_octvalue_to_pyobj (cell.xelem (i)); - - if (PyList_Append (list, item) < 0) - throw boost::python::error_already_set (); + PyTuple_SET_ITEM (tuple, i, item); } - return list; + return tuple; } std::string diff -r b0d012e9975f -r 6bd8f5e3542a oct-py-types.h --- a/oct-py-types.h Tue Aug 16 00:31:22 2016 -0700 +++ b/oct-py-types.h Tue Aug 16 12:57:07 2016 -0700 @@ -121,15 +121,15 @@ PyObject * make_py_int (uint64_t value); -//! Create a Python list object from the given Octave cell array value. +//! Create a Python tuple object from the given Octave cell array value. //! //! The values contained in the cell array are recursively converted to //! appropriate Python values. //! //! @param cell Octave cell array -//! @return Python list object +//! @return Python tuple object PyObject * -make_py_list (const Cell& cell); +make_py_tuple (const Cell& cell); //! Create a Python numeric object from the given Octave numeric or boolean //! scalar value. diff -r b0d012e9975f -r 6bd8f5e3542a octave_to_python.cc --- a/octave_to_python.cc Tue Aug 16 00:31:22 2016 -0700 +++ b/octave_to_python.cc Tue Aug 16 12:57:07 2016 -0700 @@ -175,7 +175,7 @@ } else if (octvalue.is_cell ()) { - PyObject *obj = make_py_list (octvalue.cell_value ()); + PyObject *obj = make_py_tuple (octvalue.cell_value ()); py_object = object (handle (obj)); } else if (octvalue.is_numeric_type () || octvalue.is_string ()