bugGNU Octave - Bugs: bug #50050, MEX mxAssert macro expands wrongly.

 
 

bug #50050: MEX mxAssert macro expands wrongly.

Submitter:  Kai Torben Ohlhus <siko1056>
Submitted:  Fri 13 Jan 2017 04:54:33 PM UTC
   
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Matlab Compatibility
Status:  Fixed Assigned to:  siko1056
Originator Name:  Open/Closed:  * Closed
Release:  * 4.2.0 Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Fri 13 Jan 2017 11:11:47 PM UTC, comment #2: 

Done: http://hg.savannah.gnu.org/hgweb/octave/rev/0412dc701e28

@Rik: You are right about the -g flag. It seems to be in my default settings, independent of SeDuMi.


>> mkoctfile -p ALL_CFLAGS
-I/workspace/octave/ [snip] -pthread -fopenmp -g -O2
-varbatim-

In line 639 of http://hg.savannah.gnu.org/hgweb/octave/file/7b368d85e86c/src/mkoctfile.in.cc one can find the setting of "-DMEX_DEBUG".

Thanks for you help.

-- Closing report.

Kai Torben Ohlhus <siko1056>
Group Member
Fri 13 Jan 2017 05:45:27 PM UTC, comment #1: 

@Kai: Your analysis is correct.  There should be '(' and ')' around "expr".  Go ahead and make a changeset for stable.

As for why MxAssert is getting compiled in, either there is a '-g' being added (maybe from the user's own CFLAGS?) or someone is defining "-DMEX_DEBUG".  My guess is the former.  To debug, try


mkoctfile -p ALL_CFLAGS


The code in mkoctfile.cc is looking for '-g' somewhere in ALL_CFLAGS to indicated debug mode.  Maybe there is something like "optionabc-gxyz" and the '-g' is being found in the middle of a word.  Maybe the search should be for ' -g' with a space in front.


Rik <rik5>
Group administrator
Fri 13 Jan 2017 04:54:33 PM UTC, original submission:  

The SeDuMi bug tracker filed a bug https://github.com/sqlp/sedumi/issues/24 that seems to be more an issue of Octave. I assume the source of the error to lie inside the if statement of lines 311 and 328 in http://hg.savannah.gnu.org/hgweb/octave/file/tip/libinterp/corefcn/mexproto.h

namely


if (! expr)


I created the following MCVE mex file to check my assumption. Basically, it does the same as the erroneous file from the SeDuMi-Tracker, namely checking that there is at least one input and at most one output:


#include "mex.h"

/* mex -g mxAssertError.c; clear -f; clear all; a = mxAssertError(1,2) */

void mexFunction( int nlhs, mxArray *plhs[],
  int nrhs, const mxArray *prhs[])
{
  mexPrintf ("nrhs = %d\n", nrhs);
  mexPrintf ("nlhs = %d\n", nlhs);
  mexPrintf ("!nrhs = %d\n", !nrhs);
  mexPrintf ("!nlhs = %d\n", !nlhs);
  mexPrintf (" !nrhs  >= 1  = %d\n",  !nrhs  >= 1);
  mexPrintf ("(!nrhs) >= 1  = %d\n", (!nrhs) >= 1);
  mexPrintf ("!(nrhs  >= 1) = %d\n", !(nrhs  >= 1));
  mexPrintf (" !nlhs  <= 1  = %d\n", ! nlhs  <= 1);
  mexPrintf ("(!nlhs) <= 1  = %d\n", (!nlhs) <= 1);
  mexPrintf ("!(nlhs  <= 1) = %d\n", !(nlhs  <= 1));

  mxAssert ( nrhs >= 1 , "works.");
  mxAssert ((nrhs >= 1), "works.");
  mxAssert ((nlhs <= 1), "works.");
  mxAssert ( nlhs <= 1 , "does not work in Octave.");

  plhs[0] = mxCreateDoubleMatrix(1,1,mxREAL);
}


Matlab R2016b does:


>> mex -g mxAssertError.c; clear -f; clear all; a = mxAssertError(1,2)
Building with 'gcc'.
Warning: You are using gcc version '6.2.1'. The version of gcc is not supported. The version currently
supported with MEX is '4.9.x'. For a list of currently supported compilers see:
http://www.mathworks.com/support/compilers/current_release.
MEX completed successfully.
nrhs = 2
nlhs = 1
!nrhs = 0
!nlhs = 0
 !nrhs  >= 1  = 0
(!nrhs) >= 1  = 0
!(nrhs  >= 1) = 0
 !nlhs  <= 1  = 1
(!nlhs) <= 1  = 1
!(nlhs  <= 1) = 0

a =

     0

>>


and Octave 4.2.0:


>> mex -g mxAssertError.c; clear -f; clear all; a = mxAssertError(1,2)

nrhs = 2
nlhs = 1
!nrhs = 0
!nlhs = 0
 !nrhs  >= 1  = 0
(!nrhs) >= 1  = 0
!(nrhs  >= 1) = 0
 !nlhs  <= 1  = 1
(!nlhs) <= 1  = 1
!(nlhs  <= 1) = 0
error: mxAssertError: Assertion failed: nlhs <= 1, at line 22 of file "mxAssertError.c".
does not work in Octave.


Do you agree, that the Macros expand in a wrong fashion?

My suggested fix is


if (! (expr))


in the two lines, what works for me. I would also like to apply this patch to stable for 4.2.1.

Another issue is, that why is mxAssert expanded anyways? I thought it was only available with "mex -g", but SeDuMi compiles without "-g". Maybe another bug?

Kai Torben Ohlhus <siko1056>
Group Member

 

(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 siko1056 (Submitted the item)
  • -email is unavailable- added by siko1056 (Knows more about mex.)
  •  

    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 4 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2017-01-13 siko1056 StatusIn Progress Fixed
        Open/ClosedOpen Closed
    2017-01-13 rik5 StatusNeed Info In Progress
    2017-01-13 siko1056 Carbon-Copy- Added rik5

    Back to the top

    Powered by Savane 3.13-02a9.
    Corresponding source code