Mercurial > octave
changeset 23110:af48d8be62b3
move recover_from_exception and atexit functions inside octave namespace
* interpreter.h, interpreter.cc (recover_from_exception,
octave_add_atexit_function, octave_remove_atexit_function,
octave_atexit_functions): Move inside octave::interpreter class and
rename without octave_ prefix. Change all uses.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 27 Jan 2017 18:15:48 -0500 |
parents | 3e7ca46d3eab |
children | 252975fdc444 |
files | libgui/graphics/__init_qt__.cc libinterp/corefcn/cellfun.cc libinterp/corefcn/graphics.cc libinterp/corefcn/input.cc libinterp/corefcn/interpreter.cc libinterp/corefcn/interpreter.h libinterp/corefcn/load-path.cc libinterp/corefcn/ls-mat-ascii.cc libinterp/corefcn/mex.cc libinterp/corefcn/oct-stream.cc libinterp/corefcn/utils.cc libinterp/corefcn/variables.cc libinterp/octave-value/ov-class.cc libinterp/octave-value/ov-fcn-handle.cc libinterp/octave-value/ov-oncleanup.cc libinterp/parse-tree/oct-parse.in.yy libinterp/parse-tree/pt-eval.cc |
diffstat | 17 files changed, 106 insertions(+), 84 deletions(-) [+] |
line wrap: on
line diff
--- a/libgui/graphics/__init_qt__.cc Fri Jan 27 17:54:12 2017 -0500 +++ b/libgui/graphics/__init_qt__.cc Fri Jan 27 18:15:48 2017 -0500 @@ -59,7 +59,7 @@ graphics_toolkit tk (new Backend ()); gtk_manager::load_toolkit (tk); - octave_add_atexit_function ("__shutdown_qt__"); + octave::interpreter::add_atexit_function ("__shutdown_qt__"); // Change some default settings to use Qt default colors QPalette p;
--- a/libinterp/corefcn/cellfun.cc Fri Jan 27 17:54:12 2017 -0500 +++ b/libinterp/corefcn/cellfun.cc Fri Jan 27 18:15:48 2017 -0500 @@ -82,7 +82,7 @@ { if (error_handler.is_defined ()) { - recover_from_exception (); + octave::interpreter::recover_from_exception (); execution_error = true; }
--- a/libinterp/corefcn/graphics.cc Fri Jan 27 17:54:12 2017 -0500 +++ b/libinterp/corefcn/graphics.cc Fri Jan 27 18:15:48 2017 -0500 @@ -3270,7 +3270,7 @@ } catch (const octave::execution_exception&) { - recover_from_exception (); + octave::interpreter::recover_from_exception (); } } } @@ -9748,7 +9748,7 @@ << std::endl; octave::feval ("lasterr", ovl ("execution error in graphics callback function")); - recover_from_exception (); + octave::interpreter::recover_from_exception (); } } else if (cb.is_cell () && cb.length () > 0 @@ -9781,7 +9781,7 @@ << std::endl; octave::feval ("lasterr", ovl ("execution error in graphics callback function")); - recover_from_exception (); + octave::interpreter::recover_from_exception (); } // Redraw after interacting with a user-interface (ui*) object.
--- a/libinterp/corefcn/input.cc Fri Jan 27 17:54:12 2017 -0500 +++ b/libinterp/corefcn/input.cc Fri Jan 27 18:15:48 2017 -0500 @@ -217,7 +217,7 @@ std::cerr << stack_trace; if (octave::application::interactive ()) - recover_from_exception (); + octave::interpreter::recover_from_exception (); } octave::flush_stdout (); @@ -724,7 +724,7 @@ std::cerr << stack_trace; // Ignore errors when in debugging mode; - recover_from_exception (); + octave::interpreter::recover_from_exception (); } } }
--- a/libinterp/corefcn/interpreter.cc Fri Jan 27 17:54:12 2017 -0500 +++ b/libinterp/corefcn/interpreter.cc Fri Jan 27 18:15:48 2017 -0500 @@ -194,22 +194,6 @@ disable_warning ("Octave:possible-matlab-short-circuit-operator"); } -void -recover_from_exception (void) -{ - octave::can_interrupt = true; - octave_interrupt_immediately = 0; - octave_interrupt_state = 0; - octave_signal_caught = 0; - octave_exception_state = octave_no_exception; - octave_restore_signal_mask (); - octave::catch_interrupts (); -} - -// Fix up things before exiting. - -static std::list<std::string> octave_atexit_functions; - DEFUN (quit, args, , doc: /* -*- texinfo -*- @deftypefn {} {} exit @@ -254,31 +238,6 @@ DEFALIAS (exit, quit); -void -octave_add_atexit_function (const std::string& fname) -{ - octave_atexit_functions.push_front (fname); -} - -bool -octave_remove_atexit_function (const std::string& fname) -{ - bool found = false; - - for (auto it = octave_atexit_functions.begin (); - it != octave_atexit_functions.end (); it++) - { - if (*it == fname) - { - octave_atexit_functions.erase (it); - found = true; - break; - } - } - - return found; -} - DEFUN (atexit, args, nargout, doc: /* -*- texinfo -*- @deftypefn {} {} atexit (@var{fcn}) @@ -333,10 +292,10 @@ octave_value_list retval; if (add_mode) - octave_add_atexit_function (arg); + octave::interpreter::add_atexit_function (arg); else { - bool found = octave_remove_atexit_function (arg); + bool found = octave::interpreter::remove_atexit_function (arg); if (nargout > 0) retval = ovl (found); @@ -362,13 +321,13 @@ } catch (const octave::interrupt_exception&) { - recover_from_exception (); + octave::interpreter::recover_from_exception (); return 1; } catch (const octave::execution_exception&) { - recover_from_exception (); + octave::interpreter::recover_from_exception (); return 1; } @@ -387,11 +346,11 @@ } catch (const octave::interrupt_exception&) { - recover_from_exception (); + octave::interpreter::recover_from_exception (); } catch (const octave::execution_exception&) { - recover_from_exception (); + octave::interpreter::recover_from_exception (); } } @@ -1013,11 +972,11 @@ OCTAVE_SAFE_CALL (remove_input_event_hook_functions, ()); - while (! octave_atexit_functions.empty ()) + while (! atexit_functions.empty ()) { - std::string fcn = octave_atexit_functions.front (); + std::string fcn = atexit_functions.front (); - octave_atexit_functions.pop_front (); + atexit_functions.pop_front (); OCTAVE_SAFE_CALL (reset_error_handler, ()); @@ -1083,4 +1042,42 @@ OCTAVE_SAFE_CALL (octave::chunk_buffer::clear, ()); } } + + void recover_from_exception (void) + { + octave::can_interrupt = true; + octave_interrupt_immediately = 0; + octave_interrupt_state = 0; + octave_signal_caught = 0; + octave_exception_state = octave_no_exception; + octave_restore_signal_mask (); + octave::catch_interrupts (); + } + + // Functions to call when the interpreter exits. + + std::list<std::string> atexit_functions; + + void interpreter::add_atexit_function (const std::string& fname) + { + atexit_functions.push_front (fname); + } + + bool interpreter::remove_atexit_function (const std::string& fname) + { + bool found = false; + + for (auto it = atexit_functions.begin (); + it != atexit_functions.end (); it++) + { + if (*it == fname) + { + atexit_functions.erase (it); + found = true; + break; + } + } + + return found; + } }
--- a/libinterp/corefcn/interpreter.h Fri Jan 27 17:54:12 2017 -0500 +++ b/libinterp/corefcn/interpreter.h Fri Jan 27 18:15:48 2017 -0500 @@ -34,14 +34,6 @@ extern OCTINTERP_API bool quit_allowed; -extern OCTINTERP_API void recover_from_exception (void); - -extern OCTINTERP_API void -octave_add_atexit_function (const std::string& fname); - -extern OCTINTERP_API bool -octave_remove_atexit_function (const std::string& fname); - // TRUE means we are ready to interpret commands, but not everything // is ready for interactive use. extern OCTINTERP_API bool octave_interpreter_ready; @@ -79,8 +71,16 @@ bool interactive (void) const { return m_interactive; } void interactive (bool arg) { m_interactive = arg; } + static void recover_from_exception (void); + + static void add_atexit_function (const std::string& fname); + + static bool remove_atexit_function (const std::string& fname); + private: + static std::list<std::string> atexit_functions; + int execute_internal (void); void display_startup_message (void) const; @@ -106,4 +106,29 @@ }; } +#if defined (OCTAVE_USE_DEPRECATED_FUNCTIONS) + +OCTAVE_DEPRECATED ("use 'octave::interpreter::recover_from_exception' instead") +static inline void +recover_from_exception (void) +{ + octave::interpreter::recover_from_exception (); +} + +OCTAVE_DEPRECATED ("use 'octave::interpreter::add_atexit_function' instead") +static inline void +add_atexit_function (const std::string& fname) +{ + octave::interpreter::add_atexit_function (fname); +} + +OCTAVE_DEPRECATED ("use 'octave::interpreter::remove_atexit_function' instead") +static inline bool +remove_atexit_function (const std::string& fname) +{ + return octave::interpreter::remove_atexit_function (fname); +} + #endif + +#endif
--- a/libinterp/corefcn/load-path.cc Fri Jan 27 17:54:12 2017 -0500 +++ b/libinterp/corefcn/load-path.cc Fri Jan 27 18:15:48 2017 -0500 @@ -108,7 +108,7 @@ { // Skip updating if we don't know where we are, // but don't treat it as an error. - recover_from_exception (); + octave::interpreter::recover_from_exception (); } } // Absolute path, check timestamp to see whether it requires re-caching @@ -172,7 +172,7 @@ // Skip updating if we don't know where we are but don't treat // it as an error. - recover_from_exception (); + octave::interpreter::recover_from_exception (); } } else
--- a/libinterp/corefcn/ls-mat-ascii.cc Fri Jan 27 17:54:12 2017 -0500 +++ b/libinterp/corefcn/ls-mat-ascii.cc Fri Jan 27 18:15:48 2017 -0500 @@ -360,7 +360,7 @@ } catch (const octave::execution_exception& e) { - recover_from_exception (); + octave::interpreter::recover_from_exception (); success = false; }
--- a/libinterp/corefcn/mex.cc Fri Jan 27 17:54:12 2017 -0500 +++ b/libinterp/corefcn/mex.cc Fri Jan 27 18:15:48 2017 -0500 @@ -3186,7 +3186,7 @@ { if (mex_context->trap_feval_error) { - recover_from_exception (); + octave::interpreter::recover_from_exception (); execution_error = true; } @@ -3266,7 +3266,7 @@ } catch (const octave::execution_exception&) { - recover_from_exception (); + octave::interpreter::recover_from_exception (); execution_error = true; } @@ -3293,7 +3293,7 @@ } catch (const octave::execution_exception&) { - recover_from_exception (); + octave::interpreter::recover_from_exception (); execution_error = true; }
--- a/libinterp/corefcn/oct-stream.cc Fri Jan 27 17:54:12 2017 -0500 +++ b/libinterp/corefcn/oct-stream.cc Fri Jan 27 18:15:48 2017 -0500 @@ -89,7 +89,7 @@ } catch (const octave::execution_exception&) { - recover_from_exception (); + octave::interpreter::recover_from_exception (); conv_err = 1; }
--- a/libinterp/corefcn/utils.cc Fri Jan 27 17:54:12 2017 -0500 +++ b/libinterp/corefcn/utils.cc Fri Jan 27 18:15:48 2017 -0500 @@ -1371,7 +1371,7 @@ } catch (const octave::execution_exception&) { - recover_from_exception (); + octave::interpreter::recover_from_exception (); retval = false; }
--- a/libinterp/corefcn/variables.cc Fri Jan 27 17:54:12 2017 -0500 +++ b/libinterp/corefcn/variables.cc Fri Jan 27 18:15:48 2017 -0500 @@ -287,7 +287,7 @@ } catch (const octave::execution_exception&) { - recover_from_exception (); + octave::interpreter::recover_from_exception (); } } }
--- a/libinterp/octave-value/ov-class.cc Fri Jan 27 17:54:12 2017 -0500 +++ b/libinterp/octave-value/ov-class.cc Fri Jan 27 18:15:48 2017 -0500 @@ -1065,7 +1065,7 @@ } catch (const octave::execution_exception&) { - recover_from_exception (); + octave::interpreter::recover_from_exception (); execution_error = true; }
--- a/libinterp/octave-value/ov-fcn-handle.cc Fri Jan 27 17:54:12 2017 -0500 +++ b/libinterp/octave-value/ov-fcn-handle.cc Fri Jan 27 18:15:48 2017 -0500 @@ -2043,7 +2043,7 @@ } catch (const octave::execution_exception&) { - recover_from_exception (); + octave::interpreter::recover_from_exception (); bad = true; }
--- a/libinterp/octave-value/ov-oncleanup.cc Fri Jan 27 17:54:12 2017 -0500 +++ b/libinterp/octave-value/ov-oncleanup.cc Fri Jan 27 18:15:48 2017 -0500 @@ -85,7 +85,7 @@ } catch (const octave::interrupt_exception&) { - recover_from_exception (); + octave::interpreter::recover_from_exception (); warning ("onCleanup: interrupt occurred in cleanup action"); }
--- a/libinterp/parse-tree/oct-parse.in.yy Fri Jan 27 17:54:12 2017 -0500 +++ b/libinterp/parse-tree/oct-parse.in.yy Fri Jan 27 18:15:48 2017 -0500 @@ -2343,7 +2343,7 @@ } catch (const octave::execution_exception&) { - recover_from_exception (); + octave::interpreter::recover_from_exception (); } } } @@ -3963,7 +3963,7 @@ } catch (const octave::execution_exception&) { - recover_from_exception (); + octave::interpreter::recover_from_exception (); } } @@ -5223,7 +5223,7 @@ } catch (const octave::execution_exception&) { - recover_from_exception (); + octave::interpreter::recover_from_exception (); execution_error = true; } @@ -5393,7 +5393,7 @@ } catch (const octave::execution_exception&) { - recover_from_exception (); + octave::interpreter::recover_from_exception (); execution_error = true; }
--- a/libinterp/parse-tree/pt-eval.cc Fri Jan 27 17:54:12 2017 -0500 +++ b/libinterp/parse-tree/pt-eval.cc Fri Jan 27 18:15:48 2017 -0500 @@ -833,7 +833,7 @@ } catch (const octave::execution_exception&) { - recover_from_exception (); + octave::interpreter::recover_from_exception (); in_try_catch--; // must be restored before "catch" block execution_error = true; @@ -905,7 +905,7 @@ } catch (const octave::execution_exception&) { - recover_from_exception (); + octave::interpreter::recover_from_exception (); if (tree_break_command::breaking || tree_return_command::returning) frame.discard (2); @@ -969,7 +969,7 @@ // interpreter's exception handling state to something "safe" // while the cleanup block runs instead of just resetting it // here? - recover_from_exception (); + octave::interpreter::recover_from_exception (); // Run the cleanup code on exceptions, so that it is run even // in case of interrupt or out-of-memory.