bugGNU Octave - Bugs: bug #50116, libinterp functions should call...

 
 

bug #50116: libinterp functions should call C++ directly rather than calling through feval

Submitter:  Rik <rik5>
Submitted:  Sat 21 Jan 2017 11:07:17 PM UTC
   
 
Category:  Interpreter Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Performance
Status:  Fixed Assigned to:  None
Originator Name:  Open/Closed:  * Closed
Release:  * dev Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Wed 01 Feb 2017 01:30:34 AM UTC, comment #6: 

I replaced the possible feval calls in libinterp with direct calls to C++ function in this cset (http://hg.savannah.gnu.org/hgweb/octave/rev/35e3d199527c).  Closing report.

Rik <rik5>
Group administrator
Tue 24 Jan 2017 05:20:14 PM UTC, comment #5: 

Yes, you can call the built-in functions directly in some cases.  But we should not do that when it is possible to use liboctave functions directly.  For example, we shouldn't be packing matrix objects inside octave_value{,_list} objects just so Fsum can unpack them, then compute the sum, then put them back in octave_value{,_list} objects so we can unpack them again.

John W. Eaton <jwe>
Group administrator
Tue 24 Jan 2017 05:03:59 PM UTC, comment #4: 

Another note, looking in the list of instances that I got from grep'ing the code, this instance should not be replaced


corefcn/graphics.cc:9776:            octave::feval (fcn, args);


This is executing a callback function which is held in the variable "fcn".  This instance needs to continue using feval.


Rik <rik5>
Group administrator
Tue 24 Jan 2017 04:56:02 PM UTC, comment #3: 

The second argument is the number of output arguments (nargout).  For the function "sum", there is only one output.  But a function like "sort" might have two outputs.

I hadn't gotten around to it but this is exactly the way I was going to proceed.  Add


#include "builtin-defun-decls.h"


to the top of the files that need it, and then replace


feval ("fcn_name", args, nargout);


with


Ffcn_name (args, nargout);



Rik <rik5>
Group administrator
Tue 24 Jan 2017 09:02:47 AM UTC, comment #2: 

The example of comment #1 is bad, as "isequal" is a pure M-file. Another example:

Before:


octave_value_list in;
in(0) = val_A;
in(1) = val_B;
octave_value_list result = octave::feval ("sum", in, 1);


After:


#include "builtin-defun-decls.h"

...

octave_value_list in;
in(0) = val_A;
in(1) = val_B;
octave_value_list result = Fsum (in, 1);


Kai Torben Ohlhus <siko1056>
Group Member
Tue 24 Jan 2017 08:52:58 AM UTC, comment #1: 

A remedy could be the following pattern to refactor the code:

Before:


octave_value_list in;
in(0) = matrix_A;
in(1) = matrix_B;
octave_value_list result = octave::feval ("isequal", args, 1);


After:


#include "builtin-defun-decls.h"

...

octave_value_list in;
in(0) = matrix_A;
in(1) = matrix_B;
octave_value_list result = Fisequal (args, 1);


The remedy is inspired by "examples/code/standalonebuiltin.cc". This compiles for me (I am currently working on bug #50105 but decided to post here for generality). Now I want to know if this approach is desired and what does the "1" in the end of Fisequal (args, 1) mean? In "libinterpreter/builtin-defun-decls.h" it is "0" by default. Is there any documentation available? The file "libinterpreter/builtin-defun-decls.h" is generated by the undocumented "build-aux/mk-builtins.pl".

Kai Torben Ohlhus <siko1056>
Group Member
Sat 21 Jan 2017 11:07:17 PM UTC, original submission:  

Within C++, interpreter functions written in C++ like "sum" can be called directly using the name with 'F' prepended.  For example, "Fsum" or "Flasterr".  However, the code often makes use of feval to do this instead.

Whenever the function name might be overloaded in the symbol table, such as with display for class objects, then the invocation implementation needs to remain as feval.  However, the rest of the time these could be

Examples:


corefcn/defun.cc:64:  octave::feval ("print_usage", octave_value (name), 0);
corefcn/dot.cc:184:      tmp = octave::feval ("sum", tmp, 1);
corefcn/graphics.cc:9749:              octave::feval ("lasterr",
corefcn/graphics.cc:9776:            octave::feval (fcn, args);
corefcn/graphics.cc:9782:            octave::feval ("lasterr",
corefcn/graphics.cc:11039:      octave::feval ("graphics_toolkit", args);
corefcn/graphics.cc:11553:  octave_value_list result = octave::feval ("isequal", args, 1);
corefcn/input.cc:208:          octave::feval ("drawnow");
octave-value/ov-java.cc:1983:          retval = octave::feval (std::string ("javaMethod"), ovl, 1);
octave-value/ov-java.cc:1992:          retval = octave::feval (std::string ("__java_get__"), ovl, 1);
octave-value/ov-java.cc:2048:          octave::feval ("__java_set__", ovl, 0);


See the related bug #50105.

Rik <rik5>
Group administrator

 

(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 siko1056 (Knows everything about Octave.)
  • -email is unavailable- added by siko1056 (Posted a comment)
  • -email is unavailable- added by rik5 (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 3 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2017-02-01 rik5 StatusNone Fixed
        Open/ClosedOpen Closed
    2017-01-24 siko1056 Carbon-Copy- Added jwe

    Back to the top

    Powered by Savane 3.13-4448.
    Corresponding source code