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

 
 

bug #42614: exist problems with incorrect mex files

Submitted by:  Richard <crobar>
Submitted on:  Wed 25 Jun 2014 04:20:20 PM UTC  
 
Category: Octave FunctionSeverity: 3 - Normal
Priority: 5 - NormalItem Group: Matlab Compatibility
Status: FixedAssigned to: None
Originator Name: Richard CrozierOpen/Closed: Closed
Release: devOperating System: GNU/Linux

Add a New Comment(Rich Markup)
   

You are not logged in

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

 

(Jump to the original submission 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>
Project 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>
Project Administrator
Thu 26 Jun 2014 04:36:46 PM UTC, comment #9:

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

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

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>
Project 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

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

No files currently attached

 

Digest:
   bug dependencies.

Items that depend on this one: None found

 

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

    Date Changed By Updated Field Previous Value => Replaced By
    Thu 26 Jun 2014 04:57:56 PM UTCrik5StatusConfirmed=>Fixed
      Open/ClosedOpen=>Closed
    Thu 26 Jun 2014 03:58:47 PM UTCrik5Dependencies-=>Depends on bugs #36067
    Thu 26 Jun 2014 03:58:14 PM UTCrik5StatusFixed=>Confirmed
      Open/ClosedClosed=>Open
      Summaryexist returns 3 for \'mexfunction\', but 2 for \'mexfunction.mex\'=>exist problems with incorrect mex files
    Wed 25 Jun 2014 09:04:43 PM UTCrik5StatusNeed Info=>Fixed
      Open/ClosedOpen=>Closed
    Wed 25 Jun 2014 05:21:33 PM UTCrik5StatusNone=>Need Info

    Back to the top


    Powered by Savane 3.1-cleanup1