/[ascend]/trunk/base/generic/utilities/ascPanic.h
ViewVC logotype

Annotation of /trunk/base/generic/utilities/ascPanic.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 778 - (hide annotations) (download) (as text)
Tue Jul 18 05:10:03 2006 UTC (13 years, 7 months ago) by johnpye
File MIME type: text/x-chdr
File size: 4689 byte(s)
Working to fix the 'NORETURN' stuff so that it works on both MSVC++ and GCC and fails
gracefully elsewhere.
1 johnpye 127 /*
2     ASCEND Language Interpreter
3     AscPanic by Mark Thomas, created 15 May 1997
4     Copyright (C) 2005 Carnegie-Mellon University
5 aw0a 1
6 johnpye 127 This program is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10 aw0a 1
11 johnpye 127 This program is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14     GNU General Public License for more details.
15 aw0a 1
16 johnpye 127 You should have received a copy of the GNU General Public License
17     along with this program; if not, write to the Free Software
18     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19     This file is part of the SLV solver.
20     */
21 jds 59
22 johnpye 127 /** @file
23     Ascend Panic - fatal error handling.
24 jds 59
25 johnpye 127 Requires
26     #include <stdarg.h>
27     #include "utilities/ascConfig.h"
28     */
29 jds 59
30 johnpye 127 /* removed changelog -- see ViewCVS for full history */
31 jds 59
32 johnpye 127 #ifndef ASC_ASCPANIC_H
33     #define ASC_ASCPANIC_H
34 jds 59
35 johnpye 127 /**
36     Our assert macro. Uses Asc_Panic() to report & handle assertion failure. Disabled if ASC_NO_ASSERTIONS is defined.
37     */
38     #ifdef ASC_NO_ASSERTIONS
39     # define asc_assert(x) ((void)0)
40     #else
41     # define asc_assert(cond) \
42     ((cond) ? (void)0 : Asc_Panic(ASCERR_ASSERTION_FAILED, NULL, \
43     "Assertion failed in %s:%d: '%s'", __FILE__, __LINE__, #cond))
44     #endif
45    
46 johnpye 778 NORETURN ASC_DLLSPEC(void) Asc_Panic(
47     CONST int status, CONST char *function,
48     CONST char *format, ...
49     );
50 johnpye 127 /**< Print fatal error message, run callback function & (usually) exit the program.
51 aw0a 1
52 johnpye 127 @param status Status code passed by the calling function.
53     @param function Pointer to the name of the calling function.
54     @param format printf-style format string for VAR_ARGS to follow.
55    
56     This is the fatal error handler for the ASCEND system. It prints
57     the printf-style variable arguments using the specified format to
58     ASCERR file handle. The message is formatted with a header
59     (e.g. 'ASCEND PANIC!!) and the name of the function (if non-NULL),
60     followed by the variables & format passed as arguments. ASCERR
61     should have been initialized to a valid file stream or else the
62     message will not be printed (checked by assertion). @par
63 johnpye 778
64 johnpye 127 If a valid file name has been previously set using
65     Asc_PanicSetOutfile(), the message is printed to this file also.
66     Under Windows, a MessageBox will also be displayed with the
67     message. @par
68 johnpye 778
69 johnpye 127 If a callback has been set using Asc_PanicSetCallback(), the
70     registered function will be called with the specified status.
71     If the callback returns non-NULL, then exit() is called to end
72     the program. This is the default behavior. If the callback
73     is able to resolve the problem, then it should return zero and
74     Asc_Panic() will just return. This will be useful mostly for
75 johnpye 778 testing purposes, and should be used with caution.
76 johnpye 127 */
77    
78 johnpye 593 ASC_DLLSPEC(void ) Asc_PanicSetOutfile(CONST char *filename);
79 johnpye 127 /**< Sets a file name for reporting of Asc_Panic() messages.
80    
81     @param filename Pointer to the name of the file to print messages to.
82    
83     Calling this function with a non-NULL "filename" will cause
84     Asc_Panic() to write panic messages to "filename" in addition to the
85     ASCERR file handle. Passing in a "filename" of NULL causes panic
86     messages not to be written to disk---this undoes the effect of
87     previous calls to Asc_PanicSetOutfile().
88 aw0a 1 */
89    
90 jds 59 typedef int (*PanicCallbackFunc)(int);
91 johnpye 127 /**< Signature of the callback function called by Asc_Panic().
92 jds 54
93 johnpye 127 @param the status code passed to Asc_Panic() by the original caller.
94     @return nonzero if ASCEND should exit, 0 if Asc_Panic should just return.
95 johnpye 778
96 johnpye 127 This functionality is provided primarily for internal testing
97     purposes. It should be used with extreme caution in release
98     code. Asc_Panic() is called from all over ASCEND for many
99     error conditions, and current calls assume no return.
100     */
101    
102 johnpye 593 ASC_DLLSPEC(PanicCallbackFunc ) Asc_PanicSetCallback(PanicCallbackFunc func);
103 johnpye 127 /**< Registers a callback function to be called by Asc_Panic().
104 jds 59
105 johnpye 127 @param func Pointer to the new function to call during an Asc_Panic().
106     @return A pointer to the previously-registered callback, or NULL
107     if none was registered.
108    
109     This allows the user to specify a cleanup function to be
110 johnpye 778 called during a fatal error.
111 johnpye 127
112     @see PanicCallbackFunc for the form this callback function takes.
113     */
114    
115 johnpye 593 ASC_DLLSPEC(void ) Asc_PanicDisplayMessageBox(int is_displayed);
116 jds 59 /**<
117 johnpye 127 Controls whether a MessageBox is displayed by Asc_Panic() on Windows.
118 jds 59
119 johnpye 127 @param is_displayed if non-zero, messagebox should be displayed, else not.
120 jds 59
121 johnpye 127 Has no effect on non-Windows platforms.
122     */
123    
124     #endif /* ASC_ASCPANIC_H */

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22