# HG changeset patch # User Mike Miller # Date 1493399584 25200 # Node ID 692cecebc71f5ebd26c68f37a50523c268952f64 # Parent 3905052ebe1db9ccb924d19956974737172a3204 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. diff -r 3905052ebe1d -r 692cecebc71f octave_to_python.cc --- 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 ()); diff -r 3905052ebe1d -r 692cecebc71f pycall.cc --- 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));