changeset 25451:f84755f24ccd stable

allow NULL mxArray* to be returned as undefined from fcn calls (bug #54096) * mxarray.in.h, mex.cc (mxArray::as_octave_value (const mxArray *): New bool arg, null_is_empty, with default value of true. If Check null_is_empty to determine whether to return and empty Matrix object or an undefined octave_value object when ptr is NULL. (call_mex): Pass false for null_is_empty when creating output values from plhs array.
author John W. Eaton <jwe@octave.org>
date Tue, 12 Jun 2018 10:24:25 -0400
parents 66b72fbf2845
children 582f343e9022 41ea5f665659
files libinterp/corefcn/mex.cc libinterp/corefcn/mxarray.in.h
diffstat 2 files changed, 9 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/mex.cc	Mon Jun 11 13:25:40 2018 -0400
+++ b/libinterp/corefcn/mex.cc	Tue Jun 12 10:24:25 2018 -0400
@@ -2073,9 +2073,13 @@
 }
 
 octave_value
-mxArray::as_octave_value (const mxArray *ptr)
+mxArray::as_octave_value (const mxArray *ptr, bool null_is_empty)
 {
-  return ptr ? ptr->as_octave_value () : octave_value ();
+  static const octave_value empty_matrix = Matrix ();
+
+  return (ptr
+          ? ptr->as_octave_value ()
+          : (null_is_empty ? empty_matrix : octave_value ()));
 }
 
 octave_value
@@ -3197,7 +3201,7 @@
   retval.resize (nargout);
 
   for (int i = 0; i < nargout; i++)
-    retval(i) = mxArray::as_octave_value (argout[i]);
+    retval(i) = mxArray::as_octave_value (argout[i], false);
 
   return retval;
 }
--- a/libinterp/corefcn/mxarray.in.h	Mon Jun 11 13:25:40 2018 -0400
+++ b/libinterp/corefcn/mxarray.in.h	Tue Jun 12 10:24:25 2018 -0400
@@ -545,7 +545,8 @@
     return retval;
   }
 
-  static octave_value as_octave_value (const mxArray *ptr);
+  static octave_value
+  as_octave_value (const mxArray *ptr, bool null_is_empty = true);
 
   octave_value as_octave_value (void) const;