Mercurial > hg > octave-nkf
changeset 18435:d1e16bdb3958 stable
myfeval.c: Fix segfault in mex example code.
* myfeval.c: Correctly cast away const attribute of prhs[].
Also, add code to work with Octave's built-in 'ans' variable.
* external.txi: Update example in External Code Interface for myfeval.
author | Rik <rik@octave.org> |
---|---|
date | Fri, 24 Jan 2014 09:09:48 -0800 |
parents | 2e62b1f01bfe |
children | 877b82d73ed9 |
files | doc/interpreter/external.txi examples/myfeval.c |
diffstat | 2 files changed, 11 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/doc/interpreter/external.txi +++ b/doc/interpreter/external.txi @@ -1712,12 +1712,11 @@ @example @group -myfeval ("sin", 1) a = myfeval ("sin", 1) -@result{} Hello, World! - I have 2 inputs and 1 outputs - I'm going to call the interpreter function sin - a = 0.84147 +@result{} Starting file myfeval.mex + I have 2 inputs and 1 outputs + I'm going to call the interpreter function sin + a = 0.84147 @end group @end example @@ -1811,8 +1810,7 @@ This is the norm of the matrix: 34.4952 - +$ @end group @end example -
--- a/examples/myfeval.c +++ b/examples/myfeval.c @@ -6,7 +6,7 @@ { char *str; - mexPrintf ("Hello, World!\n"); + mexPrintf ("Starting file myfeval.mex\n"); mexPrintf ("I have %d inputs and %d outputs\n", nrhs, nlhs); @@ -17,7 +17,11 @@ mexPrintf ("I'm going to call the function %s\n", str); - mexCallMATLAB (nlhs, plhs, nrhs-1, (mxArray*)prhs+1, str); + if (nlhs == 0) + nlhs = 1; // Octave's automatic 'ans' variable + + /* Cast prhs just to get rid of 'const' qualifier and stop compile warning */ + mexCallMATLAB (nlhs, plhs, nrhs-1, (mxArray**)prhs+1, str); mxFree (str); }