bugGNU Octave - Bugs: bug #50539, builtin() is unable to call...

 
 

bug #50539: builtin() is unable to call shadowed core isequaln.m

Submitter:  Felipe G. Nievinski <fgnievinski>
Submitted:  Tue 14 Mar 2017 12:54:29 AM UTC
   
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Unexpected Error or Warning
Status:  Wont Fix Assigned to:  None
Originator Name:  Open/Closed:  * Closed
Release:  * 4.2.1 Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Thu 16 Mar 2017 02:00:38 AM UTC, comment #4: 

I agree that WONTFIX is appropriate here given that it's hard to keep track of which functions are compiled and interpreted; it's just bad practice to rely on this level of compatibility.

As for the original need, I guess the best way out would be to rename my wrapper as myisequaln.m, then internally call the implementation included in Octave or Matlab if it's available.

Felipe G. Nievinski <fgnievinski>
Tue 14 Mar 2017 05:33:12 PM UTC, comment #3: 

If Octave is behaving like Matlab then there is no bug to fix here.

For the motivating issue for this report, I think there is no easy way short of finding the function yourself.  I would first determine whether you are running Octave or Matlab and then find the full path to isequaln.m and use that in the try/catch block.  The function hasn't moved around much in Octave so you could get by with a fixed string.


fcn_path = fullfile (OCTAVE_HOME, "share", "octave", version (), "m", "general", "isequaln.m");


Or you could try something like


fcn_path = file_in_loadpath ("isequaln.m", "all")


and then figure out which version was your replacement and which was the m-file from the core libraries.

Rik <rik5>
Group administrator
Tue 14 Mar 2017 04:49:34 PM UTC, comment #2: 

Indeed, unless things have changed recently, Matlab's "builtin" function will only call those functions that are really built-in to Matlab, not core functions that are implemented as .m files.

This is likely to be a constant source of incompatibility since there is no guarantee that the functions built-in to Matlab will also be built-in to Octave.

I guess this also makes it difficult for TMW to change the implementation of a built-in function to be a .m file instead, since some users may depend on calling certain functions through the "builtin" function.

John W. Eaton <jwe>
Group administrator
Tue 14 Mar 2017 03:37:38 PM UTC, comment #1: 

There might be multiple issues here.  I want to clarify the behavior of exist() first.  In Octave, "builtin" means a compiled implementation of a function.  Therefore,


exist ("some_m_file_name", "builtin")


will return 0 since an m-file is not compiled.

From the help page for builtin (http://www.mathworks.com/help/matlab/ref/builtin.html)


A built-in function is part of the MATLAB executable. MATLAB does not implement these functions in the MATLAB language. Although most built-in functions have a .m file associated with them, this file only supplies documentation for the function.


You can use the syntax which function to check whether a function is built-in.

If you can check with an m-file that you know to be in the Matlab core libraries (try 'which xxx' and look at the file to see if it is an m-file) and then see what exist returns that would help debug this issue.

Also, take a look at the documentation for builtin.  It seems to suggest that builtin only works when the "original" function is a compiled function, not when it is an m-file.


Rik <rik5>
Group administrator
Tue 14 Mar 2017 12:54:29 AM UTC, original submission:  

In trying to support multiple Octave/Matlab versions, I have my own isequaln.m:

function varargout = isequaln (varargin)
    try
        [varargout{1:nargout}] = builtin ('isequaln', varargin{:});
    catch
        % ... do something here.
    end
end

Octave does acknowledge that isequaln is being shadowed:

warning: function C:\work\misc\fx\mpsim\lib\util\legacy\isequaln.m shadows a core library function

But then it is unable to find it:

>> exist('isequaln', 'builtin')

ans = 0

- Question: are core library functions not considered builtin functions?  If so, this would represent a Matlab incompatibility issue.

Thanks.


Felipe G. Nievinski <fgnievinski>

 

(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 jwe (Posted a comment)
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by fgnievinski (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 4 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2017-03-16 rik5 StatusNeed Info Wont Fix
        Open/ClosedOpen Closed
    2017-03-14 rik5 StatusNone Need Info
        Operating SystemMicrosoft Windows Any

    Back to the top

    Powered by Savane 3.13-caa5.
    Corresponding source code