changeset 399:692cecebc71f

Error on attempt to convert a char array to Python str (fixes issue #75) * octave_to_python.cc (pytave::octvalue_to_pyobj): Throw an exception on attempt to convert a char array with more than one row. * pycall.cc: Add %!tests.
author Mike Miller <mtmiller@octave.org>
date Fri, 28 Apr 2017 10:13:04 -0700
parents 3905052ebe1d
children 6c316b5f30f7
files octave_to_python.cc pycall.cc
diffstat 2 files changed, 7 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/octave_to_python.cc	Fri Apr 28 09:03:55 2017 -0700
+++ b/octave_to_python.cc	Fri Apr 28 10:13:04 2017 -0700
@@ -164,6 +164,9 @@
     if (octvalue.is_undefined ())
       throw value_convert_exception (
         "Octave value `undefined'. Can not convert to a Python object");
+    else if (octvalue.is_string () && octvalue.rows () > 1)
+      throw value_convert_exception (
+        "Octave multirow char array cannot be converted to a Python object");
     else if (octvalue.is_string ())
       {
         PyObject *obj = make_py_str (octvalue.string_value ());
--- a/pycall.cc	Fri Apr 28 09:03:55 2017 -0700
+++ b/pycall.cc	Fri Apr 28 10:13:04 2017 -0700
@@ -186,6 +186,10 @@
 %!error (pycall ("list", {1, 2, 3; 4, 5, 6}))
 %!error (pycall ("dict", {1, 2, 3}))
 
+## Test failure to convert char arrays to strings
+%!error (pycall ("str", ("hello")'))
+%!error (pycall ("str", ["hello"; "world"]))
+
 ## Test construction of dict from pyargs
 %!test
 %! a = pycall ("dict", pyargs ("a", 1, "b", 2, "c", 3));