Blender  V3.3
BLI_assert.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
9 #include "BLI_assert.h" /* Own include. */
10 #include "BLI_system.h"
11 
12 #include <stdio.h>
13 #include <stdlib.h>
14 
15 void _BLI_assert_print_pos(const char *file, const int line, const char *function, const char *id)
16 {
17  fprintf(stderr, "BLI_assert failed: %s:%d, %s(), at \'%s\'\n", file, line, function, id);
18 }
19 
20 void _BLI_assert_print_extra(const char *str)
21 {
22  fprintf(stderr, " %s\n", str);
23 }
24 
25 void _BLI_assert_unreachable_print(const char *file, const int line, const char *function)
26 {
27  fprintf(stderr, "Code marked as unreachable has been executed. Please report this as a bug.\n");
28  fprintf(stderr, "Error found at %s:%d in %s.\n", file, line, function);
29 }
30 
32 {
33 #ifndef NDEBUG
34  BLI_system_backtrace(stderr);
35 #endif
36 }
37 
39 {
40  /* Wrap to remove 'noreturn' attribute since this suppresses missing return statements,
41  * allowing changes to debug builds to accidentally to break release builds.
42  *
43  * For example `BLI_assert_unreachable();` at the end of a function that returns a value,
44  * will hide that it's missing a return. */
45 
46  abort();
47 }
void _BLI_assert_print_backtrace(void)
Definition: BLI_assert.c:31
void _BLI_assert_print_extra(const char *str)
Definition: BLI_assert.c:20
void _BLI_assert_unreachable_print(const char *file, const int line, const char *function)
Definition: BLI_assert.c:25
void _BLI_assert_print_pos(const char *file, const int line, const char *function, const char *id)
Definition: BLI_assert.c:15
void _BLI_assert_abort(void)
Definition: BLI_assert.c:38
void BLI_system_backtrace(FILE *fp)
Definition: system.c:62
FILE * file
#define str(s)