Subversion Repositories Games.Descent

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 pmbaty 1
/*
2
 * Portions of this file are copyright Rebirth contributors and licensed as
3
 * described in COPYING.txt.
4
 * Portions of this file are copyright Parallax Software and licensed
5
 * according to the Parallax license below.
6
 * See COPYING.txt for license details.
7
 
8
THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
9
SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
10
END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
11
ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
12
IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
13
SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
14
FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
15
CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
16
AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
17
COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
18
*/
19
 
20
/*
21
 *
22
 * Header for error handling/printing/exiting code
23
 *
24
 */
25
 
26
#pragma once
27
 
28
#include <cstddef>
29
#include <stdio.h>
30
#include "dxxsconf.h"
31
#include "dsx-ns.h"
32
#include <assert.h>
33
#include "fmtcheck.h"
34
 
35
#ifdef __cplusplus
36
 
37
#ifdef __GNUC__
38
#define __noreturn __attribute__ ((noreturn))
39
#else
40
#define __noreturn
41
#endif
42
 
43
namespace dcx {
44
 
45
void Warning_puts(const char *str) __attribute_nonnull();
46
void Warning(const char *fmt,...) __attribute_format_printf(1, 2);                              //print out warning message to user
47
#define Warning(F,...)  dxx_call_printf_checked(Warning,Warning_puts,(),(F),##__VA_ARGS__)
48
#if DXX_USE_EDITOR
49
void set_warn_func(void (*f)(const char *s));//specifies the function to call with warning messages
50
void clear_warn_func();//say this function no longer valid
51
#endif
52
__noreturn
53
__attribute_nonnull()
54
void Error_puts(const char *file, unsigned line, const char *func, const char *str);
55
#define Error_puts(F)   Error_puts(__FILE__, __LINE__, __func__, F)
56
__noreturn
57
__attribute_format_printf(4, 5)
58
__attribute_nonnull()
59
void Error(const char *file, unsigned line, const char *func, const char *fmt,...);                             //exit with error code=1, print message
60
#define Error(F,...)    dxx_call_printf_checked(Error,(Error_puts),(__FILE__, __LINE__, __func__),(F),##__VA_ARGS__)
61
 
62
__noreturn
63
void UserError_puts(const char *str, std::size_t);
64
 
65
template <std::size_t len>
66
__noreturn
67
static inline void UserError_puts(const char (&str)[len])
68
{
69
        UserError_puts(str, len - 1);
70
}
71
void UserError(const char *fmt, ...) __noreturn __attribute_format_printf(1, 2);
72
 
73
}
74
#define DXX_STRINGIZE_FL2(F,L,S)        F ":" #L ": " S
75
#define DXX_STRINGIZE_FL(F,L,S) DXX_STRINGIZE_FL2(F, L, S)
76
#define UserError(F,...)        dxx_call_printf_checked(UserError,(UserError_puts),(),DXX_STRINGIZE_FL(__FILE__, __LINE__, F),##__VA_ARGS__)
77
#define Assert assert
78
 
79
#define LevelErrorV(V,F,...)    con_printf(V, DXX_STRINGIZE_FL(__FILE__, __LINE__, F "  Please report this to the level author, not to the Rebirth maintainers."), ##__VA_ARGS__)
80
#define LevelError(F,...)       LevelErrorV(CON_URGENT, F, ##__VA_ARGS__)
81
 
82
/* Compatibility with x86-specific name */
83
#define Int3() d_debugbreak()
84
 
85
#ifndef NDEBUG          //macros for debugging
86
#       define DXX_ENABLE_DEBUGBREAK_TRAP
87
#endif
88
 
89
/* Allow macro override */
90
 
91
#if defined(DXX_ENABLE_DEBUGBREAK_TRAP) && !defined(DXX_DEBUGBREAK_TRAP)
92
 
93
#if defined __clang__
94
        /* Must be first, since clang also defines __GNUC__ */
95
#       define DXX_DEBUGBREAK_TRAP()    __builtin_debugtrap()
96
#elif defined __GNUC__
97
#       if defined(__i386__) || defined(__amd64__)
98
#               define DXX_DEBUGBREAK_TRAP()    __asm__ __volatile__("int3" ::: "cc", "memory")
99
#       endif
100
#elif defined _MSC_VER
101
#       define DXX_DEBUGBREAK_TRAP()    __debugbreak()
102
#endif
103
 
104
#ifndef DXX_DEBUGBREAK_TRAP
105
#       if defined __unix__
106
/* for raise */
107
#               include <signal.h>
108
#               define DXX_DEBUGBREAK_TRAP()    raise(SIGTRAP)
109
#       elif defined __GNUC__
110
        /* May terminate execution */
111
#               define DXX_DEBUGBREAK_TRAP()    __builtin_trap()
112
#       endif
113
#endif
114
 
115
#endif
116
 
117
namespace dcx {
118
 
119
// Encourage optimizer to treat d_debugbreak paths as unlikely
120
__attribute_cold
121
// Requested by btb to force Xcode to stay in the calling function
122
__attribute_always_inline()
123
static inline void d_debugbreak()
124
{
125
        /* Allow explicit activation in NDEBUG builds */
126
#ifdef DXX_DEBUGBREAK_TRAP
127
        DXX_DEBUGBREAK_TRAP();
128
#endif
129
 
130
}
131
 
132
}
133
 
134
#endif