bugGNU Octave - Bugs: bug #44643, classdef handle object can go into...

 
 

bug #44643: classdef handle object can go into an recursive loop with isequal(obj1,obj2) if both are self-referential

Submitter:  -X- <jsh>
Submitted:  Fri 27 Mar 2015 07:50:45 AM UTC
   
 
Category:  Classdef Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  Confirmed Assigned to:  None
Originator Name:  Open/Closed:  * Open
Release:  * 4.0.0 Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Thu 25 Jan 2024 08:54:36 PM UTC, comment #4: 

This problem is still present on the current development branch.  I added a test for it in the following changeset:

http://hg.savannah.gnu.org/hgweb/octave/rev/ff21351709dc

John W. Eaton <jwe>
Group administrator
Wed 29 Jun 2016 02:52:21 AM UTC, comment #3: 

I don't think this is trivial.

The issue is that


a.parent = b;
b.child = a;


is assigning handles to the objects, rather than assigning values.  That gives rise to a closed loop:  a.parent.child = a.  Naively walking that structure as a tree gives the loop.

If we repeat that with


c = foo ();
d = foo ();
c.parent = d;
d.child = c;


then to compare isequal(a, c), we need _isequal_ to learn the actual structure (since we can't simply rely on checking that the "rep" is the same, which was my first thought).

It isn't even clear what _isequal_(a,c) should be.  Either "true" or "false" is self-consistent.

Perhaps we can still walk the tree keeping track of the rep values we have seen.  If one finds the n'th rep again and the other also finds the n'th rep at the same point, we report success without the recursive call.  If one finds the n'th rep again and the other doesn't, we return false.

That will consume a huge amount of memory when comparing large trees.  It would be helped slightly if a persistent variable is used, so we don't need the list of visited nodes in each stack frame.

I'm reassigning this from "crash" to "Matlab compatibility".  (There is still no way to distinguish a very dangerous silent "incorrect result" from something that simply reports an error.)

Lachlan Andrew <lachlan>
Tue 02 Jun 2015 04:43:59 PM UTC, comment #2: 

Retagging release from 4.0.0-rc2 to 4.0.0.

John W. Eaton <jwe>
Group administrator
Mon 30 Mar 2015 05:46:31 AM UTC, comment #1: 

Confirmed.  This looks like something rather trivial in _isequal_.m.

Rik <rik5>
Group administrator
Fri 27 Mar 2015 07:50:45 AM UTC, original submission:  

When using a handle class object with properties that define child/parent relations isequal comparison goes into a recursive loop when comparing an instance with itself. For example, define the class foo:


classdef foo < handle
  properties
    child
    parent
  end
end


And create two instances one child and one parent:


a = foo();
b = foo();
a.parent = b;
b.child  = a;

isequal(a,b)

isequal(a,a)


isequal(a,b) works fine and returns zero while isequal(a,a) or isequal(b,b) goes into a recursive loop (unlike Matlab which returns 1).

-X- <jsh>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by lachlan (Posted a comment)
  • -email is unavailable- added by jwe (Posted a comment)
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by jordigh (Updated the item)
  • -email is unavailable- added by jsh (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 7 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2024-01-25 jwe CategoryInterpreter Classdef
        Item GroupMatlab Compatibility Incorrect Result
    2016-06-29 lachlan Item GroupSegfault, Bus Error, etc. Matlab Compatibility
        Summaryclassdef handle object can go into an recursive loop with isequal(obj,obj) classdef handle object can go into an recursive loop with isequal(obj1,obj2) if both are self-referential
    2015-06-02 jwe Release4.0.0-rc2 4.0.0
    2015-03-30 rik5 StatusNone Confirmed
    2015-03-27 jordigh Item GroupMatlab Compatibility Segfault, Bus Error, etc.

    Back to the top

    Powered by Savane 3.13-4448.
    Corresponding source code