Mercurial > octave
changeset 28726:0a4dcea2987a stable
stash (shallow) copy of indexed object instead of pointer
* pt-eval.h, pt-eval.cc (tree_evaluator::m_indexed_object): Now
"octave_value" instead of "const octave_value *". Change all uses.
(tree_evaluator::indexed_object): Return octave_value instead of
"const octave_value *". Change all uses.
(tree_evaluator::convert_to_const_vector,
tree_evaluator::make_value_list): Pass reference to indexed object
instead of pointer. Change all uses.
* pt-idx.cc (make_value_list): Pass reference to indexed object
instead of pointer. Change all uses.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sat, 12 Sep 2020 14:52:03 -0400 |
parents | 07c0df93ff9d |
children | 533993e3f115 aabebd95488b |
files | libinterp/parse-tree/pt-eval.cc libinterp/parse-tree/pt-eval.h libinterp/parse-tree/pt-idx.cc |
diffstat | 3 files changed, 26 insertions(+), 27 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/parse-tree/pt-eval.cc Fri Sep 11 20:15:40 2020 -0700 +++ b/libinterp/parse-tree/pt-eval.cc Sat Sep 12 14:52:03 2020 -0400 @@ -1665,7 +1665,7 @@ octave::tree_evaluator& tw = interp.get_evaluator (); - const octave_value *indexed_object = tw.indexed_object (); + octave_value indexed_object = tw.indexed_object (); int index_position = tw.index_position (); int num_indices = tw.num_indices (); @@ -1675,18 +1675,18 @@ // provide a better error message. So just fail with an invalid use // message. See bug #58830. - if (! indexed_object) + if (indexed_object.is_undefined ()) error ("invalid use of 'end': may only be used to index existing value"); - if (indexed_object->isobject ()) + if (indexed_object.isobject ()) { octave_value_list args; args(2) = num_indices; args(1) = index_position + 1; - args(0) = *indexed_object; - - std::string class_name = indexed_object->class_name (); + args(0) = indexed_object; + + std::string class_name = indexed_object.class_name (); octave::symbol_table& symtab = interp.get_symbol_table (); @@ -1696,7 +1696,7 @@ return octave::feval (meth.function_value (), args, 1); } - dim_vector dv = indexed_object->dims (); + dim_vector dv = indexed_object.dims (); int ndims = dv.ndims (); if (num_indices < ndims) @@ -1741,17 +1741,18 @@ { octave_value_list tree_evaluator::convert_to_const_vector (tree_argument_list *arg_list, - const octave_value *object) + const octave_value& object) { // END doesn't make sense as a direct argument for a function (i.e., // "fcn (end)" is invalid but "fcn (array (end))" is OK). Maybe we // need a different way of asking an octave_value object this // question? - bool stash_object = (object && ! (object->is_function () - || object->is_function_handle ())); - - unwind_protect_var<const octave_value *> upv1 (m_indexed_object); + bool stash_object + = (object.is_defined () + && ! (object.is_function () || object.is_function_handle ())); + + unwind_protect_var<octave_value> upv1 (m_indexed_object); unwind_protect_var<int> upv2 (m_index_position); unwind_protect_var<int> upv3 (m_num_indices); @@ -3863,7 +3864,7 @@ octave_value_list tree_evaluator::make_value_list (tree_argument_list *args, const string_vector& arg_nm, - const octave_value *object, bool rvalue) + const octave_value& object, bool rvalue) { octave_value_list retval; @@ -3872,8 +3873,7 @@ unwind_protect_var<const std::list<octave_lvalue> *> upv (m_lvalue_list, nullptr); - if (rvalue && object && args->has_magic_end () - && object->is_undefined ()) + if (rvalue && args->has_magic_end () && object.is_undefined ()) err_invalid_inquiry_subscript (); retval = convert_to_const_vector (args, object);
--- a/libinterp/parse-tree/pt-eval.h Fri Sep 11 20:15:40 2020 -0700 +++ b/libinterp/parse-tree/pt-eval.h Sat Sep 12 14:52:03 2020 -0400 @@ -138,7 +138,7 @@ m_echo_state (false), m_echo_file_name (), m_echo_file_pos (1), m_echo_files (), m_in_loop_command (false), m_breaking (0), m_continuing (0), m_returning (0), - m_indexed_object (nullptr), m_index_position (0), + m_indexed_object (), m_index_position (0), m_num_indices (0) { } @@ -357,7 +357,7 @@ octave_value_list convert_to_const_vector (tree_argument_list *arg_list, - const octave_value *object = nullptr); + const octave_value& object = octave_value ()); octave_value_list convert_return_list_to_const_vector @@ -627,7 +627,7 @@ return val; } - const octave_value * indexed_object (void) const + octave_value indexed_object (void) const { return m_indexed_object; } @@ -706,7 +706,7 @@ octave_value_list make_value_list (tree_argument_list *args, const string_vector& arg_nm, - const octave_value *object, bool rvalue = true); + const octave_value& object, bool rvalue = true); std::list<octave_lvalue> make_lvalue_list (tree_argument_list *); @@ -832,7 +832,7 @@ int m_returning; // Used by END function. - const octave_value *m_indexed_object; + octave_value m_indexed_object; int m_index_position; int m_num_indices; };
--- a/libinterp/parse-tree/pt-idx.cc Fri Sep 11 20:15:40 2020 -0700 +++ b/libinterp/parse-tree/pt-idx.cc Sat Sep 12 14:52:03 2020 -0400 @@ -150,7 +150,7 @@ static inline octave_value_list make_value_list (tree_evaluator& tw, tree_argument_list *m_args, - const string_vector& m_arg_nm, const octave_value *object, + const string_vector& m_arg_nm, const octave_value& object, bool rvalue = true) { // FIXME: This function duplicates tree_evaluator::make_value_list. @@ -167,8 +167,7 @@ }, tw.lvalue_list ()); tw.set_lvalue_list (nullptr); - if (rvalue && object && m_args->has_magic_end () - && object->is_undefined ()) + if (rvalue && m_args->has_magic_end () && object.is_undefined ()) err_invalid_inquiry_subscript (); retval = tw.convert_to_const_vector (m_args, object); @@ -250,7 +249,7 @@ case '(': { octave_value_list tidx - = make_value_list (tw, *p_args, *p_arg_nm, &tmp, false); + = make_value_list (tw, *p_args, *p_arg_nm, tmp, false); idx.push_back (tidx); @@ -268,7 +267,7 @@ case '{': { octave_value_list tidx - = make_value_list (tw, *p_args, *p_arg_nm, &tmp, false); + = make_value_list (tw, *p_args, *p_arg_nm, tmp, false); if (tmp.is_undefined ()) { @@ -648,12 +647,12 @@ { case '(': idx_list.push_back (make_value_list (tw, *p_args, *p_arg_nm, - &partial_expr_val)); + partial_expr_val)); break; case '{': idx_list.push_back (make_value_list (tw, *p_args, *p_arg_nm, - &partial_expr_val)); + partial_expr_val)); break; case '.':