changeset 26926:71724787d972

don't call inherited delete methods (bug #53956) * cdef-method.h, cdef-method.cc (cdef_method::is_defined_in_class, cdef_method::cdef_method_rep::is_defined_in_class): New functions. * cdef-class.cc (cdef_class::cdef_clsas_rep::delete_object): Skip calls to inherited delete methods. * test/bug-53956/bug-53956.tst, test/bug-53956/bug53956_class_2.m, test/bug-53956/bug53956_class_3.m, test/bug-53956/bug53956_class_4.m, test/bug-53956/module.mk: New files. * test/module.mk: Update.
author John W. Eaton <jwe@octave.org>
date Fri, 15 Mar 2019 21:09:19 +0000
parents 7fdbb03d5f76
children df9fe0026f73
files libinterp/octave-value/cdef-class.cc libinterp/octave-value/cdef-method.cc libinterp/octave-value/cdef-method.h test/bug-53956/bug-53956.tst test/bug-53956/bug53956_class_2.m test/bug-53956/bug53956_class_3.m test/bug-53956/bug53956_class_4.m test/bug-53956/module.mk test/module.mk
diffstat 9 files changed, 68 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/octave-value/cdef-class.cc	Fri Mar 15 18:45:20 2019 +0000
+++ b/libinterp/octave-value/cdef-class.cc	Fri Mar 15 21:09:19 2019 +0000
@@ -529,7 +529,10 @@
   {
     cdef_method dtor = find_method ("delete");
 
-    if (dtor.ok ())
+    // FIXME: would it be better to tell find_method above to not find
+    // overloaded functions?
+
+    if (dtor.ok () && dtor.is_defined_in_class (get_name ()))
       dtor.execute (obj, octave_value_list (), 0, true, "destructor");
 
     // FIXME: should we destroy corresponding properties here?
--- a/libinterp/octave-value/cdef-method.cc	Fri Mar 15 18:45:20 2019 +0000
+++ b/libinterp/octave-value/cdef-method.cc	Fri Mar 15 21:09:19 2019 +0000
@@ -181,6 +181,14 @@
   }
 
   bool
+  cdef_method::cdef_method_rep::is_defined_in_class (const std::string &cname) const
+  {
+    return (function.is_function ()
+            ? function.function_value ()->dispatch_class () == cname
+            : false);
+  }
+
+  bool
   cdef_method::cdef_method_rep::check_access (void) const
   {
     cdef_class cls (to_cdef (get ("DefiningClass")));
--- a/libinterp/octave-value/cdef-method.h	Fri Mar 15 18:45:20 2019 +0000
+++ b/libinterp/octave-value/cdef-method.h	Fri Mar 15 21:09:19 2019 +0000
@@ -90,6 +90,8 @@
 
       bool is_constructor (void) const;
 
+      bool is_defined_in_class (const std::string& cname) const;
+
       octave_value_list
       meta_subsref (const std::string& type,
                     const std::list<octave_value_list>& idx, int nargout);
@@ -190,6 +192,11 @@
       return get_rep ()->is_constructor ();
     }
 
+    bool is_defined_in_class (const std::string& cname) const
+    {
+      return get_rep ()->is_defined_in_class (cname);
+    }
+
     bool is_external (void) const { return get_rep ()->is_external (); }
 
     void mark_as_external (const std::string& dtype)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/bug-53956/bug-53956.tst	Fri Mar 15 21:09:19 2019 +0000
@@ -0,0 +1,15 @@
+%!test <53956>
+%! global dtor2_called dtor4_called
+%!
+%! dtor2_called = dtor4_called = 0;
+%! x = bug53956_class_3 ();
+%! clear x
+%! assert (dtor2_called, 1);
+%!
+%! dtor2_called = dtor4_called = 0;
+%! x = bug53956_class_4 ();
+%! clear x
+%! assert (dtor2_called, 1);
+%! assert (dtor4_called, 1);
+%!
+%! clear -global dtor2_called dtor4_called;  # cleanup after test
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/bug-53956/bug53956_class_2.m	Fri Mar 15 21:09:19 2019 +0000
@@ -0,0 +1,10 @@
+classdef bug53956_class_2 < handle
+  properties
+  end
+  methods
+    function delete (self)
+      global dtor2_called
+      dtor2_called++;
+    end
+  end
+end
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/bug-53956/bug53956_class_3.m	Fri Mar 15 21:09:19 2019 +0000
@@ -0,0 +1,6 @@
+classdef bug53956_class_3 < bug53956_class_2
+  properties
+  end
+  methods
+  end
+end
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/bug-53956/bug53956_class_4.m	Fri Mar 15 21:09:19 2019 +0000
@@ -0,0 +1,10 @@
+classdef bug53956_class_4 < bug53956_class_3
+  properties
+  end
+  methods
+    function delete (self)
+      global dtor4_called
+      dtor4_called++;
+    end
+  end
+end
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/bug-53956/module.mk	Fri Mar 15 21:09:19 2019 +0000
@@ -0,0 +1,7 @@
+bug_53956_TEST_FILES = \
+  %reldir%/bug-53956.tst \
+  %reldir%/bug53956_class_2.m \
+  %reldir%/bug53956_class_3.m \
+  %reldir%/bug53956_class_4.m
+
+TEST_FILES += $(bug_53956_TEST_FILES)
--- a/test/module.mk	Fri Mar 15 18:45:20 2019 +0000
+++ b/test/module.mk	Fri Mar 15 21:09:19 2019 +0000
@@ -77,6 +77,7 @@
 include %reldir%/bug-52722/module.mk
 include %reldir%/bug-53027/module.mk
 include %reldir%/bug-53468/module.mk
+include %reldir%/bug-53956/module.mk
 include %reldir%/bug-54995/module.mk
 include %reldir%/bug-55758/module.mk
 include %reldir%/class-concat/module.mk