changeset 29186:eea3a92651d3

maint: merge stable to default.
author John W. Eaton <jwe@octave.org>
date Mon, 14 Dec 2020 21:00:01 -0500
parents dd4cb1ad9dc8 (current diff) 76c94c998d7b (diff)
children ed1a8af4242f
files libinterp/octave-value/ov-fcn-handle.cc
diffstat 2 files changed, 31 insertions(+), 44 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/octave-value/ov-fcn-handle.cc	Mon Dec 14 14:31:27 2020 -0800
+++ b/libinterp/octave-value/ov-fcn-handle.cc	Mon Dec 14 21:00:01 2020 -0500
@@ -2567,7 +2567,7 @@
 octave_fcn_handle::octave_fcn_handle (const octave_fcn_handle& fh)
   : octave_base_value (fh)
 {
-  m_rep = fh.m_rep->clone ();
+  m_rep.reset (fh.m_rep->clone ());
 }
 
 dim_vector
@@ -2586,7 +2586,7 @@
 bool
 octave_fcn_handle::load_ascii (std::istream& is)
 {
-  octave::base_fcn_handle *new_rep = nullptr;
+  std::shared_ptr<octave::base_fcn_handle> new_rep;
 
   // Read enough to detect type then create new rep object and dispatch
   // to finish loading object.
@@ -2631,9 +2631,9 @@
       is >> name;
 
       if (name == anonymous)
-        new_rep = new octave::anonymous_fcn_handle ();
+        new_rep.reset (new octave::anonymous_fcn_handle ());
       else
-        new_rep = new octave::simple_fcn_handle (name, fpath, octaveroot);
+        new_rep.reset (new octave::simple_fcn_handle (name, fpath, octaveroot));
     }
   else
     {
@@ -2644,30 +2644,30 @@
           std::string name;
           is >> name;
 
-          new_rep = new octave::simple_fcn_handle (name, fpath, octaveroot);
+          new_rep.reset (new octave::simple_fcn_handle (name, fpath, octaveroot));
         }
       else if (subtype == "scopedfunction")
         {
           std::string name;
           is >> name;
 
-          new_rep = new octave::scoped_fcn_handle (name, fpath, octaveroot);
+          new_rep.reset (new octave::scoped_fcn_handle (name, fpath, octaveroot));
         }
       else if (subtype == "anonymous")
-        new_rep = new octave::anonymous_fcn_handle ();
+        new_rep.reset (new octave::anonymous_fcn_handle ());
       else if (subtype == "nested")
         {
           std::string name;
           is >> name;
 
-          new_rep = new octave::nested_fcn_handle (name, fpath, octaveroot);
+          new_rep.reset (new octave::nested_fcn_handle (name, fpath, octaveroot));
         }
       else if (subtype == "classsimple")
         {
           std::string name;
           is >> name;
 
-          new_rep = new octave::class_simple_fcn_handle (name, fpath, octaveroot);
+          new_rep.reset (new octave::class_simple_fcn_handle (name, fpath, octaveroot));
         }
     }
 
@@ -2675,12 +2675,8 @@
     return false;
 
   if (! new_rep->load_ascii (is))
-    {
-      delete new_rep;
-      return false;
-    }
-
-  delete m_rep;
+    return false;
+
   m_rep = new_rep;
 
   return true;
@@ -2715,7 +2711,7 @@
   if (! is)
     return false;
 
-  octave::base_fcn_handle *new_rep = nullptr;
+  std::shared_ptr<octave::base_fcn_handle> new_rep;
 
   size_t anl = anonymous.length ();
 
@@ -2726,7 +2722,7 @@
       // number of local variables appended.  We decode that inside the
       // load_binary function.
 
-      new_rep = new octave::anonymous_fcn_handle (name);
+      new_rep.reset (new octave::anonymous_fcn_handle (name));
     }
   else
     {
@@ -2765,25 +2761,21 @@
       // following list.
 
       if (subtype == "simple")
-        new_rep = new octave::simple_fcn_handle (name, fpath, octaveroot);
+        new_rep.reset (new octave::simple_fcn_handle (name, fpath, octaveroot));
       else if (subtype == "scopedfunction")
-        new_rep = new octave::scoped_fcn_handle (name, fpath, octaveroot);
+        new_rep.reset (new octave::scoped_fcn_handle (name, fpath, octaveroot));
       else if (subtype == "nested")
-        new_rep = new octave::nested_fcn_handle (name, fpath, octaveroot);
+        new_rep.reset (new octave::nested_fcn_handle (name, fpath, octaveroot));
       else if (subtype == "classsimple")
-        new_rep = new octave::class_simple_fcn_handle (name, fpath, octaveroot);
+        new_rep.reset (new octave::class_simple_fcn_handle (name, fpath, octaveroot));
     }
 
   if (! new_rep)
     return false;
 
   if (! new_rep->load_binary (is, swap, fmt))
-    {
-      delete new_rep;
-      return false;
-    }
-
-  delete m_rep;
+    return false;
+
   m_rep = new_rep;
 
   return true;
@@ -2876,14 +2868,14 @@
 
   std::string name (nm_tmp);
 
-  octave::base_fcn_handle *new_rep = nullptr;
+  std::shared_ptr<octave::base_fcn_handle> new_rep;
 
   if (name == anonymous)
     {
       // Even with extra info stored in the function name, anonymous
       // functions look the same.
 
-      new_rep = new octave::anonymous_fcn_handle ();
+      new_rep.reset (new octave::anonymous_fcn_handle ());
     }
   else
     {
@@ -2922,27 +2914,21 @@
       // following list.
 
       if (subtype == "simple")
-        new_rep = new octave::simple_fcn_handle (name, fpath, octaveroot);
+        new_rep.reset (new octave::simple_fcn_handle (name, fpath, octaveroot));
       else if (subtype == "scopedfunction")
-        new_rep = new octave::scoped_fcn_handle (name, fpath, octaveroot);
+        new_rep.reset (new octave::scoped_fcn_handle (name, fpath, octaveroot));
       else if (subtype == "nested")
-        new_rep = new octave::nested_fcn_handle (name, fpath, octaveroot);
+        new_rep.reset (new octave::nested_fcn_handle (name, fpath, octaveroot));
       else if (subtype == "classsimple")
-        new_rep = new octave::class_simple_fcn_handle (name, fpath, octaveroot);
+        new_rep.reset (new octave::class_simple_fcn_handle (name, fpath, octaveroot));
     }
 
   bool status = false;
 
-  if (new_rep)
+  if (new_rep && new_rep->load_hdf5 (group_hid, space_hid, type_hid))
     {
-      if (new_rep->load_hdf5 (group_hid, space_hid, type_hid))
-        {
-          delete m_rep;
-          m_rep = new_rep;
-          status = true;
-        }
-      else
-        delete new_rep;
+      m_rep = new_rep;
+      status = true;
     }
 
   // FIXME: manage these with an unwind_action object?
--- a/libinterp/octave-value/ov-fcn-handle.h	Mon Dec 14 14:31:27 2020 -0800
+++ b/libinterp/octave-value/ov-fcn-handle.h	Mon Dec 14 21:00:01 2020 -0500
@@ -30,6 +30,7 @@
 
 #include <iosfwd>
 #include <list>
+#include <memory>
 #include <string>
 
 #include "oct-map.h"
@@ -325,11 +326,11 @@
 
 private:
 
-  octave::base_fcn_handle *m_rep;
+  std::shared_ptr<octave::base_fcn_handle> m_rep;
 
   octave_fcn_handle (octave::base_fcn_handle *rep);
 
-  octave::base_fcn_handle * get_rep (void) const { return m_rep; }
+  octave::base_fcn_handle * get_rep (void) const { return m_rep.get (); }
 
   DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA
 };