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

Submitted by:  -X- <jsh>
Submitted on:  Fri 27 Mar 2015 07:50:45 AM UTC  
 
Category:  Interpreter Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Matlab Compatibility
Status:  Confirmed Assigned to:  None
Originator Name:  Open/Closed:  Open
Release:  4.0.0 Operating System:  Any

Add a New Comment (Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

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>
Project Administrator
Mon 30 Mar 2015 05:46:31 AM UTC, comment #1:

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

Rik <rik5>
Project 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)
  •  

    Do you think this task is very important?
    If so, you can add your encouragement to it.
    This task has 0 encouragements so far.

    Only project members can vote.

     

     

     

    Follow 5 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    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.4