[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Octave-bug-tracker] [bug #50050] MEX mxAssert macro expands wrongly.
From: |
Kai Torben Ohlhus |
Subject: |
[Octave-bug-tracker] [bug #50050] MEX mxAssert macro expands wrongly. |
Date: |
Fri, 13 Jan 2017 16:54:34 +0000 (UTC) |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36 |
URL:
<http://savannah.gnu.org/bugs/?50050>
Summary: MEX mxAssert macro expands wrongly.
Project: GNU Octave
Submitted by: siko1056
Submitted on: Fri 13 Jan 2017 05:54:33 PM CET
Category: Octave Function
Severity: 3 - Normal
Priority: 5 - Normal
Item Group: Matlab Compatibility
Status: Need Info
Assigned to: siko1056
Originator Name:
Originator Email:
Open/Closed: Open
Discussion Lock: Any
Release: 4.2.0
Operating System: Any
_______________________________________________________
Details:
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?
_______________________________________________________
Reply to this item at:
<http://savannah.gnu.org/bugs/?50050>
_______________________________________________
Message sent via/by Savannah
http://savannah.gnu.org/
- [Octave-bug-tracker] [bug #50050] MEX mxAssert macro expands wrongly.,
Kai Torben Ohlhus <=