changeset 30139:c789e728d57a

Backed out changeset 938794bc82b7 Renaming octave_base_value::count to m_count breaks some packages that define new octave_value data types. Maybe those packages shouldn't be touching the count directly, but they do. Since we may also want to switch to using std::shared_ptr to manage octave_value objects instead of our own custom reference counting implmentation, it is probably best to delay this change until we know exactly what path we want to take.
author John W. Eaton <jwe@octave.org>
date Wed, 08 Sep 2021 11:14:44 -0400
parents 2dca5c25237d
children a001811a68e6
files libinterp/octave-value/ov-base-diag.cc libinterp/octave-value/ov-base.cc libinterp/octave-value/ov-base.h libinterp/octave-value/ov-cell.cc libinterp/octave-value/ov-class.cc libinterp/octave-value/ov-classdef.cc libinterp/octave-value/ov-java.cc libinterp/octave-value/ov-perm.cc libinterp/octave-value/ov-re-diag.cc libinterp/octave-value/ov-struct.cc libinterp/octave-value/ov.cc libinterp/octave-value/ov.h
diffstat 12 files changed, 68 insertions(+), 74 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/octave-value/ov-base-diag.cc	Wed Sep 08 06:46:19 2021 -0400
+++ b/libinterp/octave-value/ov-base-diag.cc	Wed Sep 08 11:14:44 2021 -0400
@@ -192,7 +192,7 @@
                   {
                     m_matrix.dgelem (i0(0)) = val;
                     retval = this;
-                    this->m_count++;
+                    this->count++;
                     // invalidate cache
                     m_dense_cache = octave_value ();
                   }
@@ -220,7 +220,7 @@
                   {
                     m_matrix.dgelem (i0(0)) = val;
                     retval = this;
-                    this->m_count++;
+                    this->count++;
                     // invalidate cache
                     m_dense_cache = octave_value ();
                   }
--- a/libinterp/octave-value/ov-base.cc	Wed Sep 08 06:46:19 2021 -0400
+++ b/libinterp/octave-value/ov-base.cc	Wed Sep 08 11:14:44 2021 -0400
@@ -1248,7 +1248,7 @@
 
   if (done)
     {
-      m_count++;
+      count++;
       retval = octave_value (this);
     }
   else
@@ -1311,7 +1311,7 @@
           else
             tmp_rhs = rhs;
 
-          m_count++;
+          count++;
           octave_value tmp_lhs = octave_value (this);
 
           if (cf_this)
--- a/libinterp/octave-value/ov-base.h	Wed Sep 08 06:46:19 2021 -0400
+++ b/libinterp/octave-value/ov-base.h	Wed Sep 08 11:14:44 2021 -0400
@@ -254,9 +254,9 @@
 
   friend class octave_value;
 
-  octave_base_value (void) : m_count (1) { }
+  octave_base_value (void) : count (1) { }
 
-  octave_base_value (const octave_base_value&) : m_count (1) { }
+  octave_base_value (const octave_base_value&) : count (1) { }
 
   virtual ~octave_base_value (void) = default;
 
@@ -274,8 +274,7 @@
   virtual octave_base_value *
   unique_clone (void) { return clone (); }
 
-  virtual void break_closure_cycles (const std::shared_ptr<octave::stack_frame>&)
-  { }
+  virtual void break_closure_cycles (const std::shared_ptr<octave::stack_frame>&) { }
 
   virtual type_conv_info
   numeric_conversion_function (void) const
@@ -302,8 +301,7 @@
   virtual octave_value as_uint32 (void) const;
   virtual octave_value as_uint64 (void) const;
 
-  virtual octave_base_value * try_narrowing_conversion (void)
-  { return nullptr; }
+  virtual octave_base_value * try_narrowing_conversion (void) { return nullptr; }
 
   virtual void maybe_economize (void) { }
 
@@ -892,25 +890,21 @@
 
   OCTINTERP_API void reset (void) const;
 
+  // A reference count.
+  // NOTE: the declaration is octave_idx_type because with 64-bit indexing,
+  // it is well possible to have more than MAX_INT copies of a single value
+  // (think of an empty cell array with >2G elements).
+  octave::refcount<octave_idx_type> count;
+
   OCTINTERP_API static const char * get_umap_name (unary_mapper_t);
 
   OCTINTERP_API void warn_load (const char *type) const;
   OCTINTERP_API void warn_save (const char *type) const;
 
-  //--------
-
-  // A reference count.
-  // NOTE: the declaration is octave_idx_type because with 64-bit indexing,
-  // it is well possible to have more than MAX_INT copies of a single value
-  // (think of an empty cell array with >2G elements).
-  octave::refcount<octave_idx_type> m_count;
-
 private:
 
   OCTINTERP_API void wrong_type_arg_error (void) const;
 
-  //--------
-
   static int curr_print_indent_level;
   static bool beginning_of_line;
 
--- a/libinterp/octave-value/ov-cell.cc	Wed Sep 08 06:46:19 2021 -0400
+++ b/libinterp/octave-value/ov-cell.cc	Wed Sep 08 11:14:44 2021 -0400
@@ -364,7 +364,7 @@
         else
           octave_base_matrix<Cell>::assign (i, Cell (t_rhs));
 
-        m_count++;
+        count++;
         retval = octave_value (this);
       }
       break;
@@ -396,7 +396,7 @@
         else
           err_nonbraced_cs_list_assignment ();
 
-        m_count++;
+        count++;
         retval = octave_value (this);
       }
       break;
--- a/libinterp/octave-value/ov-class.cc	Wed Sep 08 06:46:19 2021 -0400
+++ b/libinterp/octave-value/ov-class.cc	Wed Sep 08 11:14:44 2021 -0400
@@ -208,16 +208,16 @@
 octave_base_value *
 octave_class::unique_clone (void)
 {
-  if (m_count == m_obsolete_copies)
+  if (count == m_obsolete_copies)
     {
       // All remaining copies are obsolete.  We don't actually need to clone.
-      m_count++;
+      count++;
       return this;
     }
   else
     {
       // In theory, this shouldn't be happening, but it's here just in case.
-      if (m_count < m_obsolete_copies)
+      if (count < m_obsolete_copies)
         m_obsolete_copies = 0;
 
       return clone ();
@@ -320,7 +320,7 @@
 
   if (meth.is_defined ())
     {
-      m_count++;
+      count++;
       octave_value_list args (1, octave_value (this));
 
       octave_value_list lv = octave::feval (meth.function_value (), args, 1);
@@ -363,7 +363,7 @@
     {
       octave_value_list args (idx.length () + 1, octave_value ());
 
-      m_count++;
+      count++;
       args(0) = octave_value (this);
 
       for (octave_idx_type i = 0; i < idx.length (); i++)
@@ -461,7 +461,7 @@
 
           args(1) = make_idx_args (type, idx, "subsref");
 
-          m_count++;
+          count++;
           args(0) = octave_value (this);
 
           // FIXME: for Matlab compatibility, let us attempt to set up a proper
@@ -525,7 +525,7 @@
                         const std::list<octave_value_list>& idx,
                         const octave_value& rhs)
 {
-  m_count++;
+  count++;
   return subsasgn_common (octave_value (this), type, idx, rhs);
 }
 
@@ -627,7 +627,7 @@
 
       obvp->subsasgn (type, idx, rhs);
 
-      m_count++;
+      count++;
       retval = octave_value (this);
 
       return retval;
@@ -753,7 +753,7 @@
 
             m_map.assign (idx.front (), key, t_rhs);
 
-            m_count++;
+            count++;
             retval = octave_value (this);
           }
         else
@@ -764,7 +764,7 @@
 
                 m_map.assign (idx.front (), rhs_map);
 
-                m_count++;
+                count++;
                 retval = octave_value (this);
               }
             else
@@ -774,7 +774,7 @@
 
                 m_map.delete_elements (idx.front ());
 
-                m_count++;
+                count++;
                 retval = octave_value (this);
               }
           }
@@ -809,7 +809,7 @@
             m_map.setfield (key, tmp_cell);
           }
 
-        m_count++;
+        count++;
         retval = octave_value (this);
       }
       break;
--- a/libinterp/octave-value/ov-classdef.cc	Wed Sep 08 06:46:19 2021 -0400
+++ b/libinterp/octave-value/ov-classdef.cc	Wed Sep 08 11:14:44 2021 -0400
@@ -88,7 +88,7 @@
 
           args(1) = make_idx_args (type, idx, "subsref");
 
-          m_count++;
+          count++;
           args(0) = octave_value (this);
 
           retval = meth.execute (args, nargout, true, "subsref");
@@ -131,7 +131,7 @@
 
           args(1) = make_idx_args (type, idx, "subsref");
 
-          m_count++;
+          count++;
           args(0) = octave_value (this);
 
           retval = meth.execute (args, 1, true, "subsref");
@@ -167,7 +167,7 @@
 
           args(1) = make_idx_args (type, idx, "subsasgn");
 
-          m_count++;
+          count++;
           args(0) = octave_value (this);
           args(2) = rhs;
 
@@ -216,7 +216,7 @@
 
       if (meth.ok ())
         {
-          m_count++;
+          count++;
           octave_value_list args (1, octave_value (this));
 
           octave_value_list lv = meth.execute (args, 1, true, "size");
@@ -246,7 +246,7 @@
         {
           octave_value_list args (idx.length () + 1, octave_value ());
 
-          m_count++;
+          count++;
           args(0) = octave_value (this);
 
           for (octave_idx_type i = 0; i < idx.length (); i++)
--- a/libinterp/octave-value/ov-java.cc	Wed Sep 08 06:46:19 2021 -0400
+++ b/libinterp/octave-value/ov-java.cc	Wed Sep 08 11:14:44 2021 -0400
@@ -2198,7 +2198,7 @@
       if (type.length () > 1 && type[1] == '(')
         {
           octave_value_list ovl;
-          m_count++;
+          count++;
           ovl(1) = octave_value (this);
           ovl(0) = (idx.front ())(0);
           auto it = idx.begin ();
@@ -2209,7 +2209,7 @@
       else
         {
           octave_value_list ovl;
-          m_count++;
+          count++;
           ovl(0) = octave_value (this);
           ovl(1) = (idx.front ())(0);
           retval = octave::F__java_get__ (ovl, 1);
@@ -2264,13 +2264,13 @@
         {
           // field assignment
           octave_value_list ovl;
-          m_count++;
+          count++;
           ovl(0) = octave_value (this);
           ovl(1) = (idx.front ())(0);
           ovl(2) = rhs;
           octave::F__java_set__ (ovl);
 
-          m_count++;
+          count++;
           retval = octave_value (this);
         }
       else if (type.length () > 2 && type[1] == '(')
@@ -2286,7 +2286,7 @@
           next_idx.erase (next_idx.begin ());
           u(0).subsasgn (type.substr (2), next_idx, rhs);
 
-          m_count++;
+          count++;
           retval = octave_value (this);
         }
       else if (type[1] == '.')
@@ -2297,7 +2297,7 @@
           next_idx.erase (next_idx.begin ());
           u(0).subsasgn (type.substr (1), next_idx, rhs);
 
-          m_count++;
+          count++;
           retval = octave_value (this);
         }
       else
@@ -2310,7 +2310,7 @@
           set_array_elements (current_env, TO_JOBJECT (to_java ()),
                               idx.front (), rhs);
 
-          m_count++;
+          count++;
           retval = octave_value (this);
         }
       break;
--- a/libinterp/octave-value/ov-perm.cc	Wed Sep 08 06:46:19 2021 -0400
+++ b/libinterp/octave-value/ov-perm.cc	Wed Sep 08 11:14:44 2021 -0400
@@ -118,7 +118,7 @@
           else
             {
               retval = this;
-              this->m_count++;
+              this->count++;
             }
         }
     }
--- a/libinterp/octave-value/ov-re-diag.cc	Wed Sep 08 06:46:19 2021 -0400
+++ b/libinterp/octave-value/ov-re-diag.cc	Wed Sep 08 11:14:44 2021 -0400
@@ -118,7 +118,7 @@
               else
                 {
                   retval = this;
-                  this->m_count++;
+                  this->count++;
                 }
             }
         }
--- a/libinterp/octave-value/ov-struct.cc	Wed Sep 08 06:46:19 2021 -0400
+++ b/libinterp/octave-value/ov-struct.cc	Wed Sep 08 11:14:44 2021 -0400
@@ -465,7 +465,7 @@
 
                 m_map.assign (idxf, key, tmp_cell);
 
-                m_count++;
+                count++;
                 retval = octave_value (this);
               }
             else
@@ -478,7 +478,7 @@
                     m_map.assign (idxf,
                                 key, Cell (t_rhs.storable_value ()));
 
-                    m_count++;
+                    count++;
                     retval = octave_value (this);
                   }
                 else
@@ -493,7 +493,7 @@
 
                 m_map.assign (idx.front (), rhs_map);
 
-                m_count++;
+                count++;
                 retval = octave_value (this);
               }
             else
@@ -503,7 +503,7 @@
 
                 m_map.delete_elements (idx.front ());
 
-                m_count++;
+                count++;
                 retval = octave_value (this);
               }
           }
@@ -540,7 +540,7 @@
             m_map.setfield (key, tmp_cell);
           }
 
-        m_count++;
+        count++;
         retval = octave_value (this);
       }
       break;
@@ -1268,7 +1268,7 @@
 
       m_map.setfield (key, t_rhs.storable_value ());
 
-      m_count++;
+      count++;
       retval = this;
     }
   else
--- a/libinterp/octave-value/ov.cc	Wed Sep 08 06:46:19 2021 -0400
+++ b/libinterp/octave-value/ov.cc	Wed Sep 08 11:14:44 2021 -0400
@@ -1232,7 +1232,7 @@
   : m_rep (new_rep)
 {
   if (borrow)
-    m_rep->m_count++;
+    m_rep->count++;
 }
 
 octave_base_value *
@@ -1275,7 +1275,7 @@
 
   if (tmp && tmp != m_rep)
     {
-      if (--m_rep->m_count == 0)
+      if (--m_rep->count == 0)
         delete m_rep;
 
       m_rep = tmp;
@@ -1666,7 +1666,7 @@
       octave::type_info::assign_op_fcn f = nullptr;
 
       // Only attempt to operate in-place if this variable is unshared.
-      if (m_rep->m_count == 1)
+      if (m_rep->count == 1)
         {
           int tthis = this->type_id ();
           int trhs = rhs.type_id ();
@@ -2292,14 +2292,14 @@
   if (isnull ())
     {
       octave_base_value *rc = m_rep->empty_clone ();
-      if (--m_rep->m_count == 0)
+      if (--m_rep->count == 0)
         delete m_rep;
       m_rep = rc;
     }
   else if (is_magic_int ())
     {
       octave_base_value *rc = new octave_scalar (m_rep->double_value ());
-      if (--m_rep->m_count == 0)
+      if (--m_rep->count == 0)
         delete m_rep;
       m_rep = rc;
     }
@@ -2327,7 +2327,7 @@
 octave_value::print_info (std::ostream& os, const std::string& prefix) const
 {
   os << prefix << "type_name: " << type_name () << "\n"
-     << prefix << "m_count:     " << get_count () << "\n"
+     << prefix << "count:     " << get_count () << "\n"
      << prefix << "m_rep info:  ";
 
   m_rep->print_info (os, prefix + ' ');
@@ -2470,14 +2470,14 @@
             {
               f (*m_rep);
 
-              if (old_rep && --old_rep->m_count == 0)
+              if (old_rep && --old_rep->count == 0)
                 delete old_rep;
             }
           else
             {
               if (old_rep)
                 {
-                  if (--m_rep->m_count == 0)
+                  if (--m_rep->count == 0)
                     delete m_rep;
 
                   m_rep = old_rep;
@@ -2496,7 +2496,7 @@
       octave::type_info::non_const_unary_op_fcn f = nullptr;
 
       // Only attempt to operate in-place if this variable is unshared.
-      if (m_rep->m_count == 1)
+      if (m_rep->count == 1)
         {
           octave::type_info& ti
             = octave::__get_type_info__ ("non_const_unary_op");
--- a/libinterp/octave-value/ov.h	Wed Sep 08 06:46:19 2021 -0400
+++ b/libinterp/octave-value/ov.h	Wed Sep 08 11:14:44 2021 -0400
@@ -170,7 +170,7 @@
   octave_value (void)
     : m_rep (nil_rep ())
   {
-    m_rep->m_count++;
+    m_rep->count++;
   }
 
   OCTINTERP_API octave_value (short int i);
@@ -359,7 +359,7 @@
   octave_value (const octave_value& a)
     : m_rep (a.m_rep)
   {
-    m_rep->m_count++;
+    m_rep->count++;
   }
 
   octave_value (octave_value&& a)
@@ -383,17 +383,17 @@
     // operator, rep may be a nullptr here.  We should only need to
     // protect the move assignment operator in a similar way.
 
-    if (m_rep && --m_rep->m_count == 0 && m_rep != nil_rep ())
+    if (m_rep && --m_rep->count == 0 && m_rep != nil_rep ())
       delete m_rep;
   }
 
   void make_unique (void)
   {
-    if (m_rep->m_count > 1)
+    if (m_rep->count > 1)
       {
         octave_base_value *r = m_rep->unique_clone ();
 
-        if (--m_rep->m_count == 0 && m_rep != nil_rep ())
+        if (--m_rep->count == 0 && m_rep != nil_rep ())
           delete m_rep;
 
         m_rep = r;
@@ -405,11 +405,11 @@
   // know a certain copy, typically within a cell array, to be obsolete.
   void make_unique (int obsolete_copies)
   {
-    if (m_rep->m_count > obsolete_copies + 1)
+    if (m_rep->count > obsolete_copies + 1)
       {
         octave_base_value *r = m_rep->unique_clone ();
 
-        if (--m_rep->m_count == 0 && m_rep != nil_rep ())
+        if (--m_rep->count == 0 && m_rep != nil_rep ())
           delete m_rep;
 
         m_rep = r;
@@ -428,11 +428,11 @@
   {
     if (m_rep != a.m_rep)
       {
-        if (--m_rep->m_count == 0 && m_rep != nil_rep ())
+        if (--m_rep->count == 0 && m_rep != nil_rep ())
           delete m_rep;
 
         m_rep = a.m_rep;
-        m_rep->m_count++;
+        m_rep->count++;
       }
 
     return *this;
@@ -446,7 +446,7 @@
 
     if (this != &a)
       {
-        if (m_rep && --m_rep->m_count == 0 && m_rep != nil_rep ())
+        if (m_rep && --m_rep->count == 0 && m_rep != nil_rep ())
           delete m_rep;
 
         m_rep = a.m_rep;
@@ -456,7 +456,7 @@
     return *this;
   }
 
-  octave_idx_type get_count (void) const { return m_rep->m_count; }
+  octave_idx_type get_count (void) const { return m_rep->count; }
 
   octave_base_value::type_conv_info numeric_conversion_function (void) const
   { return m_rep->numeric_conversion_function (); }