# HG changeset patch # User Rik # Date 1390583388 28800 # Node ID d1e16bdb39581a5510df7bc4d2cf8043a2a8d42b # Parent 2e62b1f01bfece6a5c10ba60006f22085a34abc1 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. diff -r 2e62b1f01bfe -r d1e16bdb3958 doc/interpreter/external.txi --- a/doc/interpreter/external.txi Fri Jan 24 04:19:00 2014 -0500 +++ b/doc/interpreter/external.txi Fri Jan 24 09:09:48 2014 -0800 @@ -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 - diff -r 2e62b1f01bfe -r d1e16bdb3958 examples/myfeval.c --- a/examples/myfeval.c Fri Jan 24 04:19:00 2014 -0500 +++ b/examples/myfeval.c Fri Jan 24 09:09:48 2014 -0800 @@ -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); }