Debian Codegraph @

melder/melder_assert.h

raw symbols SCIP
1 #ifndef _melder_assert_h_
2 #define _melder_assert_h_
3 /* melder_assert.h
4 *
5 * Copyright (C) 1992-2018,2025,2026 Paul Boersma
6 *
7 * This code is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or (at
10 * your option) any later version.
11 *
12 * This code is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15 * See the GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this work. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 /*
22 SYNOPSIS
23
24 Melder_assert (condition);
25
26 Crash with a message based on the following template:
27 "Assertion failed in file <fileName> on line <lineNumber>: <condition>"
28 */
29
30 void _private_Melder_assert (const char *fileName, int lineNumber, const char *condition);
31 void _private_Melder_pre (const char *fileName, int lineNumber, const char *condition);
32 void _private_Melder_post (const char *fileName, int lineNumber, const char *condition);
33
34 #ifdef NDEBUG
35 #define Melder_assert(x) ((void) 0)
36 #define Melder_pre(x) ((void) 0)
37 #define Melder_post(x) ((void) 0)
38 #else
39 #define Melder_assert(x) ((x) ? (void) (0) : (_private_Melder_assert (__FILE__, __LINE__, #x), abort ()))
40 #define Melder_pre(x) ((x) ? (void) (0) : (_private_Melder_pre (__FILE__, __LINE__, #x), abort ()))
41 #define Melder_post(x) ((x) ? (void) (0) : (_private_Melder_post (__FILE__, __LINE__, #x), abort ()))
42 #endif
43
44 template <typename Tag>
45 class _private_Melder_nonReentrant {
46 inline static bool entered = false;
47 public:
48 _private_Melder_nonReentrant (const char *fileName, int lineNumber) {
49 if (entered) {
50 _private_Melder_assert (fileName, lineNumber, "This non-reentrant function in now entered for the second time.");
51 abort ();
52 }
53 entered = true;
54 }
55 ~_private_Melder_nonReentrant () {
56 entered = false;
57 }
58 };
59 #define MELDER_ASSERT_NONREENTRANT \
60 _private_Melder_nonReentrant <struct _private_Melder_nonReentrant_tag_##__COUNTER__> _private_Melder_nonReentrant_guard (__FILE__, __LINE__);
61
62 #endif // !_melder_assert_h_