Mercurial > octave
changeset 33261:ab68bff7b8b8
style fixes for panic_ functions
* panic.h (panic_impossible, panic_if, panic_unless): If NDEBUG is
defined, define away using "do { } while (0)" so that a semicolon is
always required. Also allow panic_impossible to be defined away if
NDEBUG is defined.
* lo-error.h (liboctave_panic_impossible, liboctave_panic_if,
liboctave_panic_unless): Likewise.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 28 Mar 2024 00:32:26 -0400 |
parents | 9a0bf9284128 |
children | c338b0cb940e a7d829ba6d44 |
files | libinterp/corefcn/panic.h liboctave/util/lo-error.h |
diffstat | 2 files changed, 23 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/corefcn/panic.h Wed Mar 27 23:44:46 2024 -0400 +++ b/libinterp/corefcn/panic.h Thu Mar 28 00:32:26 2024 -0400 @@ -41,19 +41,23 @@ // panic_impossible, panic_if, and panic_unless symbols must be defined // as macros. -#define panic_impossible() \ +#if defined (NDEBUG) + +# define panic_impossible() do { } while (0) + +# define panic_if(cond) do { } while (0) + +# define panic_unless(cond) do { } while (0) + +#else + +# define panic_impossible() \ ::panic ("impossible state reached in file '%s' at line %d", __FILE__, __LINE__) -#if defined (NDEBUG) -# define panic_if(cond) -#else # define panic_if(cond) do { if (cond) panic_impossible (); } while (0) -#endif -#if defined (NDEBUG) -# define panic_unless(cond) -#else # define panic_unless(cond) panic_if (! (cond)) + #endif #endif
--- a/liboctave/util/lo-error.h Wed Mar 27 23:44:46 2024 -0400 +++ b/liboctave/util/lo-error.h Thu Mar 28 00:32:26 2024 -0400 @@ -85,18 +85,22 @@ // liboctave_panic_impossible, liboctave_panic_if, and // liboctave_panic_unless symbols must be defined as macros. -#define liboctave_panic_impossible() (*current_liboctave_error_handler) ("impossible state reached in file '%s' at line %d", __FILE__, __LINE__) +#if defined (NDEBUG) + +# define liboctave_panic_impossible() do { } while (0) + +# define liboctave_panic_if(cond) do { } while (0) -#if defined (NDEBUG) -# define liboctave_panic_if(cond) +# define liboctave_panic_unless(cond) do { } while (0) + #else + +# define liboctave_panic_impossible() (*current_liboctave_error_handler) ("impossible state reached in file '%s' at line %d", __FILE__, __LINE__) + # define liboctave_panic_if(cond) do { if (cond) liboctave_panic_impossible (); } while (0) -#endif -#if defined (NDEBUG) -# define liboctave_panic_unless(cond) -#else # define liboctave_panic_unless(cond) liboctave_panic_if (! (cond)) + #endif #if defined (__cplusplus)