1 | /* |
2 | * The contents of this file are subject to the Interbase Public |
3 | * License Version 1.0 (the "License"); you may not use this file |
4 | * except in compliance with the License. You may obtain a copy |
5 | * of the License at http://www.Inprise.com/IPL.html |
6 | * |
7 | * Software distributed under the License is distributed on an |
8 | * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express |
9 | * or implied. See the License for the specific language governing |
10 | * rights and limitations under the License. |
11 | * |
12 | * The Original Code was created by Inprise Corporation |
13 | * and its predecessors. Portions created by Inprise Corporation are |
14 | * Copyright (C) Inprise Corporation. |
15 | * |
16 | * All Rights Reserved. |
17 | * Contributor(s): ______________________________________. |
18 | * CVC: Do not override local fb_assert like the ones in gpre and dsql. |
19 | */ |
20 | |
21 | #ifndef COMMON_GDSASSERT_H |
22 | #define COMMON_GDSASSERT_H |
23 | |
24 | #include "../yvalve/gds_proto.h" |
25 | |
26 | #ifdef DEV_BUILD |
27 | |
28 | #include <stdlib.h> // abort() |
29 | #include <stdio.h> |
30 | |
31 | #ifdef WIN_NT |
32 | #include <io.h> // isatty() |
33 | #endif |
34 | #ifdef HAVE_UNISTD_H |
35 | #include <unistd.h> // isatty() |
36 | #endif |
37 | |
38 | inline void fb_assert_impl(const char* msg, const char* file, int line, bool do_abort) |
39 | { |
40 | const char* const ASSERT_FAILURE_STRING = "Assertion (%s) failure: %s %" LINEFORMAT"\n" ; |
41 | |
42 | if (isatty(2)) |
43 | fprintf(stderr, ASSERT_FAILURE_STRING, msg, file, line); |
44 | else |
45 | gds__log(ASSERT_FAILURE_STRING, msg, file, line); |
46 | |
47 | if (do_abort) |
48 | abort(); |
49 | } |
50 | |
51 | #if !defined(fb_assert) |
52 | |
53 | #define fb_assert(ex) \ |
54 | ((void) ( !(ex) && (fb_assert_impl(#ex, __FILE__, __LINE__, true), 1) )) |
55 | |
56 | #define fb_assert_continue(ex) \ |
57 | ((void) ( !(ex) && (fb_assert_impl(#ex, __FILE__, __LINE__, false), 1) )) |
58 | |
59 | #endif // fb_assert |
60 | |
61 | #else // DEV_BUILD |
62 | |
63 | #define fb_assert(ex) \ |
64 | ((void) 0) |
65 | |
66 | #define fb_assert_continue(ex) \ |
67 | ((void) 0) |
68 | |
69 | #endif // DEV_BUILD |
70 | |
71 | namespace DtorException { |
72 | inline void devHalt() |
73 | { |
74 | // If any guard's dtor is executed during exception processing, |
75 | // (remember - this guards live on the stack), exception |
76 | // in leave() causes std::terminate() to be called, therefore |
77 | // losing original exception information. Not good for us. |
78 | // Therefore ignore in release and abort in debug. |
79 | #ifdef DEV_BUILD |
80 | abort(); |
81 | #endif |
82 | } |
83 | } |
84 | |
85 | #endif // COMMON_GDSASSERT_H |
86 | |