comparison libinterp/corefcn/panic.h @ 33243:d9ed1a322311

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