A few fixups in error handling: mark pg_re_throw() as noreturn for gcc,
authorTom Lane <tgl@sss.pgh.pa.us>
Fri, 4 May 2007 02:01:02 +0000 (02:01 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Fri, 4 May 2007 02:01:02 +0000 (02:01 +0000)
and for other compilers, insert a dummy exit() call so that they understand
PG_RE_THROW() doesn't return.  Insert fflush(stderr) in ExceptionalCondition,
per recent buildfarm evidence that that might not happen automatically on some
platforms.  And const-ify ExceptionalCondition's declaration while at it.

src/backend/utils/error/assert.c
src/backend/utils/error/elog.c
src/include/postgres.h
src/include/utils/elog.h

index fd334a1947088829b3c12476794dc6930d02e0cd..a2d455b397c03ca2b76b97056d84c2c0f9f7df3b 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/backend/utils/error/assert.c,v 1.33 2007/01/05 22:19:43 momjian Exp $
+ *   $PostgreSQL: pgsql/src/backend/utils/error/assert.c,v 1.34 2007/05/04 02:01:02 tgl Exp $
  *
  * NOTE
  *   This should eventually work with elog()
 
 /*
  * ExceptionalCondition - Handles the failure of an Assert()
+ *
+ * Note: this can't actually return, but we declare it as returning int
+ * because the TrapMacro() macro might get wonky otherwise.
  */
 int
-ExceptionalCondition(char *conditionName,
-                    char *errorType,
-                    char *fileName,
+ExceptionalCondition(const char *conditionName,
+                    const char *errorType,
+                    const char *fileName,
                     int lineNumber)
 {
    if (!PointerIsValid(conditionName)
@@ -39,6 +42,9 @@ ExceptionalCondition(char *conditionName,
                     fileName, lineNumber);
    }
 
+   /* Usually this shouldn't be needed, but make sure the msg went out */
+   fflush(stderr);
+
 #ifdef SLEEP_ON_ASSERT
 
    /*
index d74442ee54b3ce368b76c8f765150f856fc9ae64..93e7663da3aca50e02bedbf9c0b5424171edcbb2 100644 (file)
@@ -42,7 +42,7 @@
  *
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/backend/utils/error/elog.c,v 1.184 2007/05/02 15:32:41 tgl Exp $
+ *   $PostgreSQL: pgsql/src/backend/utils/error/elog.c,v 1.185 2007/05/04 02:01:02 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -1151,6 +1151,16 @@ pg_re_throw(void)
 
        errfinish(0);
    }
+
+   /* We mustn't return... */
+   ExceptionalCondition("pg_re_throw tried to return", "FailedAssertion",
+                        __FILE__, __LINE__);
+
+   /*
+    * Since ExceptionalCondition isn't declared noreturn because of
+    * TrapMacro(), we need this to keep gcc from complaining.
+    */
+   abort();
 }
 
 
index 1ff0e97e9b6343826096d48af14d21f27458a0c4..27c21e2bcc8e1ed7762e55d71def68e47c8af36f 100644 (file)
@@ -10,7 +10,7 @@
  * Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
  * Portions Copyright (c) 1995, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/include/postgres.h,v 1.79 2007/04/06 04:21:44 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/postgres.h,v 1.80 2007/05/04 02:01:02 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -694,8 +694,9 @@ extern DLLIMPORT bool assert_enabled;
        Trap(!(condition), "BadState")
 #endif   /* USE_ASSERT_CHECKING */
 
-extern int ExceptionalCondition(char *conditionName, char *errorType,
-                    char *fileName, int lineNumber);
+extern int ExceptionalCondition(const char *conditionName,
+                               const char *errorType,
+                               const char *fileName, int lineNumber);
 
 /* ----------------------------------------------------------------
  *             Section 4: genbki macros used by catalog/pg_xxx.h files
index e84d67345f9cf03e4249e2fa930d4b4ce7a48120..6a4809a33974b130f7038dafa448ca320f6dd5b3 100644 (file)
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/include/utils/elog.h,v 1.85 2007/05/02 15:32:42 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/utils/elog.h,v 1.86 2007/05/04 02:01:02 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -222,8 +222,17 @@ extern DLLIMPORT ErrorContextCallback *error_context_stack;
        error_context_stack = save_context_stack; \
    } while (0)
 
+/*
+ * gcc understands __attribute__((noreturn)); for other compilers, insert
+ * a useless exit() call so that the compiler gets the point.
+ */
+#ifdef __GNUC__
 #define PG_RE_THROW()  \
    pg_re_throw()
+#else
+#define PG_RE_THROW()  \
+   (pg_re_throw(), exit(1))
+#endif
 
 extern DLLIMPORT sigjmp_buf *PG_exception_stack;
 
@@ -262,7 +271,7 @@ extern ErrorData *CopyErrorData(void);
 extern void FreeErrorData(ErrorData *edata);
 extern void FlushErrorState(void);
 extern void ReThrowError(ErrorData *edata);
-extern void pg_re_throw(void);
+extern void pg_re_throw(void) __attribute__((noreturn));
 
 
 /* GUC-configurable parameters */