# HG changeset patch # User John W. Eaton # Date 1296127010 18000 # Node ID 1860ce6c30d0a701a8d3259b7af8b58855cadf2e # Parent 5f1bb7aa3a3a1f46a635b20b533af930d5c41a2e fix another bug in class assignment to undefined object with index diff -r 5f1bb7aa3a3a -r 1860ce6c30d0 src/ChangeLog --- a/src/ChangeLog Thu Jan 27 04:27:42 2011 -0500 +++ b/src/ChangeLog Thu Jan 27 06:16:50 2011 -0500 @@ -1,3 +1,10 @@ +2011-01-27 John W. Eaton + + * ov-struct.cc (octave_struct::subsasgn, + octave_scalar_struct::subsasgn): Call undef_subsasgn on object + returned by octave_value::empty_conv if LHS is initially undefined. + Bug #32242. + 2011-01-27 John W. Eaton * input.cc (input_event_hook): Fix incorrect use of iterator. @@ -23,7 +30,7 @@ * ov-class.h, ov-class.cc (octave_class::undef_subsasgn, octave_class::subsasgn_common): New functions. * ov-base.h, ov-base.cc (octave_base_value::subsasgn): If - undefined, undef_subsasgn on object returned by + undefined, call undef_subsasgn on object returned by octave_value::empty_conv. (octave_base_value::undef_subsasgn): New virtual function. (octave_base_value::subsasgn): Only handle case of undefined diff -r 5f1bb7aa3a3a -r 1860ce6c30d0 src/ov-struct.cc --- a/src/ov-struct.cc Thu Jan 27 04:27:42 2011 -0500 +++ b/src/ov-struct.cc Thu Jan 27 06:16:50 2011 -0500 @@ -328,7 +328,9 @@ { octave_value& tmp = tmpc(0); - if (! tmp.is_defined () || tmp.is_zero_by_zero ()) + bool orig_undefined = tmp.is_undefined (); + + if (orig_undefined || tmp.is_zero_by_zero ()) { tmp = octave_value::empty_conv (next_type, rhs); tmp.make_unique (); // probably a no-op. @@ -338,7 +340,9 @@ tmp.make_unique (1); if (! error_state) - t_rhs = tmp.subsasgn (next_type, next_idx, rhs); + t_rhs = (orig_undefined + ? tmp.undef_subsasgn (next_type, next_idx, rhs) + : tmp.subsasgn (next_type, next_idx, rhs)); } else gripe_indexed_cs_list (); @@ -378,7 +382,9 @@ { octave_value& tmp = tmpc(0); - if (! tmp.is_defined () || tmp.is_zero_by_zero ()) + bool orig_undefined = tmp.is_undefined (); + + if (orig_undefined || tmp.is_zero_by_zero ()) { tmp = octave_value::empty_conv (next_type, rhs); tmp.make_unique (); // probably a no-op. @@ -388,7 +394,9 @@ tmp.make_unique (1); if (! error_state) - t_rhs = tmp.subsasgn (next_type, next_idx, rhs); + t_rhs = (orig_undefined + ? tmp.undef_subsasgn (next_type, next_idx, rhs) + : tmp.subsasgn (next_type, next_idx, rhs)); } else gripe_indexed_cs_list (); @@ -1244,7 +1252,9 @@ if (! error_state) { - if (! tmp.is_defined () || tmp.is_zero_by_zero ()) + bool orig_undefined = tmp.is_undefined (); + + if (orig_undefined || tmp.is_zero_by_zero ()) { tmp = octave_value::empty_conv (next_type, rhs); tmp.make_unique (); // probably a no-op. @@ -1254,7 +1264,9 @@ tmp.make_unique (1); if (! error_state) - t_rhs = tmp.subsasgn (next_type, next_idx, rhs); + t_rhs = (orig_undefined + ? tmp.undef_subsasgn (next_type, next_idx, rhs) + : tmp.subsasgn (next_type, next_idx, rhs)); } }