# HG changeset patch # User John W. Eaton # Date 1552684159 0 # Node ID 71724787d9727b4c504fda13ea5f024ae1d49e7c # Parent 7fdbb03d5f76bd0e583d34df587b6abe6fbd4901 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. diff -r 7fdbb03d5f76 -r 71724787d972 libinterp/octave-value/cdef-class.cc --- 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? diff -r 7fdbb03d5f76 -r 71724787d972 libinterp/octave-value/cdef-method.cc --- 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"))); diff -r 7fdbb03d5f76 -r 71724787d972 libinterp/octave-value/cdef-method.h --- 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& 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) diff -r 7fdbb03d5f76 -r 71724787d972 test/bug-53956/bug-53956.tst --- /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 diff -r 7fdbb03d5f76 -r 71724787d972 test/bug-53956/bug53956_class_2.m --- /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 diff -r 7fdbb03d5f76 -r 71724787d972 test/bug-53956/bug53956_class_3.m --- /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 diff -r 7fdbb03d5f76 -r 71724787d972 test/bug-53956/bug53956_class_4.m --- /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 diff -r 7fdbb03d5f76 -r 71724787d972 test/bug-53956/module.mk --- /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) diff -r 7fdbb03d5f76 -r 71724787d972 test/module.mk --- 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