changeset 27149:61226b7bd6b9

fix calculation of value offsets for variables added to script scopes * stack-frame.cc (script_stack_frame::get_val_offsets): Attempt to find valid value offset (if any) for value added to scope. (script_stack_frame::get_val_offsets_with_insert): Likewise.
author John W. Eaton <jwe@octave.org>
date Tue, 04 Jun 2019 20:04:21 +0000
parents 224ce8329074
children 961b76f59fa2
files libinterp/corefcn/stack-frame.cc
diffstat 1 files changed, 33 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/stack-frame.cc	Wed Jun 05 12:27:41 2019 +0200
+++ b/libinterp/corefcn/stack-frame.cc	Tue Jun 04 20:04:21 2019 +0000
@@ -888,6 +888,18 @@
         // invoked.
 
         frame_offset = m_lexical_frame_offsets.at (data_offset);
+
+        if (frame_offset == 0)
+          {
+            // If the frame offset stored in m_lexical_frame_offsets is
+            // zero, then the data offset in the evaluation scope has
+            // not been determined so try to do that now.  The symbol
+            // may have been added by eval and without calling
+            // resize_and_update_script_offsets.
+
+            return get_val_offsets_internal (sym, frame_offset, data_offset);
+          }
+
         data_offset = m_value_offsets.at (data_offset);
       }
     else
@@ -925,6 +937,27 @@
         // invoked.
 
         frame_offset = m_lexical_frame_offsets.at (data_offset);
+
+        if (frame_offset == 0)
+          {
+            // If the frame offset stored in m_lexical_frame_offsets is
+            // zero, then the data offset in the evaluation scope has
+            // not been determined so try to do that now.  The symbol
+            // may have been added by eval and without calling
+            // resize_and_update_script_offsets.
+
+            // We don't need to resize here.  That case is handled above.
+
+            // FIXME: We should be able to avoid creating the map object
+            // and the looping in the set_scripts_offsets_internal
+            // function.  Can we do that without (or with minimal) code
+            // duplication?
+
+            std::map<std::string, symbol_record> tmp_symbols;
+            tmp_symbols[sym.name ()] = sym;
+            set_script_offsets_internal (tmp_symbols);
+          }
+
         data_offset = m_value_offsets.at (data_offset);
       }
     else