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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 709 - (show annotations) (download) (as text)
Wed Jun 28 16:28:57 2006 UTC (14 years, 3 months ago) by johnpye
File MIME type: text/x-chdr
File size: 4712 byte(s)
Monster commit!
Lots of recommenting and reorganising of external relations-related stuff.
Replaced a lot of ascmalloc and asccalloc calls with the new ASC_NEW* macros.
Fixed (?) the problem Art is having with icons in PyGTK.
Turned on -Wall in SConstruct and fixed up a stack of warnings.
Removed the redundant exit(2) from after Asc_Panic calls and added __attribute__((noreturn)).
Set doxygen to create callgraphs to level 2, updated doxyfile to version 1.4.7.
Fixed up building of extfntest.c.
1 /*
2 ASCEND Language Interpreter
3 AscPanic by Mark Thomas, created 15 May 1997
4 Copyright (C) 2005 Carnegie-Mellon University
5
6 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
11 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
16 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
22 /** @file
23 Ascend Panic - fatal error handling.
24
25 Requires
26 #include <stdarg.h>
27 #include "utilities/ascConfig.h"
28 */
29
30 /* removed changelog -- see ViewCVS for full history */
31
32 #ifndef ASC_ASCPANIC_H
33 #define ASC_ASCPANIC_H
34
35 /**
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 ASC_DLLSPEC(void ) Asc_Panic(CONST int status, CONST char *function,
47 CONST char *format, ...) NORETURN;
48 /**< Print fatal error message, run callback function & (usually) exit the program.
49
50 @param status Status code passed by the calling function.
51 @param function Pointer to the name of the calling function.
52 @param format printf-style format string for VAR_ARGS to follow.
53
54 This is the fatal error handler for the ASCEND system. It prints
55 the printf-style variable arguments using the specified format to
56 ASCERR file handle. The message is formatted with a header
57 (e.g. 'ASCEND PANIC!!) and the name of the function (if non-NULL),
58 followed by the variables & format passed as arguments. ASCERR
59 should have been initialized to a valid file stream or else the
60 message will not be printed (checked by assertion). @par
61
62 If a valid file name has been previously set using
63 Asc_PanicSetOutfile(), the message is printed to this file also.
64 Under Windows, a MessageBox will also be displayed with the
65 message. @par
66
67 If a callback has been set using Asc_PanicSetCallback(), the
68 registered function will be called with the specified status.
69 If the callback returns non-NULL, then exit() is called to end
70 the program. This is the default behavior. If the callback
71 is able to resolve the problem, then it should return zero and
72 Asc_Panic() will just return. This will be useful mostly for
73 testing purposes, and should be used with caution.
74 */
75
76 ASC_DLLSPEC(void ) Asc_PanicSetOutfile(CONST char *filename);
77 /**< Sets a file name for reporting of Asc_Panic() messages.
78
79 @param filename Pointer to the name of the file to print messages to.
80
81 Calling this function with a non-NULL "filename" will cause
82 Asc_Panic() to write panic messages to "filename" in addition to the
83 ASCERR file handle. Passing in a "filename" of NULL causes panic
84 messages not to be written to disk---this undoes the effect of
85 previous calls to Asc_PanicSetOutfile().
86 */
87
88 typedef int (*PanicCallbackFunc)(int);
89 /**< Signature of the callback function called by Asc_Panic().
90
91 @param the status code passed to Asc_Panic() by the original caller.
92 @return nonzero if ASCEND should exit, 0 if Asc_Panic should just return.
93
94 This functionality is provided primarily for internal testing
95 purposes. It should be used with extreme caution in release
96 code. Asc_Panic() is called from all over ASCEND for many
97 error conditions, and current calls assume no return.
98 */
99
100 ASC_DLLSPEC(PanicCallbackFunc ) Asc_PanicSetCallback(PanicCallbackFunc func);
101 /**< Registers a callback function to be called by Asc_Panic().
102
103 @param func Pointer to the new function to call during an Asc_Panic().
104 @return A pointer to the previously-registered callback, or NULL
105 if none was registered.
106
107 This allows the user to specify a cleanup function to be
108 called during a fatal error.
109
110 @see PanicCallbackFunc for the form this callback function takes.
111 */
112
113 ASC_DLLSPEC(void ) Asc_PanicDisplayMessageBox(int is_displayed);
114 /**<
115 Controls whether a MessageBox is displayed by Asc_Panic() on Windows.
116
117 @param is_displayed if non-zero, messagebox should be displayed, else not.
118
119 Has no effect on non-Windows platforms.
120 */
121
122 #endif /* ASC_ASCPANIC_H */

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