diff oct-py-types.cc @ 336:c081e30c2f64

Overhaul Python list creation from cell array * oct-py-types.cc, oct-py-types.h (pytave::make_py_list): New function. * octave_to_python.cc (pytave::octvalue_to_pyobj): Use it. (pytave::octcell_to_pyobject): Delete.
author Mike Miller <mtmiller@octave.org>
date Mon, 15 Aug 2016 16:14:38 -0700
parents 5782d7932529
children d3d355dc44ad
line wrap: on
line diff
--- a/oct-py-types.cc	Mon Aug 15 15:16:24 2016 -0700
+++ b/oct-py-types.cc	Mon Aug 15 16:14:38 2016 -0700
@@ -24,6 +24,7 @@
 #  include <config.h>
 #endif
 
+#include <octave/Cell.h>
 #include <octave/oct-map.h>
 #include <octave/quit.h>
 
@@ -86,6 +87,28 @@
   return 0;
 }
 
+PyObject *
+make_py_list (const Cell& cell)
+{
+  if (! (cell.is_empty () || cell.is_vector ()))
+    throw value_convert_exception (
+      "unable to convert multidimensional cell array into Python sequence");
+
+  PyObject *list = PyList_New (0);
+  if (! list)
+    octave_throw_bad_alloc ();
+
+  for (octave_idx_type i = 0; i < cell.numel (); i++)
+    {
+      PyObject *item = wrap_octvalue_to_pyobj (cell.xelem (i));
+
+      if (PyList_Append (list, item) < 0)
+        throw boost::python::error_already_set ();
+    }
+
+  return list;
+}
+
 std::string
 extract_py_str (PyObject *obj)
 {