changeset 32843:20c5b16170c6 bytecode-interpreter

Backed out changeset 3c4c1af66055
author John W. Eaton <jwe@octave.org>
date Wed, 24 Jan 2024 21:52:52 -0500
parents f7dd1c796277
children 75825900637c
files libinterp/octave-value/ov.cc libinterp/octave-value/ov.h
diffstat 2 files changed, 11 insertions(+), 34 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/octave-value/ov.cc	Wed Jan 24 21:52:25 2024 -0500
+++ b/libinterp/octave-value/ov.cc	Wed Jan 24 21:52:52 2024 -0500
@@ -117,29 +117,12 @@
 
 // Octave's value type.
 
-// Special class to do as a nil value that never reaches
-// a count of 0 so we don't need to check for for "nil_rep()"
-// pointer when deleting octave_base_value:s in the octave_value
-// destructor.
-class octave_nil_value : octave_base_value
+octave_base_value *
+octave_value::nil_rep ()
 {
-public:
-  octave_nil_value ()
-  {
-    m_count++; // Also increased in octave_base_value()
-  }
-
-  // A clone of the nil value just returns itself since there can be only
-  // one nil value.
-  octave_base_value *
-  clone () const
-  {
-    octave_value_nilrep.m_count++;
-    return &octave_value_nilrep;
-  }
-};
-
-octave_nil_value octave_value_nilrep;
+  static octave_base_value nr;
+  return &nr;
+}
 
 std::string
 octave_value::unary_op_as_string (unary_op op)
--- a/libinterp/octave-value/ov.h	Wed Jan 24 21:52:25 2024 -0500
+++ b/libinterp/octave-value/ov.h	Wed Jan 24 21:52:52 2024 -0500
@@ -72,15 +72,12 @@
 class octave_fcn_handle;
 class octave_value_list;
 class octave_fcn_cache;
-class octave_nil_value;
 
 #include "mxtypes.h"
 
 #include "oct-stream.h"
 #include "ov-base.h"
 
-OCTINTERP_API extern octave_nil_value octave_value_nilrep;
-
 class OCTINTERP_API octave_value
 {
 public:
@@ -355,7 +352,7 @@
     // 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)
+    if (m_rep && --m_rep->m_count == 0 && m_rep != nil_rep ())
       delete m_rep;
   }
 
@@ -365,7 +362,7 @@
       {
         octave_base_value *r = m_rep->unique_clone ();
 
-        if (--m_rep->m_count == 0)
+        if (--m_rep->m_count == 0 && m_rep != nil_rep ())
           delete m_rep;
 
         m_rep = r;
@@ -381,7 +378,7 @@
       {
         octave_base_value *r = m_rep->unique_clone ();
 
-        if (--m_rep->m_count == 0)
+        if (--m_rep->m_count == 0 && m_rep != nil_rep ())
           delete m_rep;
 
         m_rep = r;
@@ -400,7 +397,7 @@
   {
     if (m_rep != a.m_rep)
       {
-        if (--m_rep->m_count == 0)
+        if (--m_rep->m_count == 0 && m_rep != nil_rep ())
           delete m_rep;
 
         m_rep = a.m_rep;
@@ -418,7 +415,7 @@
 
     if (this != &a)
       {
-        if (m_rep && --m_rep->m_count == 0)
+        if (m_rep && --m_rep->m_count == 0 && m_rep != nil_rep ())
           delete m_rep;
 
         m_rep = a.m_rep;
@@ -1661,10 +1658,7 @@
   //! The real representation.
   octave_base_value *m_rep;
 
-  static OCTINTERP_API octave_base_value * nil_rep ()
-  {
-    return reinterpret_cast<octave_base_value*> (&octave_value_nilrep);
-  }
+  static OCTINTERP_API octave_base_value * nil_rep ();
 
 private: