bugGNU Octave - Bugs: bug #33064, Object does not seem to be cloned

 
 

bug #33064: Object does not seem to be cloned

Submitter:  Dominik Schulz <realniki>
Submitted:  Wed 13 Apr 2011 04:07:34 PM UTC
   
 
Category:  Interpreter Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  Fixed Assigned to:  None
Originator Name:  Open/Closed:  * Closed
Release:  * 3.2.4 Operating System:  * GNU/Linux
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Wed 29 Feb 2012 05:30:32 PM UTC, comment #3: 

The behavior did change from Octave-3.2.4 (no cloning) to Octave-3.4.0 (cloning).

I suppose the issue is still resolved for you since this is the behavior you were looking for and Octave now does this by default.

Rik <rik5>
Group administrator
Wed 29 Feb 2012 09:04:36 AM UTC, comment #2: 

Maybe it is me who has a problem of understanding the issue, but using Octave 3.6.0 (Gentoo Linux) I get the expected results (r1 == 951 and r2 == 987). So, changing the member 'a' via setparam() does not change the respective member in the other object.

Dominik Schulz <realniki>
Tue 28 Feb 2012 01:14:37 AM UTC, comment #1: 

This is not a bug.   The '=' operator implements only a shallow copy.  If you want to implement a deep copy (or clone) you need to write the code for it into the class itself.  The Matlab documentation has multiple articles on this.  See http://www.mathworks.com/help/techdoc/matlab_prog/brtm8si.html as well as this one for a solution http://www.mathworks.com/matlabcentral/fileexchange/22965-clone-handle-object-using-matlab-oop

Rik <rik5>
Group administrator
Wed 13 Apr 2011 04:07:34 PM UTC, original submission:  

I encountered a strange behavior on my Kubuntu 10.10 workstation with GNU Octave 3.2.4 when using classes as described in the Octave documentation.

Let's say I have a class 'testclass1' in directory @testclass1 which provides a member 'a' like this:


function y = testclass1(a)
        y.a = a;
        y = class(y, "testclass1");
endfunction



function self = setparam(self, a)
        self.a = a;
endfunction



function a = getparam(self)
        a = self.a;
endfunction


Now I derive a mainly  empty class called 'testclass2' (directory @testclass2) from 'testclass1' like this:


function y = testclass2()
        y = struct;
        super = @testclass1(951);
        y = class(y, "testclass2", super);
endfunction


Now I am using 'testclass2' in a code like this


c_1 = testclass2();
c_2 = c_1;
c_2 = setparam(c_2, 987);
r1= getparam(c_1),
r2 = getparam(c_2),


The result is that r1 and r2 are both equal to 987, which I assume to be wrong when r2 should be a clone of r1. Only the value of c_2 should be modified. Actually it makes no difference whether one modifies c_1 or c_2. It always changes both objects. Thus, for me both objects seem to be the same.
  Strangely the problem does not occur when the base class testclass1 is empty and all members ('a', setparam(), getparam()) are implemented in the derived class testclass2.


Thank you

Dominik Schulz <realniki>

 

(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 rik5 (Posted a comment)
  • -email is unavailable- added by realniki (Submitted the item)
  • -email is unavailable- added by realniki
  •  

    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 4 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2012-02-29 rik5 StatusInvalid / Not an Octave Bug Fixed
    2012-02-28 rik5 StatusNone Invalid / Not an Octave Bug
        Open/ClosedOpen Closed
    2011-04-13 realniki Carbon-Copy- Added realniki

    Back to the top

    Powered by Savane 3.13-02a9.
    Corresponding source code