Mercurial > octave
changeset 27520:7a871724d4b0
restore some exception handling functions and variables and deprecate them
* quit.h, quit.cc (octave_exception_state, octave_bad_alloc_hook):
Restore variables, mark as deprecated.
(enum octave_exception): Restore enum values, mark as deprecated.
(internal_exception_state): New static variable for internal use.
(enum octave_internal_exception): New enum values. Use to replace
octave_exception enum values internally.
(octave_throw_interrupt_exception, octave_throw_execution_exception,
octave_throw_bad_alloc, octave_rethrow_exception): Restore functions,
mark as deprecated.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 17 Oct 2019 11:59:26 -0400 |
parents | 804e5d42b728 |
children | 37f9eb2c05e0 |
files | liboctave/util/quit.cc liboctave/util/quit.h |
diffstat | 2 files changed, 124 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/util/quit.cc Wed Oct 16 23:26:33 2019 -0400 +++ b/liboctave/util/quit.cc Thu Oct 17 11:59:26 2019 -0400 @@ -34,11 +34,32 @@ sig_atomic_t octave_interrupt_state = 0; +// DEPRECATED in Octave 6. +// This variable should never have been public. +sig_atomic_t octave_exception_state = 0; +// Use this variable internally until the functions that use it can be +// removed. +static sig_atomic_t internal_exception_state; + volatile sig_atomic_t octave_signal_caught = 0; void (*octave_signal_hook) (void) = nullptr; void (*octave_interrupt_hook) (void) = nullptr; +// DEPRECATED in Octave 6. +void (*octave_bad_alloc_hook) (void) = nullptr; + +// The octave_exception enum values were DEPRECATED in Octave 6. +// Use these values internally until the functions that use them can be +// removed. +enum octave_internal_exception +{ + octave_internal_no_exception = 0, + octave_internal_exec_exception = 1, + octave_internal_alloc_exception = 3, + octave_internal_quit_exception = 4 +}; + namespace octave { std::string execution_exception::stack_trace (void) const @@ -96,8 +117,6 @@ void octave_handle_signal (void) { - octave_signal_caught = 0; - if (octave_signal_hook) octave_signal_hook (); @@ -105,9 +124,64 @@ { octave_interrupt_state = -1; - if (octave_interrupt_hook) - octave_interrupt_hook (); + throw octave::interrupt_exception (); + } +} + +// DEPRECATED in Octave 6 +void +octave_throw_interrupt_exception (void) +{ + if (octave_interrupt_hook) + octave_interrupt_hook (); + + throw octave::interrupt_exception (); +} + +// DEPRECATED in Octave 6 +void +octave_throw_execution_exception (void) +{ + // FIXME: would a hook function be useful here? + + internal_exception_state = octave_internal_exec_exception; + + throw octave::execution_exception (); +} + +// DEPRECATED in Octave 6 +void +octave_throw_bad_alloc (void) +{ + internal_exception_state = octave_internal_alloc_exception; + + throw std::bad_alloc (); +} + +// DEPRECATED in Octave 6 +void +octave_rethrow_exception (void) +{ + if (octave_interrupt_state) + { + octave_interrupt_state = -1; throw octave::interrupt_exception (); } + else + { + switch (internal_exception_state) + { + case octave_internal_exec_exception: + throw octave::execution_exception (); + break; + + case octave_internal_alloc_exception: + throw std::bad_alloc (); + break; + + default: + break; + } + } }
--- a/liboctave/util/quit.h Wed Oct 16 23:26:33 2019 -0400 +++ b/liboctave/util/quit.h Thu Oct 17 11:59:26 2019 -0400 @@ -197,6 +197,26 @@ #endif +enum +octave_exception +{ + octave_no_exception + OCTAVE_DEPRECATED (6, "the 'octave_no_exception' enum value is an obsolete internal value; any uses should be removed") + = 0, + + octave_exec_exception + OCTAVE_DEPRECATED (6, "the 'octave_exec_exception' enum value is an obsolete internal value; any uses should be removed") + = 1, + + octave_alloc_exception + OCTAVE_DEPRECATED (6, "the 'octave_alloc_exception' enum value is an obsolete internal value; any uses should be removed") + = 3, + + octave_quit_exception + OCTAVE_DEPRECATED (6, "the 'octave_quit_exception' enum value is an obsolete internal value; any uses should be removed") + = 4 +}; + /* > 0: interrupt pending 0: no interrupt pending @@ -204,16 +224,34 @@ */ OCTAVE_API extern sig_atomic_t octave_interrupt_state; +OCTAVE_DEPRECATED (6, "'octave_exception_state' is an obsolete internal variable; any uses should be removed") +OCTAVE_API extern sig_atomic_t octave_exception_state; + OCTAVE_API extern volatile sig_atomic_t octave_signal_caught; OCTAVE_API extern void octave_handle_signal (void); +OCTAVE_DEPRECATED (6, "use 'throw octave::interrupt_exception' instead") +OCTAVE_NORETURN OCTAVE_API extern void octave_throw_interrupt_exception (void); + +OCTAVE_DEPRECATED (6, "use 'throw octave::execution_exception' instead") +OCTAVE_NORETURN OCTAVE_API extern void octave_throw_execution_exception (void); + +OCTAVE_DEPRECATED (6, "use 'throw std::bad_alloc' instead") +OCTAVE_NORETURN OCTAVE_API extern void octave_throw_bad_alloc (void); + +OCTAVE_DEPRECATED (6, "use 'throw' instead") +OCTAVE_API extern void octave_rethrow_exception (void); + #if defined (__cplusplus) inline void octave_quit (void) { if (octave_signal_caught) - octave_handle_signal (); + { + octave_signal_caught = 0; + octave_handle_signal (); + } }; #define OCTAVE_QUIT octave_quit () @@ -224,10 +262,12 @@ do \ { \ if (octave_signal_caught) \ - octave_handle_signal (); \ + { \ + octave_signal_caught = 0; \ + octave_handle_signal (); \ + } \ } \ while (0) - #endif /* The following macros are obsolete. Interrupting immediately by @@ -268,6 +308,9 @@ extern OCTAVE_API void (*octave_signal_hook) (void); extern OCTAVE_API void (*octave_interrupt_hook) (void); +OCTAVE_DEPRECATED (6, "'octave_bad_alloc_hook' is obsolete and no longer used") +extern OCTAVE_API void (*octave_bad_alloc_hook) (void); + #endif #endif