Mercurial > octave
changeset 29422:8b9e3f0bd06f stable
fix context link when creating handle to nested function
* pt-eval.cc (tree_evaluator::make_fcn_handle): When creating a handle
to a nested from from inside that function, set context link to parent
stack frame.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sun, 07 Mar 2021 23:28:25 -0500 |
parents | 24e62692e8ac |
children | e4904768ca48 c003947a98a7 |
files | libinterp/parse-tree/pt-eval.cc |
diffstat | 1 files changed, 17 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/parse-tree/pt-eval.cc Thu Mar 04 16:19:48 2021 -0500 +++ b/libinterp/parse-tree/pt-eval.cc Sun Mar 07 23:28:25 2021 -0500 @@ -1127,6 +1127,12 @@ octave_value ov_fcn = symtab.find_scoped_function (fcn_name, curr_scope); + // If name is operator, we are in Fstr2func, so skip the stack + // frame for that function. + + bool skip_first = name_is_operator; + octave_function *curr_fcn = current_function (skip_first); + if (ov_fcn.is_defined ()) { octave_function *fcn = ov_fcn.function_value (); @@ -1141,6 +1147,17 @@ std::shared_ptr<stack_frame> frame = m_call_stack.get_current_stack_frame (); + // If we are creating a handle to the current + // function, then use the calling stack frame as the + // context. + + std::string curr_fcn_name; + if (curr_fcn) + curr_fcn_name = curr_fcn->name (); + + if (fcn_name == curr_fcn_name) + frame = frame->access_link (); + octave_fcn_handle *fh = new octave_fcn_handle (ov_fcn, fcn_name, frame); @@ -1163,12 +1180,6 @@ } } - // If name is operator, we are in Fstr2func, so skip the stack - // frame for that function. - - bool skip_first = name_is_operator; - octave_function *curr_fcn = current_function (skip_first); - if (curr_fcn && (curr_fcn->is_class_method () || curr_fcn->is_class_constructor ())) {