Mercurial > octave
diff libinterp/corefcn/variables.cc @ 23704:c495549e9a94
refactor local protection for internal variables
* ov-usr-fcn.h, ov-usr-fcn.cc
(octave_user_function::unwind_protect_frame): New function.
(octave_user_function::local_protect): Delete.
(octave_user_function::call): Set curr_unwind_protect_frame
immediately after pushing the current function on the call stack.
* variables.h, variables.cc (curr_fcn_unwind_protect_frame):
New static function.
(try_local_protect): Now static. Implement in terms of
curr_fcn_unwind_protect_frame and unwind_protect::protect_var.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 26 Jun 2017 19:35:17 -0400 |
parents | 6eb5f6199a5a |
children | 980f39c3ab90 |
line wrap: on
line diff
--- a/libinterp/corefcn/variables.cc Mon Jun 26 18:38:40 2017 -0400 +++ b/libinterp/corefcn/variables.cc Mon Jun 26 19:35:17 2017 -0400 @@ -691,18 +691,32 @@ return retval; } -template <typename T> -bool try_local_protect (T& var) +static octave::unwind_protect * +curr_fcn_unwind_protect_frame (void) { - octave::call_stack& cs = octave::__get_call_stack__ ("try_local_protect"); + octave::call_stack& cs + = octave::__get_call_stack__ ("curr_fcn_unwind_protect_frame"); octave_user_code *curr_usr_code = cs.caller_user_code (); - octave_user_function *curr_usr_fcn = nullptr; - if (curr_usr_code && curr_usr_code->is_user_function ()) - curr_usr_fcn = dynamic_cast<octave_user_function *> (curr_usr_code); - - if (curr_usr_fcn && curr_usr_fcn->local_protect (var)) - return true; + + octave_user_function *curr_usr_fcn + = (curr_usr_code && curr_usr_code->is_user_function () + ? dynamic_cast<octave_user_function *> (curr_usr_code) : nullptr); + + return curr_usr_fcn ? curr_usr_fcn->unwind_protect_frame () : nullptr; +} + +template <typename T> +static bool +try_local_protect (T& var) +{ + octave::unwind_protect *frame = curr_fcn_unwind_protect_frame (); + + if (frame) + { + frame->protect_var (var); + return true; + } else return false; }