bugGNU Octave - Bugs: bug #57941, Handle to a nested function with...

 
 

bug #57941: Handle to a nested function with more than one input does not work

Submitter:  Marco Caliari <caliari>
Submitted:  Mon 02 Mar 2020 03:23:37 PM UTC
   
 
Category:  Interpreter Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Unexpected Error or Warning
Status:  Fixed Assigned to:  jwe
Originator Name:  Open/Closed:  * Closed
Release:  * dev Operating System:  * GNU/Linux
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Thu 11 Jun 2020 01:44:03 PM UTC, comment #4: 

I believe this problem is fixed after the following changeset:

  http://hg.savannah.gnu.org/hgweb/octave/rev/e760fef2829c

I also added a test that attempts to verify that the bug is fixed:

  http://hg.savannah.gnu.org/hgweb/octave/rev/23fe97205db5

John W. Eaton <jwe>
Group administrator
Tue 03 Mar 2020 07:47:09 AM UTC, comment #3: 

Hi, i hope this fix will be applied to Octave 6.1 already?


Stephan Gebauer <stephan_ii>
Mon 02 Mar 2020 08:04:54 PM UTC, comment #2: 

I see the problem now.  The context for closures is not being stored correctly unless the function handle/closure is returned from the function where it is created.  So if you write


function [fh1, fh2] = test_hnf (A)
  fh1 = @nested1;
  function z = nested1 (x)
    z = A * x;
  end
  fh2 = @nested2;
  function z = nested2 (x,y)
    z = A * x .* y;
  end
end


and then use it as


[fh1, fh2] = test_hnf (1);
quad (fh1, 0, 1)
quad2d (fh2, 0, 1, 0, 1)


it will work as expected.

I'm working on a fix.

Thanks for reporting this problem.

John W. Eaton <jwe>
Group administrator
Mon 02 Mar 2020 05:15:32 PM UTC, comment #1: 

This looks like an error in the way offsets to values in the call stack are managed when calling nested functions through handles.  Possibly the context for closure frames is not being set correctly?  I'm looking at it.

John W. Eaton <jwe>
Group administrator
Mon 02 Mar 2020 03:23:37 PM UTC, original submission:  

Dear all, if you call the attached file with


test_hnf(1)


you see that the handle to nested1 (with one input parameter) works, while the handle to nested2 (with two input parameters) gives


error: 'A' undefined near line 8, column 8
error: called from
    test_hnf>nested2 at line 8 column 7
    quad2d>tensorproduct at line 408 column 5
    quad2d at line 305 column 41
    test_hnf at line 6 column 3


The bug is maybe related to bug #48086.

Marco Caliari <caliari>
Group Member

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #48534:  test_hnf.m added by caliari (185B - text/x-objcsrc)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by stephan_ii (Posted a comment)
  • -email is unavailable- added by jwe (Posted a comment)
  • -email is unavailable- added by caliari (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 6 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2020-07-27 jwe StatusReady For Test Fixed
        Open/ClosedOpen Closed
    2020-06-11 jwe StatusConfirmed Ready For Test
    2020-03-02 jwe StatusNone Confirmed
        Assigned toNone jwe
    2020-03-02 caliari Attached File- Added test_hnf.m, #48534

    Back to the top

    Powered by Savane 3.13-f8d8.
    Corresponding source code