OSDN Git Service

From: Raymond Toy <toy@rtp.ericsson.se>
[pg-rex/syncrep.git] / src / backend / utils / error / assert.c
1 /*-------------------------------------------------------------------------
2  *
3  * assert.c--
4  *    Assert code.
5  *
6  * Copyright (c) 1994, Regents of the University of California
7  *
8  *
9  * IDENTIFICATION
10  *    $Header: /cvsroot/pgsql/src/backend/utils/error/assert.c,v 1.4 1997/04/17 20:38:26 scrappy Exp $
11  *
12  * NOTE
13  *    This should eventually work with elog(), dlog(), etc.
14  *
15  *-------------------------------------------------------------------------
16  */
17 #include <stdio.h>
18
19 #include "postgres.h"           /* where the declaration goes */
20 #include "utils/module.h"
21
22 #include "utils/exc.h"
23
24 int
25 ExceptionalCondition(char* conditionName,
26                      Exception *exceptionP,
27                      char* detail,
28                      char* fileName,
29                      int lineNumber)
30 {
31     extern char* ExcFileName;   /* XXX */
32     extern Index ExcLineNumber; /* XXX */
33     
34     ExcFileName = fileName;
35     ExcLineNumber = lineNumber;
36     
37     if (!PointerIsValid(conditionName)
38         || !PointerIsValid(fileName)
39         || !PointerIsValid(exceptionP)) {
40         fprintf(stderr, "ExceptionalCondition: bad arguments\n");
41         
42         ExcAbort(exceptionP, 
43                  (ExcDetail)detail,
44                  (ExcData)NULL,
45                  (ExcMessage)NULL);
46     } else {
47         fprintf(stderr,
48                 "%s(\"%s:%s\", File: \"%s\", Line: %d)\n",
49                 exceptionP->message, conditionName, detail == NULL ? "" : detail,
50                 fileName, lineNumber);
51     }
52
53 #ifdef ABORT_ON_ASSERT
54     abort();
55 #endif
56     /*
57      * XXX Depending on the Exception and tracing conditions, you will
58      * XXX want to stop here immediately and maybe dump core.
59      * XXX This may be especially true for Assert(), etc.
60      */
61     
62     /* TraceDump();     dump the trace stack */
63     
64     /* XXX FIXME: detail is lost */
65     ExcRaise(exceptionP, (ExcDetail)0, (ExcData)NULL, conditionName);
66     return(0);
67 }