Mercurial > octave
changeset 22451:ad5439817753
Add mexCallMATLABWithTrap to MEX API (bug #48949).
* NEWS: Announce change.
* mex.cc (mexCallMATLABWithTrap): New function.
* mexproto.h (mexCallMATLABWithTrap): Prototype for new function.
author | Rik <rik@octave.org> |
---|---|
date | Thu, 08 Sep 2016 16:01:33 -0700 |
parents | 2fb86778f78d |
children | 3a8af9d517de |
files | NEWS libinterp/corefcn/mex.cc libinterp/corefcn/mexproto.h |
diffstat | 3 files changed, 35 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/NEWS Thu Sep 08 15:03:26 2016 -0700 +++ b/NEWS Thu Sep 08 16:01:33 2016 -0700 @@ -133,6 +133,11 @@ literally grab the HTML published code from a remote website, for example. + ** The MEX API now includes the function mexCallMATLABWithTrap. This + function will not abort if an error occurs during mexCallMATLAB, but + instead will return execution to the MEX function for error + handling. + ** Other new functions added in 4.2: audioformats
--- a/libinterp/corefcn/mex.cc Thu Sep 08 15:03:26 2016 -0700 +++ b/libinterp/corefcn/mex.cc Thu Sep 08 16:01:33 2016 -0700 @@ -3112,6 +3112,30 @@ return execution_error ? 1 : 0; } +mxArray * +mexCallMATLABWithTrap (int nargout, mxArray *argout[], int nargin, + mxArray *argin[], const char *fname) +{ + mxArray *mx = NULL; + const char *fields[] = {"identifier", "message", "case", "stack"}; + + int old_flag = mex_context ? mex_context->trap_feval_error : 0; + mexSetTrapFlag (1); + if (mexCallMATLAB (nargout, argout, nargin, argin, fname)) + { + mx = mxCreateStructMatrix (1, 1, 4, fields); + mxSetFieldByNumber (mx, 0, 0, mxCreateString ("Octave:MEX")); + std::string msg = "mexCallMATLABWithTrap: function call <" + + std::string (fname) + "> failed"; + mxSetFieldByNumber (mx, 0, 1, mxCreateString (msg.c_str ())); + mxSetFieldByNumber (mx, 0, 2, mxCreateCellMatrix (0, 0)); + mxSetFieldByNumber (mx, 0, 3, mxCreateStructMatrix (0, 1, 0, NULL)); + } + mexSetTrapFlag (old_flag); + + return mx; +} + void mexSetTrapFlag (int flag) {
--- a/libinterp/corefcn/mexproto.h Thu Sep 08 15:03:26 2016 -0700 +++ b/libinterp/corefcn/mexproto.h Thu Sep 08 16:01:33 2016 -0700 @@ -80,6 +80,12 @@ int nargin, mxArray *argin[], const char *fname); +extern OCTINTERP_API mxArray * mexCallMATLABWithTrap (int nargout, + mxArray *argout[], + int nargin, + mxArray *argin[], + const char *fname); + extern OCTINTERP_API void mexSetTrapFlag (int flag); extern OCTINTERP_API int mexEvalString (const char *s); extern OCTINTERP_API void mexErrMsgTxt (const char *s);