]> granicus.if.org Git - postgresql/blob - src/backend/utils/error/assert.c
Change Copyright from PostgreSQL, Inc to PostgreSQL Global Development Group.
[postgresql] / src / backend / utils / error / assert.c
1 /*-------------------------------------------------------------------------
2  *
3  * assert.c
4  *        Assert code.
5  *
6  * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
7  * Portions Copyright (c) 1994, Regents of the University of California
8  *
9  *
10  * IDENTIFICATION
11  *        $Header: /cvsroot/pgsql/src/backend/utils/error/assert.c,v 1.20 2001/01/24 19:43:15 momjian Exp $
12  *
13  * NOTE
14  *        This should eventually work with elog(), dlog(), etc.
15  *
16  *-------------------------------------------------------------------------
17  */
18 #include "postgres.h"
19
20 #include <stdio.h>
21 #include <unistd.h>
22
23 #include "utils/exc.h"
24
25 int
26 ExceptionalCondition(char *conditionName,
27                                          Exception *exceptionP,
28                                          char *detail,
29                                          char *fileName,
30                                          int lineNumber)
31 {
32         ExcFileName = fileName;
33         ExcLineNumber = lineNumber;
34
35         if (!PointerIsValid(conditionName)
36                 || !PointerIsValid(fileName)
37                 || !PointerIsValid(exceptionP))
38         {
39                 fprintf(stderr, "TRAP: ExceptionalCondition: bad arguments\n");
40
41                 ExcAbort(exceptionP,
42                                  (ExcDetail) detail,
43                                  (ExcData) NULL,
44                                  (ExcMessage) NULL);
45         }
46         else
47         {
48                 fprintf(stderr, "TRAP: %s(\"%s:%s\", File: \"%s\", Line: %d)\n",
49                                 exceptionP->message, conditionName,
50                                 (detail == NULL ? "" : detail),
51                                 fileName, lineNumber);
52         }
53
54 #ifdef ABORT_ON_ASSERT
55         abort();
56 #endif
57 #ifdef SLEEP_ON_ASSERT
58         sleep(1000000);
59 #endif
60
61         /*
62          * XXX Depending on the Exception and tracing conditions, you will XXX
63          * want to stop here immediately and maybe dump core. XXX This may be
64          * especially true for Assert(), etc.
65          */
66
67         /* TraceDump();         dump the trace stack */
68
69         /* XXX FIXME: detail is lost */
70         ExcRaise(exceptionP, (ExcDetail) 0, (ExcData) NULL, conditionName);
71         return 0;
72 }