Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
assertions.C
Go to the documentation of this file.
1 // ======================================================================
2 //
3 // Copyright (c) 1997 The CGAL Consortium
4 
5 // This software and related documentation is part of the Computational
6 // Geometry Algorithms Library (CGAL).
7 // This software and documentation is provided "as-is" and without warranty
8 // of any kind. In no event shall the CGAL Consortium be liable for any
9 // damage of any kind.
10 //
11 // Every use of CGAL requires a license.
12 //
13 // Academic research and teaching license
14 // - For academic research and teaching purposes, permission to use and copy
15 // the software and its documentation is hereby granted free of charge,
16 // provided that it is not a component of a commercial product, and this
17 // notice appears in all copies of the software and related documentation.
18 //
19 // Commercial licenses
20 // - A commercial license is available through Algorithmic Solutions, who also
21 // markets LEDA (http://www.algorithmic-solutions.de).
22 // - Commercial users may apply for an evaluation license by writing to
23 // Algorithmic Solutions (contact@algorithmic-solutions.com).
24 //
25 // The CGAL Consortium consists of Utrecht University (The Netherlands),
26 // ETH Zurich (Switzerland), Free University of Berlin (Germany),
27 // INRIA Sophia-Antipolis (France), Martin-Luther-University Halle-Wittenberg
28 // (Germany), Max-Planck-Institute Saarbrucken (Germany), RISC Linz (Austria),
29 // and Tel-Aviv University (Israel).
30 //
31 // ----------------------------------------------------------------------
32 //
33 // release : CGAL-2.2
34 // release_date : 2000, September 30
35 //
36 // file : src/assertions.C
37 // package : Kernel_basic (3.14)
38 // source : assertions.fw
39 // author(s) : Geert-Jan Giezeman and Sven Schönherr
40 //
41 // coordinator : MPI, Saarbruecken (<Stefan.Schirra>)
42 //
43 // email : contact@cgal.org
44 // www : http://www.cgal.org
45 //
46 // ======================================================================
47 
48 
49 #include <CGAL/config.h>
50 #include <cstdio>
51 #include <cstdlib>
52 #include <CGAL/assertions.h>
53 #include <iostream>
54 
55 #include <cassert>
56 #include "commpi.h"
57 #ifdef TRACEBACK
58 #include <execinfo.h> /* for backtrace (GNU glibc header) */
59 #endif
60 
62 // not_implemented function
63 // ------------------------
64 void
66 {
67  assert( false);
68 }
69 
70 // static behaviour variables
71 // --------------------------
72 
75 
77 #ifdef TRACEBACK
78  const int max_stack=64;
79  void *stackPtrs[max_stack];
80 
81  int levels=backtrace(stackPtrs,max_stack);
82  char **symbols=backtrace_symbols(stackPtrs, levels);
83 
84  const int nSkip=2;
85  std::printf( "\nStack Backtrace:\n");
86  for ( int i=nSkip; i<levels; i++) {
87  std::printf( " [%d] %s\n", i-nSkip, symbols[i]);
88  }
89 #endif
90 }
91 
92 // standard error handlers
93 // -----------------------
94 static
95 void
97  const char* what,
98  const char* expr,
99  const char* file,
100  int line,
101  const char* msg )
102 {
103  std::cerr << "Rocface error: " << what << " violation!" << std::endl
104  << "Expr: " << expr << std::endl
105  << "File: " << file << std::endl
106  << "Line: " << line << std::endl;
107  if ( msg != 0)
108  std::cerr << "Explanation:" << msg << std::endl;
109 }
110 
111 
112 // standard warning handler
113 // ------------------------
114 static
115 void
117  const char* expr,
118  const char* file,
119  int line,
120  const char* msg )
121 {
122  std::cerr << "Rocface warning: check violation!" << std::endl
123  << "Expr: " << expr << std::endl
124  << "File: " << file << std::endl
125  << "Line: " << line << std::endl;
126  if ( msg != 0)
127  std::cerr << "Explanation:" << msg << std::endl;
128 
129 }
130 
131 // default handler settings
132 // ------------------------
133 static Failure_function
135 
136 static Failure_function
138 
139 // failure functions
140 // -----------------
141 void
142 assertion_fail( const char* expr,
143  const char* file,
144  int line,
145  const char* msg )
146 {
147  (*_error_handler)("assertion", expr, file, line, msg);
149  switch (_error_behaviour) {
150  case ABORT:
151  if (COMMPI_Initialized()) MPI_Abort(MPI_COMM_WORLD,-1); abort();
152  case EXIT:
153  exit(1); // EXIT_FAILURE
154  case EXIT_WITH_SUCCESS:
155  exit(0); // EXIT_SUCCESS
156  case CONTINUE:
157  ;
158  }
159 }
160 
161 void
162 precondition_fail( const char* expr,
163  const char* file,
164  int line,
165  const char* msg )
166 {
167  (*_error_handler)("precondition", expr, file, line, msg);
169  switch (_error_behaviour) {
170  case ABORT:
171  if (COMMPI_Initialized()) MPI_Abort(MPI_COMM_WORLD,-1); abort();
172  case EXIT:
173  exit(1); // EXIT_FAILURE
174  case EXIT_WITH_SUCCESS:
175  exit(0); // EXIT_SUCCESS
176  case CONTINUE:
177  ;
178  }
179 }
180 
181 void
182 postcondition_fail(const char* expr,
183  const char* file,
184  int line,
185  const char* msg )
186 {
187  (*_error_handler)("postcondition", expr, file, line, msg);
189  switch (_error_behaviour) {
190  case ABORT:
191  if (COMMPI_Initialized()) MPI_Abort(MPI_COMM_WORLD,-1); abort();
192  case EXIT:
193  exit(1); // EXIT_FAILURE
194  case EXIT_WITH_SUCCESS:
195  exit(0); // EXIT_SUCCESS
196  case CONTINUE:
197  ;
198  }
199 }
200 
201 
202 // warning function
203 // ----------------
204 void
205 warning_fail( const char* expr,
206  const char* file,
207  int line,
208  const char* msg )
209 {
210  (*_warning_handler)("warning", expr, file, line, msg);
212  switch (_warning_behaviour) {
213  case ABORT:
214  MPI_Abort(MPI_COMM_WORLD,-1); abort();
215  case EXIT:
216  exit(1); // EXIT_FAILURE
217  case EXIT_WITH_SUCCESS:
218  exit(0); // EXIT_SUCCESS
219  case CONTINUE:
220  ;
221  }
222 }
223 
224 
225 // error handler set functions
226 // ---------------------------
229 {
231  _error_handler = handler;
232  return( result);
233 }
234 
237 {
239  _warning_handler = handler;
240  return( result);
241 }
242 
245 {
247  _error_behaviour = eb;
248  return result;
249 }
250 
253 {
255  _warning_behaviour = eb;
256  return result;
257 }
258 
260 
261 
void warning_fail(const char *, const char *, int, const char *)
Definition: assertions.C:205
here we put it at the!beginning of the common block The point to point and collective!routines know about but MPI_TYPE_STRUCT as yet does not!MPI_STATUS_IGNORE and MPI_STATUSES_IGNORE are similar objects!Until the underlying MPI library implements the C version of these are declared as arrays of MPI_STATUS_SIZE!The types and are OPTIONAL!Their values are zero if they are not available Note that!using these reduces the portability of MPI_IO INTEGER MPI_BOTTOM INTEGER MPI_DOUBLE_PRECISION INTEGER MPI_LOGICAL INTEGER MPI_2REAL INTEGER MPI_2DOUBLE_COMPLEX INTEGER MPI_LB INTEGER MPI_WTIME_IS_GLOBAL INTEGER MPI_COMM_WORLD
Failure_function set_error_handler(Failure_function handler)
Sets the handler for assertion-failures.
Definition: assertion.C:104
Failure_function set_warning_handler(Failure_function handler)
Definition: assertions.C:236
Failure_behaviour set_error_behaviour(Failure_behaviour eb)
Controls the behavior when an assertion fails.
Definition: assertion.C:93
void postcondition_fail(const char *, const char *, int, const char *)
Definition: assertions.C:182
void(* Failure_function)(const char *, const char *, const char *, int, const char *)
Function type for error handlers.
void precondition_fail(const char *, const char *, int, const char *)
Definition: assertions.C:162
Failure_behaviour set_warning_behaviour(Failure_behaviour eb)
Definition: assertions.C:252
Failure_behaviour
Behavior of failures.
static Failure_behaviour _error_behaviour
Definition: assertions.C:73
COM_BEGIN_NAME_SPACE void printStackBacktrace()
Print the stack backtrace.
void assertion_fail(const char *, const char *, int, const char *)
Default error handler.
Definition: assertion.C:71
static void _standard_warning_handler(const char *, const char *expr, const char *file, int line, const char *msg)
Definition: assertions.C:116
blockLoc i
Definition: read.cpp:79
Contains declarations of MPI subroutines used in Roccom.
static Failure_function _error_handler
Definition: assertions.C:134
CGAL_BEGIN_NAMESPACE void not_implemented()
Definition: assertions.C:65
static Failure_behaviour _warning_behaviour
Definition: assertions.C:74
static Failure_function _warning_handler
Definition: assertions.C:137
#define CGAL_BEGIN_NAMESPACE
Definition: kdtree_d.h:86
static void _standard_error_handler(const char *what, const char *expr, const char *file, int line, const char *msg)
Definition: assertions.C:96
int COMMPI_Initialized()
Definition: commpi.h:168
#define CGAL_END_NAMESPACE
Definition: kdtree_d.h:87