bugGNU Octave - Bugs: bug #42614, exist problems with incorrect mex...

 
 

bug #42614: exist problems with incorrect mex files

Submitter:  Richard <crobar>
Submitted:  Wed 25 Jun 2014 04:20:20 PM UTC
   
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Matlab Compatibility
Status:  Fixed Assigned to:  None
Originator Name:  Richard Crozier Open/Closed:  * Closed
Release:  * dev Operating System:  * GNU/Linux
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Thu 26 Jun 2014 04:57:56 PM UTC, comment #12: 

Good.  Closing report a second, hopefully final, time.

Rik <rik5>
Group administrator
Thu 26 Jun 2014 04:43:59 PM UTC, comment #11: 

Hmmm, that's right, silly of me to forget the mexw32 instead of mex the first time, here's the result with the file renamed with the mexw32 extension (it is the extension on this machine):

>> exist ('mexfunction', 'file')


ans =

     3.0000e+000

>> exist ('mexfunction.mexw32', 'file')


ans =

     3.0000e+000

So Matlab doesn't know any better either.

Richard <crobar>
Thu 26 Jun 2014 04:38:09 PM UTC, comment #10: 

I checked in a changeset that I believe fixes the problem with bad symbol table lookups (http://hg.savannah.gnu.org/hgweb/octave/rev/a0fd65914811).  I'll wait for Richard's verification results before closing this report again.

Rik <rik5>
Group administrator
Thu 26 Jun 2014 04:36:46 PM UTC, comment #9: 

The problem is this line in symbol_exist in variables.cc:


val = safe_symbol_lookup (name);


It might be possible to use a try/catch or unwind_protect around this piece of code.  I just used try/catch and it seemed to work.

@Richard: Could you run mexext() and see what Matlab returns?  I think for your case it will return 'mexw32'.  If this is the case, then I would like to rename the "Hello World" file to "mexfunction.mexw32" and then re-run


exist ('mexfunction', 'file')
exist ('mexfunction.mexw32', 'file')


According to Matlab's own documentation, they shouldn't be parsing the file, only looking at the extension to determine whether to return 2 or 3.

Rik <rik5>
Group administrator
Thu 26 Jun 2014 03:58:14 PM UTC, comment #8: 

I'm re-opening the bug.  There is a deep problem when the file has a name that looks like a mex file, but is not in fact a mex file.  The example of a text file with "Hello World" in it shows this.

Under the development branch with all of the latest changes to exist, I get


exist ('mexfunction')
error: caught execution error in library function


This is related to bug #36067.  The problem is that in checking for a built-in Octave looks in the symbol table for the name.  If it doesn't find it in the symbol table, but does find what looks like a possible mex file, it tries to load it.  This generates the exception.  It would be nice if there were a way to simply query the symbol table, but functions would not be loaded until they were asked for, i.e., someone typed the function name on the command line and tried to invoke it.

Rik <rik5>
Group administrator
Thu 26 Jun 2014 02:01:01 PM UTC, comment #7: 

Just to update, on ML I ge the following result

mexfunction.mex
---------------
Hello World

---------------

mexfunction2.mex
---------------
#include "mex.h"

/* the gateway function */
void mexFunction( int nlhs, mxArray *plhs[],
int nrhs, const mxArray *prhs[])
{

plhs[0] = mxCreateDoubleScalar(1.0);

}
---------------


>> exist ('mexfunction.mex', 'file')


ans =

     2.0000e+000

>> exist ('mexfunction', 'file')


ans =

     0.0000e+000

>> exist ('mexfunction2', 'file')


ans =

     3.0000e+000

>> exist ('mexfunction2.mexw32', 'file')


ans =

     3.0000e+000

Richard <crobar>
Wed 25 Jun 2014 09:18:13 PM UTC, comment #6: 

Ok, good. Then assuming it is indeed 3 for both cases in Matlab, this is now fixed with Rik's change.

Mike Miller <mtmiller>
Group Member
Wed 25 Jun 2014 09:12:49 PM UTC, comment #5: 

No ,i was being silly, that result was for octave (but i guess you could have done this yourself).

I'll try the same test in ML tomorrow, but the help for 'exist' does also imply it should be 3 in both cases in Octave too.

Anonymous
Wed 25 Jun 2014 09:04:43 PM UTC, comment #4: 

I made the behavior Matlab compatible in this changeset on the development branch (http://hg.savannah.gnu.org/hgweb/octave/rev/a1dde4d4c45c).

Rik <rik5>
Group administrator
Wed 25 Jun 2014 08:41:43 PM UTC, comment #3: 

I'm confused, can you please clarify? You originally said Matlab would return 3 for both exist('foo') and exist('foo.mex'), but in comment #2 you have

> >> exist ('mexfunction2')
>
> ans = 3
>
> >> exist ('mexfunction2.mex')
>
> ans = 2


where mexfunction2 is an actual compiled mex file. Was this from Matlab, is this the actual behavior? If so, I'm failing to see what the bug is.

Mike Miller <mtmiller>
Group Member
Wed 25 Jun 2014 08:14:26 PM UTC, comment #2: 

Apparently not, I created a text file containing just "Hello World" in the current irectory and got

>> exist ('mexfunction')

ans =  3

>> exist ('mexfunction.mex')

ans =  2

I then made a trivial mex function:

-----
#include "mex.h"


/* the gateway function */
void mexFunction( int nlhs, mxArray *plhs[],
int nrhs, const mxArray *prhs[])
{
 
    plhs[0] = mxCreateDoubleScalar(1.0);

}
-----




and get

>> mexfunction2

ans =  1

>> exist ('mexfunction2')

ans =  3

>> exist ('mexfunction2.mex')

ans =  2

Richard <crobar>
Wed 25 Jun 2014 05:21:33 PM UTC, comment #1: 

Does it matter if mexfunction.mex is actually a mex file?

Could you create a text file with "Hello World" in it and name it mexfunction.mex and then repeat the two exist calls in Matlab?

Rik <rik5>
Group administrator
Wed 25 Jun 2014 04:20:20 PM UTC, original submission:  


As in the title, the exist function returns 3 for 'mexfunction', but 2 for 'mexfunction.mex'. Matlab returns 3 for both.

This is using hg id 47d4b680d0e0 @

Richard <crobar>

 

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

Attach Files:
   
   
Comment:
   

No files currently attached

 

Digest:
   bug dependencies.

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by mtmiller (Posted a comment)
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by crobar (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 9 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2014-06-26 rik5 StatusConfirmed Fixed
        Open/ClosedOpen Closed
    2014-06-26 rik5 Dependencies- Depends on bugs #36067
    2014-06-26 rik5 StatusFixed Confirmed
        Open/ClosedClosed Open
        Summaryexist returns 3 for \'mexfunction\', but 2 for \'mexfunction.mex\' exist problems with incorrect mex files
    2014-06-25 rik5 StatusNeed Info Fixed
        Open/ClosedOpen Closed
    2014-06-25 rik5 StatusNone Need Info

    Back to the top

    Powered by Savane 3.13-4448.
    Corresponding source code