comparison oct-py-types.cc @ 342:6bd8f5e3542a

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.
author Mike Miller <mtmiller@octave.org>
date Tue, 16 Aug 2016 12:57:07 -0700
parents 06b8aeea456f
children 9d95f087e5aa
comparison
equal deleted inserted replaced
341:b0d012e9975f 342:6bd8f5e3542a
217 217
218 return 0; 218 return 0;
219 } 219 }
220 220
221 PyObject * 221 PyObject *
222 make_py_list (const Cell& cell) 222 make_py_tuple (const Cell& cell)
223 { 223 {
224 if (! (cell.is_empty () || cell.is_vector ())) 224 if (! (cell.is_empty () || cell.is_vector ()))
225 throw value_convert_exception ( 225 throw value_convert_exception (
226 "unable to convert multidimensional cell array into Python sequence"); 226 "unable to convert multidimensional cell array into Python tuple");
227 227
228 PyObject *list = PyList_New (0); 228 octave_idx_type size = cell.numel ();
229 if (! list) 229 PyObject *tuple = PyTuple_New (size);
230 if (! tuple)
230 octave_throw_bad_alloc (); 231 octave_throw_bad_alloc ();
231 232
232 for (octave_idx_type i = 0; i < cell.numel (); i++) 233 for (octave_idx_type i = 0; i < size; ++i)
233 { 234 {
234 PyObject *item = wrap_octvalue_to_pyobj (cell.xelem (i)); 235 PyObject *item = wrap_octvalue_to_pyobj (cell.xelem (i));
235 236 PyTuple_SET_ITEM (tuple, i, item);
236 if (PyList_Append (list, item) < 0) 237 }
237 throw boost::python::error_already_set (); 238
238 } 239 return tuple;
239
240 return list;
241 } 240 }
242 241
243 std::string 242 std::string
244 extract_py_str (PyObject *obj) 243 extract_py_str (PyObject *obj)
245 { 244 {