bugGNU Octave - Bugs: bug #48185, mexCallMATLAB doesn't exit mex...

 
 

bug #48185: mexCallMATLAB doesn't exit mex file on error on first call

Submitter:  Joseph Young <josyoun>
Submitted:  Thu 09 Jun 2016 01:57:32 AM UTC
   
 
Category:  Interpreter Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  Fixed Assigned to:  None
Originator Name:  josyoun Open/Closed:  * Closed
Release:  * 4.0.0 Operating System:  * GNU/Linux
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Thu 08 Sep 2016 11:34:40 PM UTC, comment #1: 

This has been fixed on the development branch by this changeset (http://hg.savannah.gnu.org/hgweb/octave/rev/3a8af9d517de).  The problem was that the value of the MEX TrapFlag was not being initialized to 0.  Hopefully this will make it in to the 4.2 release.

Rik <rik5>
Group administrator
Thu 09 Jun 2016 01:57:32 AM UTC, original submission:  

It doesn't look like mexCallMATLAB exits the routine when an error occurs on the first call.  Subsequent calls exit normally.  In general, mexCallMATLAB should immediately exit the mex file on error, which makes the return value a little superfluous.  Consider the code:

$ cat test01.cpp
#include "mex.h"
#include <array>
#include <iostream>

void mexFunction(
    int nOutput,mxArray* pOutput[],
    int nInput,mxArray const * pInput[]
) try {

    // Calling convention should be
    // f_x = test01(f,x)
    auto f = const_cast <mxArray*> (pInput[0]);
    auto x = const_cast <mxArray*> (pInput[1]);

    // Call the function
    auto input = std::array <mxArray *,2> {f,x};
    auto output = std::array <mxArray *,1> ();
    auto err=mexCallMATLAB(1,output.data(),2,input.data(),"feval");
    if(err)
        throw std::runtime_error("There's a MATLAB/Octave error");

    // Assign the return value
    pOutput[0]=output[0];

    // Return nothing
    return;

} catch(std::runtime_error const & e) {
    std::cerr << "Exception!!!!!" << std::endl;
    return;
}

which is compiled with:

g++ -std=c++14 -g -fPIC -I /usr/include/octave-4.0.0/octave/ test01.cpp -shared -o test01.mex

And the driver code:

$ cat driver01.m
f = @(x)x+1
x = {1}
y = test01(f,x)

This should error since we can't add a cell array to a number.  When we run the routine:

$ octave
octave: no graphical display found
octave: disabling GUI features
GNU Octave, version 4.0.0
Copyright (C) 2015 John W. Eaton and others.
This is free software; see the source code for copying conditions.
There is ABSOLUTELY NO WARRANTY; not even for MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.  For details, type 'warranty'.

Octave was configured for "x86_64-pc-linux-gnu".

Additional information about Octave is available at http://www.octave.org.

Please contribute if you find this software useful.
For more information, visit http://www.octave.org/get-involved.html

Read http://www.octave.org/bugs.html to learn how to submit bug reports.
For information about changes from previous versions, type 'news'.

octave:1> driver01
f =

@(x) x + 1

x =
{
  [1,1] =  1
}
error: binary operator '+' not implemented for 'cell' by 'scalar' operations
error: called from
    driver01> at line -1 column -1
    driver01 at line 3 column 3
Exception!!!!!
y = [](0x0)

We see that the exception is thrown and that y is assigned a null value.  If we run the routine a second time:

octave:2> driver01
f =

@(x) x + 1

x =
{
  [1,1] =  1
}
error: binary operator '+' not implemented for 'cell' by 'scalar' operations
error: called from
    driver01> at line -1 column -1
    driver01 at line 3 column 3

The exception is not thrown and y is not assigned a value.  I believe the behavior in the second case to be correct and the behavior in the first case to be a bug.

Joseph Young <josyoun>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by josyoun (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 2 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2016-09-08 rik5 StatusNone Fixed
        Open/ClosedOpen Closed

    Back to the top

    Powered by Savane 3.13-f8d8.
    Corresponding source code