changeset 32378:a2a04f9d56f8

VM Do proper pointer arithmetics on 32bit systems Some sloppy pointer arithmetics assumes the stack_element union and pointers are the same size, which is not true on 32-bit systems. Use stack_element* instead of octave_value*. The changed functions in pt-tm-const.* was added in 13fbc97f9362 for the VM. * pt-bytecode-vm.cc: Proper difference * libinterp/parse-tree/pt-tm-const.cc: Use stack_element* instead of octave_value*. Fwd declare stack_element. * libinterp/parse-tree/pt-tm-const.h: Move functions defs to .cc to hide stack_element* def
author Petter
date Sat, 07 Oct 2023 02:03:09 +0200
parents 94ba5c27d895
children 315dbb07cdde
files libinterp/parse-tree/pt-bytecode-vm.cc libinterp/parse-tree/pt-tm-const.cc libinterp/parse-tree/pt-tm-const.h
diffstat 3 files changed, 39 insertions(+), 30 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/parse-tree/pt-bytecode-vm.cc	Sat Oct 07 01:33:56 2023 +0200
+++ b/libinterp/parse-tree/pt-bytecode-vm.cc	Sat Oct 07 02:03:09 2023 +0200
@@ -3682,11 +3682,11 @@
 
     // The first element is down the stack
     // and the last element is at the top.
-    octave_value *first_arg = &(*sp).ov - n_el;
+    stack_element *first_arg = &sp[-n_el];
 
     // The stack pointer is pointing to the first unused
     // stack position, so it is the end pointer.
-    octave_value *end_arg = &(*sp).ov;
+    stack_element *end_arg = sp;
 
     try
       {
@@ -3729,11 +3729,11 @@
 
         // The first element is down the stack
         // and the last element is at the top.
-        octave_value *first_arg = &(*sp).ov - n_el;
+        stack_element *first_arg = &sp[-n_el];
 
         // The stack pointer is pointing to the first unused
         // stack position, so it is the end pointer.
-        octave_value *end_arg = &(*sp).ov;
+        stack_element *end_arg = sp;
 
         try
           {
@@ -3759,11 +3759,11 @@
 
         // The first element is down the stack
         // and the last element is at the top.
-        octave_value *first_arg = &(*sp).ov - n_el;
+        stack_element *first_arg = &sp[-n_el];
 
         // The stack pointer is pointing to the first unused
         // stack position, so it is the end pointer.
-        octave_value *end_arg = &(*sp).ov;
+        stack_element *end_arg = sp;
 
         try
           {
--- a/libinterp/parse-tree/pt-tm-const.cc	Sat Oct 07 01:33:56 2023 +0200
+++ b/libinterp/parse-tree/pt-tm-const.cc	Sat Oct 07 02:03:09 2023 +0200
@@ -38,6 +38,7 @@
 #include "ovl.h"
 #include "pt-arg-list.h"
 #include "pt-bp.h"
+#include "pt-bytecode-vm.h"
 #include "pt-eval.h"
 #include "pt-exp.h"
 #include "pt-mat.h"
@@ -60,6 +61,12 @@
 
 OCTAVE_BEGIN_NAMESPACE(octave)
 
+tm_row_const::tm_row_const (const stack_element *beg, const stack_element *end)
+    : tm_info (beg == end), m_values ()
+{
+  init (beg, end);
+}
+
 void tm_row_const::cellify ()
 {
   bool elt_changed = false;
@@ -228,7 +235,7 @@
 // The common parts should be factored out into a single function that
 // is used by the others.
 
-void tm_row_const::init (const octave_value *beg, const octave_value *end)
+void tm_row_const::init (const stack_element *beg, const stack_element *end)
 {
   bool first_elem = true;
 
@@ -236,7 +243,7 @@
     {
       octave_quit ();
 
-      octave_value tmp = *beg;
+      octave_value tmp = beg->ov;
 
       if (tmp.is_undefined ())
         error ("undefined element in matrix list");
@@ -282,6 +289,19 @@
     }
 }
 
+tm_const::tm_const (const stack_element *beg, const stack_element *end,
+                    octave_idx_type n_rows, tree_evaluator& tw)
+  : tm_info (beg == end), m_evaluator (tw), m_tm_rows ()
+{
+  init (beg, end, n_rows);
+}
+
+tm_const::tm_const (const stack_element *beg, const stack_element *end,
+                    const std::vector<int>& row_lengths, tree_evaluator& tw)
+  : tm_info (beg == end), m_evaluator (tw), m_tm_rows ()
+{
+  init (beg, end, row_lengths);
+}
 
 octave_value tm_const::concat (char string_fill_char) const
 {
@@ -499,7 +519,7 @@
 // is used by the others.
 
 // For variable length rows
-void tm_const::init (const octave_value *beg, const octave_value *end,
+void tm_const::init (const stack_element *beg, const stack_element *end,
                      const std::vector<int>& row_lengths)
 {
   bool first_elem = true;
@@ -628,7 +648,7 @@
 // is used by the others.
 
 // Fixed row size
-void tm_const::init (const octave_value *beg, const octave_value *end,
+void tm_const::init (const stack_element *beg, const stack_element *end,
                      octave_idx_type row_length)
 {
   bool first_elem = true;
--- a/libinterp/parse-tree/pt-tm-const.h	Sat Oct 07 01:33:56 2023 +0200
+++ b/libinterp/parse-tree/pt-tm-const.h	Sat Oct 07 02:03:09 2023 +0200
@@ -46,6 +46,7 @@
 OCTAVE_BEGIN_NAMESPACE(octave)
 
 class tree_evaluator;
+union stack_element;
 
 // Evaluate tree_matrix objects and convert them to octave_value
 // arrays (full and sparse numeric, char, cell, struct, class and
@@ -157,11 +158,7 @@
     init (row, tw);
   }
 
-  tm_row_const (const octave_value *beg, const octave_value *end)
-    : tm_info (beg == end), m_values ()
-  {
-    init (beg, end);
-  }
+  tm_row_const (const stack_element *beg, const stack_element *end);
 
   tm_row_const (const tm_row_const&) = default;
 
@@ -188,7 +185,7 @@
   void init_element (const octave_value&, bool&);
 
   void init (const tree_argument_list&, tree_evaluator& tw);
-  void init (const octave_value *beg, const octave_value *end);
+  void init (const stack_element *beg, const stack_element *end);
 };
 
 class tm_const : public tm_info
@@ -206,19 +203,11 @@
     init (tm);
   }
 
-  tm_const (const octave_value *beg, const octave_value *end,
-            octave_idx_type n_rows, tree_evaluator& tw)
-    : tm_info (beg == end), m_evaluator (tw), m_tm_rows ()
-  {
-     init (beg, end, n_rows);
-  }
+  tm_const (const stack_element *beg, const stack_element *end,
+            octave_idx_type n_rows, tree_evaluator& tw);
 
-  tm_const (const octave_value *beg, const octave_value *end,
-            const std::vector<int>& row_lengths, tree_evaluator& tw)
-    : tm_info (beg == end), m_evaluator (tw), m_tm_rows ()
-  {
-     init (beg, end, row_lengths);
-  }
+  tm_const (const stack_element *beg, const stack_element *end,
+            const std::vector<int>& row_lengths, tree_evaluator& tw);
 
   OCTAVE_DISABLE_COPY_MOVE (tm_const)
 
@@ -238,10 +227,10 @@
 
   void init (const tree_matrix& tm);
 
-  void init (const octave_value *beg, const octave_value *end,
+  void init (const stack_element *beg, const stack_element *end,
              octave_idx_type row_length);
 
-  void init (const octave_value *beg, const octave_value *end,
+  void init (const stack_element *beg, const stack_element *end,
              const std::vector<int>& row_lengths);
 
   octave_value char_array_concat (char string_fill_char) const;