diff libinterp/corefcn/stack-frame.h @ 28426:9a3deb17b4ea stable

use shared_ptr for stack frames in call stack and for accesss and static links * call-stack.h, call-stack.cc: Use std::shared_ptr<stack_frame> instead of bare pointer for elements of call stack. Change all uses. * stack-frame.h, stack-frame.cc (stack_frame::static_link, stack_frame::access_link): Use std::shared_ptr<stack_frame> instead of bare pointer. Change all uses. (stack_frame::workspace): New function. * ov-fcn-handle.h, ov-fcn-handle.cc (octave_fcn_handle::m_closure_frames): Now a std::shared_ptr<stack_frame> object instead of a list of copied stack frames. Change all uses. (octave_fcn_handle::push_closure_context): Simply store std::shared_ptr to current stack frame. (octave_fcn_handle::workspace): Call stack_frame::workspace to get workspace info when we have closure frames.
author John W. Eaton <jwe@octave.org>
date Sat, 25 Apr 2020 13:17:11 -0400
parents a5be4fc661d6
children 8eb8ba8aff9a
line wrap: on
line diff
--- a/libinterp/corefcn/stack-frame.h	Fri Apr 24 14:21:07 2020 -0400
+++ b/libinterp/corefcn/stack-frame.h	Sat Apr 25 13:17:11 2020 -0400
@@ -32,6 +32,7 @@
 #include <iosfwd>
 #include <list>
 #include <map>
+#include <memory>
 #include <string>
 
 class octave_value;
@@ -139,7 +140,8 @@
     stack_frame (void) = delete;
 
     stack_frame (tree_evaluator& tw, size_t index,
-                 stack_frame *static_link, stack_frame *access_link)
+                 const std::shared_ptr<stack_frame>& static_link,
+                 const std::shared_ptr<stack_frame>& access_link)
       : m_evaluator (tw), m_line (-1), m_column (-1), m_index (index),
         m_static_link (static_link), m_access_link (access_link),
         m_dispatch_class ()
@@ -148,24 +150,25 @@
     // Compiled function.
     static stack_frame *
     create (tree_evaluator& tw, octave_function *fcn, size_t index,
-            stack_frame *static_link);
+            const std::shared_ptr<stack_frame>& static_link);
 
     // Script.
     static stack_frame *
     create (tree_evaluator& tw, octave_user_script *script,
             unwind_protect *up_frame, size_t index,
-            stack_frame *static_link);
+            const std::shared_ptr<stack_frame>& static_link);
 
     // User-defined function.
     static stack_frame *
     create (tree_evaluator& tw, octave_user_function *fcn,
             unwind_protect *up_frame, size_t index,
-            stack_frame *static_link, stack_frame *access_link = nullptr);
+            const std::shared_ptr<stack_frame>& static_link,
+            const std::shared_ptr<stack_frame>& access_link = std::shared_ptr<stack_frame> ());
 
     // Scope.
     static stack_frame *
     create (tree_evaluator& tw, const symbol_scope& scope, size_t index,
-            stack_frame *static_link);
+            const std::shared_ptr<stack_frame>& static_link);
 
     stack_frame (const stack_frame& elt) = default;
 
@@ -242,6 +245,8 @@
 
     symbol_info_list all_variables (void);
 
+    octave_value workspace (void);
+
     std::list<std::string> variable_names (void) const;
 
     // Look for named symbol visible from current scope.  Don't
@@ -293,11 +298,13 @@
       mark_global (sym);
     }
 
-    stack_frame * static_link (void) const {return m_static_link; }
+    std::shared_ptr<stack_frame>
+    static_link (void) const {return m_static_link; }
 
-    stack_frame * access_link (void) const {return m_access_link; }
+    std::shared_ptr<stack_frame>
+    access_link (void) const {return m_access_link; }
 
-    void set_closure_links (stack_frame *dup_frame)
+    void set_closure_links (const std::shared_ptr<stack_frame>& dup_frame)
     {
       m_static_link = dup_frame;
       m_access_link = dup_frame;
@@ -556,12 +563,12 @@
 
     // Pointer to the nearest parent frame that contains variable
     // information (script, function, or scope).
-    stack_frame *m_static_link;
+    std::shared_ptr<stack_frame> m_static_link;
 
     // Pointer to the nearest lexical parent frame.  Used to access
     // non-local variables for nested and anonymous functions or as a
     // link to the parent frame in which a script is executed.
-    stack_frame *m_access_link;
+    std::shared_ptr<stack_frame> m_access_link;
 
     // Allow function handles to temporarily store their dispatch class
     // in the call stack.