annotate libinterp/corefcn/panic.h @ 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 55e1412aca35
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
33243
d9ed1a322311 move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
1 ////////////////////////////////////////////////////////////////////////
d9ed1a322311 move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
2 //
d9ed1a322311 move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
3 // Copyright (C) 2024 The Octave Project Developers
d9ed1a322311 move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
4 //
d9ed1a322311 move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
5 // See the file COPYRIGHT.md in the top-level directory of this
d9ed1a322311 move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
6 // distribution or <https://octave.org/copyright/>.
d9ed1a322311 move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
7 //
d9ed1a322311 move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
8 // This file is part of Octave.
d9ed1a322311 move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
9 //
d9ed1a322311 move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
10 // Octave is free software: you can redistribute it and/or modify it
d9ed1a322311 move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
11 // under the terms of the GNU General Public License as published by
d9ed1a322311 move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
12 // the Free Software Foundation, either version 3 of the License, or
d9ed1a322311 move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
13 // (at your option) any later version.
d9ed1a322311 move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
14 //
d9ed1a322311 move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
15 // Octave is distributed in the hope that it will be useful, but
d9ed1a322311 move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
d9ed1a322311 move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
d9ed1a322311 move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
18 // GNU General Public License for more details.
d9ed1a322311 move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
19 //
d9ed1a322311 move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
20 // You should have received a copy of the GNU General Public License
d9ed1a322311 move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
21 // along with Octave; see the file COPYING. If not, see
d9ed1a322311 move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
22 // <https://www.gnu.org/licenses/>.
d9ed1a322311 move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
23 //
d9ed1a322311 move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
24 ////////////////////////////////////////////////////////////////////////
d9ed1a322311 move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
25
d9ed1a322311 move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
26 #if ! defined (octave_panic_h)
d9ed1a322311 move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
27 #define octave_panic_h 1
d9ed1a322311 move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
28
d9ed1a322311 move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
29 #include "octave-config.h"
d9ed1a322311 move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
30
d9ed1a322311 move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
31 #include <cstdarg>
d9ed1a322311 move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
32
d9ed1a322311 move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
33 OCTAVE_NORETURN
d9ed1a322311 move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
34 extern OCTINTERP_API void vpanic (const char *fmt, va_list args);
d9ed1a322311 move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
35
d9ed1a322311 move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
36 OCTAVE_FORMAT_PRINTF (1, 2)
d9ed1a322311 move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
37 OCTAVE_NORETURN
d9ed1a322311 move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
38 extern OCTINTERP_API void panic (const char *fmt, ...);
d9ed1a322311 move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
39
d9ed1a322311 move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
40 // To allow the __FILE__ and __LINE__ macros to work as expected, the
33247
55e1412aca35 call error instead of abort in panic_impossible, panic_if, and panic_unless
John W. Eaton <jwe@octave.org>
parents: 33243
diff changeset
41 // panic_impossible, panic_if, and panic_unless symbols must be defined
55e1412aca35 call error instead of abort in panic_impossible, panic_if, and panic_unless
John W. Eaton <jwe@octave.org>
parents: 33243
diff changeset
42 // as macros.
33243
d9ed1a322311 move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
43
33261
ab68bff7b8b8 style fixes for panic_ functions
John W. Eaton <jwe@octave.org>
parents: 33247
diff changeset
44 #if defined (NDEBUG)
ab68bff7b8b8 style fixes for panic_ functions
John W. Eaton <jwe@octave.org>
parents: 33247
diff changeset
45
ab68bff7b8b8 style fixes for panic_ functions
John W. Eaton <jwe@octave.org>
parents: 33247
diff changeset
46 # define panic_impossible() do { } while (0)
ab68bff7b8b8 style fixes for panic_ functions
John W. Eaton <jwe@octave.org>
parents: 33247
diff changeset
47
ab68bff7b8b8 style fixes for panic_ functions
John W. Eaton <jwe@octave.org>
parents: 33247
diff changeset
48 # define panic_if(cond) do { } while (0)
ab68bff7b8b8 style fixes for panic_ functions
John W. Eaton <jwe@octave.org>
parents: 33247
diff changeset
49
ab68bff7b8b8 style fixes for panic_ functions
John W. Eaton <jwe@octave.org>
parents: 33247
diff changeset
50 # define panic_unless(cond) do { } while (0)
ab68bff7b8b8 style fixes for panic_ functions
John W. Eaton <jwe@octave.org>
parents: 33247
diff changeset
51
ab68bff7b8b8 style fixes for panic_ functions
John W. Eaton <jwe@octave.org>
parents: 33247
diff changeset
52 #else
ab68bff7b8b8 style fixes for panic_ functions
John W. Eaton <jwe@octave.org>
parents: 33247
diff changeset
53
ab68bff7b8b8 style fixes for panic_ functions
John W. Eaton <jwe@octave.org>
parents: 33247
diff changeset
54 # define panic_impossible() \
33243
d9ed1a322311 move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
55 ::panic ("impossible state reached in file '%s' at line %d", __FILE__, __LINE__)
d9ed1a322311 move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
56
d9ed1a322311 move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
57 # define panic_if(cond) do { if (cond) panic_impossible (); } while (0)
d9ed1a322311 move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
58
d9ed1a322311 move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
59 # define panic_unless(cond) panic_if (! (cond))
33261
ab68bff7b8b8 style fixes for panic_ functions
John W. Eaton <jwe@octave.org>
parents: 33247
diff changeset
60
33243
d9ed1a322311 move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
61 #endif
d9ed1a322311 move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
62
d9ed1a322311 move global panic functions and macros to separate panic.h and panic.cc files
John W. Eaton <jwe@octave.org>
parents:
diff changeset
63 #endif