changeset 23919:185f850aa543

Modify demos to return empty matrices for unused outputs (bug #51754). * helloworld.cc: Declare retval as an octave_value_list and fill it with empty Matrix() octave_value objects. * mex_demo.c, myhello.c: Use mxCreateDoubleMatrix with 0 rows, 0 columns to create empty matrices to return for unused outputs.
author Rik <rik@octave.org>
date Tue, 15 Aug 2017 10:02:03 -0700
parents 7662b441e2ea
children 0b971884080c ab1aa0e57b72
files examples/code/helloworld.cc examples/code/mex_demo.c examples/code/myhello.c
diffstat 3 files changed, 17 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/examples/code/helloworld.cc	Tue Aug 15 09:02:47 2017 -0400
+++ b/examples/code/helloworld.cc	Tue Aug 15 10:02:03 2017 -0700
@@ -7,5 +7,10 @@
                 << args.length () << " input arguments and "
                 << nargout << " output arguments.\n";
 
-  return octave_value_list ();
+  // Return empty matrices for any outputs
+  octave_value_list retval (nargout);
+  for (int i = 0; i < nargout; i++)
+    retval(i) = octave_value (Matrix ());
+
+  return retval;
 }
--- a/examples/code/mex_demo.c	Tue Aug 15 09:02:47 2017 -0400
+++ b/examples/code/mex_demo.c	Tue Aug 15 10:02:03 2017 -0700
@@ -50,9 +50,14 @@
 
   mexPrintf ("I have %d inputs and %d outputs\n", nrhs, nlhs);
 
+  /* Demonstrate returning a matrix with a double value */
   mxArray *v = mxCreateDoubleMatrix (1, 1, mxREAL);
   double *data = mxGetPr (v);
   *data = 1.23456789;
+  plhs[0] = v;
 
-  plhs[0] = v;
+  /* Return empty matrices for any other outputs */
+  int i;
+  for (i = 1; i < nlhs; i++)
+    plhs[i] = mxCreateDoubleMatrix (0, 0, mxREAL);
 }
--- a/examples/code/myhello.c	Tue Aug 15 09:02:47 2017 -0400
+++ b/examples/code/myhello.c	Tue Aug 15 10:02:03 2017 -0700
@@ -7,4 +7,9 @@
   mexPrintf ("Hello, World!\n");
 
   mexPrintf ("I have %d inputs and %d outputs\n", nrhs, nlhs);
+
+  /* Return empty matrices for any outputs */
+  int i;
+  for (i = 0; i < nlhs; i++)
+    plhs[i] = mxCreateDoubleMatrix (0, 0, mxREAL);
 }