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

 
 

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

Submitted by:  Joseph Young <josyoun>
Submitted on:  Thu 09 Jun 2016 01:57:32 AM UTC  
 
Category: InterpreterSeverity: 3 - Normal
Priority: 5 - NormalItem Group: Incorrect Result
Status: FixedAssigned to: None
Originator Name: josyounOpen/Closed: Closed
Release: 4.0.0Operating System: GNU/Linux

Add a New Comment(Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

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>
Project 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 File(s):
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

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

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only project members can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 2 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Thu 08 Sep 2016 11:34:40 PM UTCrik5StatusNone=>Fixed
      Open/ClosedOpen=>Closed

    Back to the top


    Powered by Savane 3.1-cleanup1