[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Bug in octave structures
From: |
John W. Eaton |
Subject: |
Bug in octave structures |
Date: |
Wed, 18 Sep 2002 02:22:01 -0500 |
On 17-Sep-2002, Roderick Koehle <address@hidden> wrote:
| In the current octave CVS release, I discovered following problems:
|
| octave:1> z = zeros(1,5);
| octave:2> s.a = z; s.b = z; s.a(1) = 1; s
| s =
| {
| a =
|
| 1 0 0 0 0
|
| b =
|
| 1 0 0 0 0
|
| }
| It seems that by assigning the vector z to s.a and s.b, these variables stay
| linked forever. Whatever you write into the vector s.a will also modify s.b.
|
| Doing the same with scalar values however works properly. So the example:
|
| octave:1> z = 0; s.a = z; s.b = z; s.a(1) = 1; s
| s =
| {
| a = 1
| b = 0
| }
|
| So for the scalar case, above example produces the correct result, writing
| into a does not cause b to be modified.
|
| The following example produces also curious results.
| A function "empty" returns a structure with an empty list element.
| When you write something into this list and then try to clear it again with
| the function "empty", you will get following:
|
| octave:1> function a=empty(), a.list = {}; endfunction
| octave:2> a=empty()
| a =
| {
| list = {}
| }
|
| octave:3> a.list{1} = 'hallo'
| a.list =
| {
| list =
| {
| [1,1] = hallo
| }
| }
|
| octave:4> a = empty()
| a =
| {
| list =
| {
| [1,1] = hallo
| }
| }
|
| Even though in the function "empty" the empty list is assigned to a.list. It
| won't change its content.
Please try the following patch. It's checked in to CVS now too, so
you could also update to get these changes.
Thanks,
jwe
2002-09-18 John W. Eaton <address@hidden>
* ov-struct.cc (octave_struct::subsasgn): Ensure that indexed
object is not shared before calling subsasgn.
Index: ov-struct.cc
===================================================================
RCS file: /usr/local/cvsroot/octave/src/ov-struct.cc,v
retrieving revision 1.22
diff -u -r1.22 ov-struct.cc
--- ov-struct.cc 3 Jun 2002 18:15:47 -0000 1.22
+++ ov-struct.cc 18 Sep 2002 07:19:16 -0000
@@ -239,6 +239,8 @@
next_idx.remove_front ();
next_idx.remove_front ();
+ u.make_unique ();
+
t_rhs = u.subsasgn (type.substr (2), next_idx, rhs);
}
}
@@ -274,6 +276,8 @@
SLList<octave_value_list> next_idx (idx);
next_idx.remove_front ();
+
+ u.make_unique ();
t_rhs = u.subsasgn (type.substr (1), next_idx, rhs);
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Bug in octave structures,
John W. Eaton <=