comparison src/ov-class.cc @ 12171:d08901c05c1b

fix bug in class assignment to undefined object with index
author John W. Eaton <jwe@octave.org>
date Wed, 26 Jan 2011 20:39:15 -0500
parents b83162e8f402
children a71c1aa9823e
comparison
equal deleted inserted replaced
12170:037f8b7608f3 12171:d08901c05c1b
502 octave_value 502 octave_value
503 octave_class::subsasgn (const std::string& type, 503 octave_class::subsasgn (const std::string& type,
504 const std::list<octave_value_list>& idx, 504 const std::list<octave_value_list>& idx,
505 const octave_value& rhs) 505 const octave_value& rhs)
506 { 506 {
507 count++;
508 return subsasgn_common (octave_value (this), type, idx, rhs);
509 }
510
511 octave_value
512 octave_class::undef_subsasgn (const std::string& type,
513 const std::list<octave_value_list>& idx,
514 const octave_value& rhs)
515 {
516 // For compatibility with Matlab, pass [] as the first argument to the
517 // the subsasgn function when the LHS of an indexed assignment is
518 // undefined.
519
520 return subsasgn_common (Matrix (), type, idx, rhs);
521 }
522
523 octave_value
524 octave_class::subsasgn_common (const octave_value& obj,
525 const std::string& type,
526 const std::list<octave_value_list>& idx,
527 const octave_value& rhs)
528 {
507 octave_value retval; 529 octave_value retval;
508 530
509 if (! (in_class_method () || called_from_builtin ())) 531 if (! (in_class_method () || called_from_builtin ()))
510 { 532 {
511 octave_value meth = symbol_table::find_method ("subsasgn", class_name ()); 533 octave_value meth = symbol_table::find_method ("subsasgn", class_name ());
527 args(1) = make_idx_args (type, idx, "subsasgn"); 549 args(1) = make_idx_args (type, idx, "subsasgn");
528 550
529 if (error_state) 551 if (error_state)
530 return octave_value_list (); 552 return octave_value_list ();
531 553
532 count++; 554 args(0) = obj;
533 args(0) = octave_value (this);
534 555
535 // Now comes the magic. Count copies with me: 556 // Now comes the magic. Count copies with me:
536 // 1. myself (obsolete) 557 // 1. myself (obsolete)
537 // 2. the copy inside args (obsolete) 558 // 2. the copy inside args (obsolete)
538 // 3. the copy in method's symbol table (working) 559 // 3. the copy in method's symbol table (working)