bugGNU Octave - Bugs: bug #61105, call to nested function triggers...


bug #61105: call to nested function triggers "internal error: invalid access link in function call stack"

Submitter:  John W. Eaton <jwe>
Submitted:  Wed 01 Sep 2021 07:40:27 PM UTC
Category:  Interpreter Severity:  4 - Important
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  Fixed Assigned to:  jwe
Originator Name:  jwe Open/Closed:  * Closed
Release:  * 6.3.0 Operating System:  * Any
* Mandatory Fields

Add a New Comment (Rich Markup)

Comment Type & Canned Response:


Wed 01 Sep 2021 08:59:21 PM UTC, comment #1: 

I pushed the following change on stable and merged with default:


Closing as fixed.

John W. Eaton <jwe>
Project Administrator
Wed 01 Sep 2021 07:40:27 PM UTC, original submission:  

Calling the function

function r = bad_access ()
  a = 3;
  b = 5;
  c = 7;
  function r = f1 (f, x)
    r = f(x) + a;
  function r = f2 (y)
    function r2 = f3 (z)
      r2 = z^2 + b*y;
    r = f1 (@f3, y) + c;
  r = f2 (2)

results in the following error:

error: internal error: invalid access link in function call stack
error: called from
    bad_access>f3 at line 10 column 10
    bad_access>f1 at line 6 column 7
    bad_access>f2 at line 12 column 7
    bad_access at line 14 column 5

Bisecting on the stable branch points to this changeset:

The first bad revision is:
changeset:   29832:6d1224698acf
branch:      stable
parent:      29825:290eff7148bb
user:        John W. Eaton <jwe@octave.org>
date:        Tue Jun 29 05:25:34 2021 -0400
summary:     fix scoping issue for handles to sibling nested functions (bug #60845)

I don't think there is anything wrong with the logic of that change, but it exposes a problem with storing parent function names in function objects in some cases.  A possible fix is:

--- a/libinterp/corefcn/symscope.cc
+++ b/libinterp/corefcn/symscope.cc
@@ -197,6 +197,20 @@ namespace octave

+  symbol_scope_rep::cache_parent_fcn_names (const std::list<std::string>& names)
+  {
+    m_parent_fcn_names = names;
+    if (m_code && m_code->is_user_function ())
+      {
+        octave_user_function *fcn
+          = dynamic_cast<octave_user_function *> (m_code);
+        fcn->stash_parent_fcn_name (names.front ());
+      }
+  }
+  void
   symbol_scope_rep::set_parent (const std::shared_ptr<symbol_scope_rep>& parent)
     m_parent = std::weak_ptr<symbol_scope_rep> (parent);
diff --git a/libinterp/corefcn/symscope.h b/libinterp/corefcn/symscope.h
--- a/libinterp/corefcn/symscope.h
+++ b/libinterp/corefcn/symscope.h
@@ -262,10 +262,7 @@ namespace octave
       return m_parent_fcn_names;

-    void cache_parent_fcn_names (const std::list<std::string>& names)
-    {
-      m_parent_fcn_names = names;
-    }
+    void cache_parent_fcn_names (const std::list<std::string>& names);

     octave_user_code *user_code (void) const { return m_code; }

I'll check in a proper changeset with a test on the stable branch after I have a bug report number.

While investigating this problem, I also found that we are storing info about parent functions directly in the function object and also in the scope object that the function contains. Since storing the same info in multiple places almost always leads to trouble and this mess is almost certainly my work, I’ll see if I can eliminate the duplication with another change on the default branch.

John W. Eaton <jwe>
Project Administrator


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

Attach Files:

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 (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 project members can vote.





    Follow 2 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2021-09-01 jwe StatusNone Fixed
        Open/ClosedOpen Closed

    Back to the top

    Powered by Savane 3.9