From c5354dff2052e6922ae7add998753d9bafcd19b0 Mon Sep 17 00:00:00 2001 From: Bruce Momjian Date: Sat, 10 Aug 2002 20:29:18 +0000 Subject: [PATCH] This patch removes a lot of unused code related to assertions and error handling, and simplifies the code that remains. Apparently, the code that left Berkeley had a whole "error handling subsystem", which exceptions and whatnot. Since we don't use that anymore, there's no reason to keep it around. The regression tests pass with the patch applied. Unless anyone sees a problem, please apply. Neil Conway --- src/backend/bootstrap/bootstrap.c | 4 +- src/backend/port/ipc_test.c | 13 +- src/backend/postmaster/postmaster.c | 6 +- src/backend/tcop/postgres.c | 35 +---- src/backend/utils/error/Makefile | 4 +- src/backend/utils/error/assert.c | 41 ++---- src/backend/utils/error/exc.c | 198 ---------------------------- src/backend/utils/error/excabort.c | 28 ---- src/backend/utils/error/excid.c | 54 -------- src/backend/utils/mmgr/mcxt.c | 3 +- src/include/postgres.h | 90 ++----------- 11 files changed, 35 insertions(+), 441 deletions(-) delete mode 100644 src/backend/utils/error/exc.c delete mode 100644 src/backend/utils/error/excabort.c delete mode 100644 src/backend/utils/error/excid.c diff --git a/src/backend/bootstrap/bootstrap.c b/src/backend/bootstrap/bootstrap.c index 90e5c2b96c..d2afa64768 100644 --- a/src/backend/bootstrap/bootstrap.c +++ b/src/backend/bootstrap/bootstrap.c @@ -8,7 +8,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/bootstrap/bootstrap.c,v 1.136 2002/08/04 06:26:38 thomas Exp $ + * $Header: /cvsroot/pgsql/src/backend/bootstrap/bootstrap.c,v 1.137 2002/08/10 20:29:17 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -37,7 +37,6 @@ #include "storage/proc.h" #include "tcop/tcopprot.h" #include "utils/builtins.h" -#include "utils/exc.h" #include "utils/fmgroids.h" #include "utils/guc.h" #include "utils/lsyscache.h" @@ -238,7 +237,6 @@ BootstrapMain(int argc, char *argv[]) */ if (!IsUnderPostmaster) { - EnableExceptionHandling(true); MemoryContextInit(); } diff --git a/src/backend/port/ipc_test.c b/src/backend/port/ipc_test.c index 9805ed5657..2421a7e5a0 100644 --- a/src/backend/port/ipc_test.c +++ b/src/backend/port/ipc_test.c @@ -21,7 +21,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/port/ipc_test.c,v 1.3 2002/06/20 20:29:33 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/port/ipc_test.c,v 1.4 2002/08/10 20:29:18 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -34,7 +34,6 @@ #include "storage/ipc.h" #include "storage/pg_sema.h" #include "storage/pg_shmem.h" -#include "utils/exc.h" /********* stuff needed to satisfy references in shmem/sema code *********/ @@ -56,8 +55,6 @@ int NBuffers = DEF_NBUFFERS; bool assert_enabled = true; #endif -Exception FailedAssertion = {"Failed Assertion"}; - #define MAX_ON_EXITS 20 @@ -120,14 +117,12 @@ ProcessInterrupts(void) int ExceptionalCondition(char *conditionName, - Exception *exceptionP, - char *detail, + char *errorType, char *fileName, int lineNumber) { - fprintf(stderr, "TRAP: %s(\"%s:%s\", File: \"%s\", Line: %d)\n", - exceptionP->message, conditionName, - (detail == NULL ? "" : detail), + fprintf(stderr, "TRAP: %s(\"%s\", File: \"%s\", Line: %d)\n", + errorType, conditionName, fileName, lineNumber); abort(); return 0; diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c index acc4d0090b..1c70c4f0ec 100644 --- a/src/backend/postmaster/postmaster.c +++ b/src/backend/postmaster/postmaster.c @@ -37,7 +37,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.282 2002/08/04 06:26:38 thomas Exp $ + * $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.283 2002/08/10 20:29:18 momjian Exp $ * * NOTES * @@ -102,7 +102,6 @@ #include "storage/proc.h" #include "access/xlog.h" #include "tcop/tcopprot.h" -#include "utils/exc.h" #include "utils/guc.h" #include "utils/memutils.h" #include "utils/ps_status.h" @@ -380,9 +379,8 @@ PostmasterMain(int argc, char *argv[]) MyProcPid = getpid(); /* - * Fire up essential subsystems: error and memory management + * Fire up essential subsystems: memory management */ - EnableExceptionHandling(true); MemoryContextInit(); /* diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c index e430d07c76..6c5e17b48f 100644 --- a/src/backend/tcop/postgres.c +++ b/src/backend/tcop/postgres.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.280 2002/08/06 05:24:04 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.281 2002/08/10 20:29:18 momjian Exp $ * * NOTES * this is the "main" module of the postgres backend and @@ -54,7 +54,6 @@ #include "tcop/pquery.h" #include "tcop/tcopprot.h" #include "tcop/utility.h" -#include "utils/exc.h" #include "utils/guc.h" #include "utils/memutils.h" #include "utils/ps_status.h" @@ -1148,7 +1147,6 @@ PostgresMain(int argc, char *argv[], const char *username) */ if (!IsUnderPostmaster) { - EnableExceptionHandling(true); MemoryContextInit(); } @@ -1676,7 +1674,7 @@ PostgresMain(int argc, char *argv[], const char *username) if (!IsUnderPostmaster) { puts("\nPOSTGRES backend interactive interface "); - puts("$Revision: 1.280 $ $Date: 2002/08/06 05:24:04 $\n"); + puts("$Revision: 1.281 $ $Date: 2002/08/10 20:29:18 $\n"); } /* @@ -2074,35 +2072,6 @@ ShowUsage(const char *title) pfree(str.data); } -#ifdef NOT_USED -static int -assertEnable(int val) -{ - assert_enabled = val; - return val; -} - -#ifdef ASSERT_CHECKING_TEST -int -assertTest(int val) -{ - Assert(val == 0); - - if (assert_enabled) - { - /* val != 0 should be trapped by previous Assert */ - elog(DEBUG3, "Assert test successful (val = %d)", val); - } - else - elog(DEBUG3, "Assert checking is disabled (val = %d)", val); - - return val; -} -#endif - -#endif - - /* ---------------------------------------------------------------- * CreateCommandTag * diff --git a/src/backend/utils/error/Makefile b/src/backend/utils/error/Makefile index 147f03c077..04d7103983 100644 --- a/src/backend/utils/error/Makefile +++ b/src/backend/utils/error/Makefile @@ -4,7 +4,7 @@ # Makefile for utils/error # # IDENTIFICATION -# $Header: /cvsroot/pgsql/src/backend/utils/error/Makefile,v 1.9 2000/08/31 16:10:48 petere Exp $ +# $Header: /cvsroot/pgsql/src/backend/utils/error/Makefile,v 1.10 2002/08/10 20:29:18 momjian Exp $ # #------------------------------------------------------------------------- @@ -12,7 +12,7 @@ subdir = src/backend/utils/error top_builddir = ../../../.. include $(top_builddir)/src/Makefile.global -OBJS = assert.o elog.o exc.o excabort.o excid.o format.o +OBJS = assert.o elog.o all: SUBSYS.o diff --git a/src/backend/utils/error/assert.c b/src/backend/utils/error/assert.c index eee458020d..81fe83c4b4 100644 --- a/src/backend/utils/error/assert.c +++ b/src/backend/utils/error/assert.c @@ -8,65 +8,44 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/error/assert.c,v 1.21 2002/06/20 20:29:39 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/error/assert.c,v 1.22 2002/08/10 20:29:18 momjian Exp $ * * NOTE - * This should eventually work with elog(), dlog(), etc. + * This should eventually work with elog() * *------------------------------------------------------------------------- */ #include "postgres.h" -#include #include -#include "utils/exc.h" - +/* + * ExceptionalCondition - Handles the failure of an Assert() + */ int ExceptionalCondition(char *conditionName, - Exception *exceptionP, - char *detail, + char *errorType, char *fileName, int lineNumber) { - ExcFileName = fileName; - ExcLineNumber = lineNumber; - if (!PointerIsValid(conditionName) || !PointerIsValid(fileName) - || !PointerIsValid(exceptionP)) + || !PointerIsValid(errorType)) { fprintf(stderr, "TRAP: ExceptionalCondition: bad arguments\n"); - - ExcAbort(exceptionP, - (ExcDetail) detail, - (ExcData) NULL, - (ExcMessage) NULL); } else { - fprintf(stderr, "TRAP: %s(\"%s:%s\", File: \"%s\", Line: %d)\n", - exceptionP->message, conditionName, - (detail == NULL ? "" : detail), + fprintf(stderr, "TRAP: %s(\"%s\", File: \"%s\", Line: %d)\n", + errorType, conditionName, fileName, lineNumber); } -#ifdef ABORT_ON_ASSERT - abort(); -#endif #ifdef SLEEP_ON_ASSERT sleep(1000000); #endif - /* - * XXX Depending on the Exception and tracing conditions, you will XXX - * want to stop here immediately and maybe dump core. XXX This may be - * especially true for Assert(), etc. - */ + abort(); - /* TraceDump(); dump the trace stack */ - - /* XXX FIXME: detail is lost */ - ExcRaise(exceptionP, (ExcDetail) 0, (ExcData) NULL, conditionName); return 0; } diff --git a/src/backend/utils/error/exc.c b/src/backend/utils/error/exc.c deleted file mode 100644 index 3dcf999154..0000000000 --- a/src/backend/utils/error/exc.c +++ /dev/null @@ -1,198 +0,0 @@ -/*------------------------------------------------------------------------- - * - * exc.c - * POSTGRES exception handling code. - * - * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group - * Portions Copyright (c) 1994, Regents of the University of California - * - * - * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/error/Attic/exc.c,v 1.39 2002/06/20 20:29:39 momjian Exp $ - * - * NOTE - * XXX this code needs improvement--check for state violations and - * XXX reset after handling an exception. - * XXX Probably should be merged with elog.c. - * - *------------------------------------------------------------------------- - */ -#include "postgres.h" - -#include - -#include "storage/ipc.h" -#include "utils/exc.h" - -extern int errno; - - -static void ExcUnCaught(Exception *excP, ExcDetail detail, ExcData data, - ExcMessage message); -static void ExcPrint(Exception *excP, ExcDetail detail, ExcData data, - ExcMessage message); - -/* - * Global Variables - */ -static bool ExceptionHandlingEnabled = false; - -char *ExcFileName = NULL; -Index ExcLineNumber = 0; - -ExcFrame *ExcCurFrameP = NULL; - -static ExcProc *ExcUnCaughtP = NULL; - -/* - * Exported Functions - */ - -/* - * EnableExceptionHandling - * Enables/disables the exception handling system. - * - * Note: - * This must be called before any exceptions occur. I.e., call this first! - * This routine will not return if an error is detected. - * This does not follow the usual Enable... protocol. - * This should be merged more closely with the error logging and tracing - * packages. - * - * Exceptions: - * none - */ -/* - * Excection handling should be supported by the language, thus there should - * be no need to explicitly enable exception processing. - * - * This function should probably not be called, ever. Currently it does - * almost nothing. If there is a need for this intialization and checking. - * then this function should be converted to the new-style Enable code and - * called by all the other module Enable functions. - */ -void -EnableExceptionHandling(bool on) -{ - if (on == ExceptionHandlingEnabled) - { - /* XXX add logging of failed state */ - proc_exit(255); - /* ExitPostgres(FatalExitStatus); */ - } - - if (on) - { /* initialize */ - ; - } - else - { /* cleanup */ - ExcFileName = NULL; - ExcLineNumber = 0; - ExcCurFrameP = NULL; - ExcUnCaughtP = NULL; - } - - ExceptionHandlingEnabled = on; -} - -static void -ExcPrint(Exception *excP, - ExcDetail detail, - ExcData data, - ExcMessage message) -{ - /* this buffer is only used if errno has a bogus value: */ - char errorstr_buf[32]; - const char *errorstr; - -#ifdef lint - data = data; -#endif - - /* Save error str before calling any function that might change errno */ - errorstr = strerror(errno); - - /* - * Some strerror()s return an empty string for out-of-range errno. - * This is ANSI C spec compliant, but not exactly useful. - */ - if (errorstr == NULL || *errorstr == '\0') - { - sprintf(errorstr_buf, "error %d", errno); - errorstr = errorstr_buf; - } - - fflush(stdout); /* In case stderr is buffered */ - - if (message != NULL) - fprintf(stderr, "%s", message); - else if (excP->message != NULL) - fprintf(stderr, "%s", excP->message); - else - fprintf(stderr, "UNNAMED EXCEPTION %p", excP); - - fprintf(stderr, " (%ld) [%s]\n", detail, errorstr); - - fflush(stderr); -} - -#ifdef NOT_USED -ExcProc * -ExcGetUnCaught(void) -{ - return ExcUnCaughtP; -} -#endif - -#ifdef NOT_USED -ExcProc * -ExcSetUnCaught(ExcProc *newP) -{ - ExcProc *oldP = ExcUnCaughtP; - - ExcUnCaughtP = newP; - - return oldP; -} -#endif - -static void -ExcUnCaught(Exception *excP, - ExcDetail detail, - ExcData data, - ExcMessage message) -{ - ExcPrint(excP, detail, data, message); - - ExcAbort(excP, detail, data, message); -} - -void -ExcRaise(Exception *excP, - ExcDetail detail, - ExcData data, - ExcMessage message) -{ - ExcFrame *efp; - - efp = ExcCurFrameP; - if (efp == NULL) - { - if (ExcUnCaughtP != NULL) - (*ExcUnCaughtP) (excP, detail, data, message); - - ExcUnCaught(excP, detail, data, message); - } - else - { - efp->id = excP; - efp->detail = detail; - efp->data = data; - efp->message = message; - - ExcCurFrameP = efp->link; - - siglongjmp(efp->context, 1); - } -} diff --git a/src/backend/utils/error/excabort.c b/src/backend/utils/error/excabort.c deleted file mode 100644 index 00fb075b26..0000000000 --- a/src/backend/utils/error/excabort.c +++ /dev/null @@ -1,28 +0,0 @@ -/*------------------------------------------------------------------------- - * - * excabort.c - * Default exception abort code. - * - * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group - * Portions Copyright (c) 1994, Regents of the University of California - * - * - * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/error/Attic/excabort.c,v 1.10 2002/06/20 20:29:39 momjian Exp $ - * - *------------------------------------------------------------------------- - */ - -#include "postgres.h" - -#include "utils/exc.h" - -void -ExcAbort(const Exception *excP, - ExcDetail detail, - ExcData data, - ExcMessage message) -{ - /* dump core */ - abort(); -} diff --git a/src/backend/utils/error/excid.c b/src/backend/utils/error/excid.c deleted file mode 100644 index b32080a5fd..0000000000 --- a/src/backend/utils/error/excid.c +++ /dev/null @@ -1,54 +0,0 @@ -/*------------------------------------------------------------------------- - * - * excid.c - * POSTGRES known exception identifier code. - * - * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group - * Portions Copyright (c) 1994, Regents of the University of California - * - * - * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/error/Attic/excid.c,v 1.11 2002/06/20 20:29:39 momjian Exp $ - * - *------------------------------------------------------------------------- - */ - -#include "postgres.h" - -/***************************************************************************** - * Generic Recoverable Exceptions * - *****************************************************************************/ - - -/* - * FailedAssertion - * Indicates an Assert(...) failed. - */ -Exception FailedAssertion = {"Failed Assertion"}; - -/* - * BadState - * Indicates a function call request is inconsistent with module state. - */ -Exception BadState = {"Bad State for Function Call"}; - -/* - * BadArg - * Indicates a function call argument or arguments is out-of-bounds. - */ -Exception BadArg = {"Bad Argument to Function Call"}; - -/***************************************************************************** - * Specific Recoverable Exceptions * - *****************************************************************************/ - -/* - * Unimplemented - * Indicates a function call request requires unimplemented code. - */ -Exception Unimplemented = {"Unimplemented Functionality"}; - -Exception CatalogFailure = {"Catalog failure"}; /* XXX inconsistent */ -Exception InternalError = {"Internal Error"}; /* XXX inconsistent */ -Exception SemanticError = {"Semantic Error"}; /* XXX inconsistent */ -Exception SystemError = {"System Error"}; /* XXX inconsistent */ diff --git a/src/backend/utils/mmgr/mcxt.c b/src/backend/utils/mmgr/mcxt.c index 01669b62e2..709bd74d32 100644 --- a/src/backend/utils/mmgr/mcxt.c +++ b/src/backend/utils/mmgr/mcxt.c @@ -14,7 +14,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/utils/mmgr/mcxt.c,v 1.30 2002/06/20 20:29:40 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/utils/mmgr/mcxt.c,v 1.31 2002/08/10 20:29:18 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -22,7 +22,6 @@ #include "postgres.h" #include "nodes/memnodes.h" -#include "utils/excid.h" #include "utils/memutils.h" diff --git a/src/include/postgres.h b/src/include/postgres.h index b95dc7c92f..c509daf061 100644 --- a/src/include/postgres.h +++ b/src/include/postgres.h @@ -10,7 +10,7 @@ * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group * Portions Copyright (c) 1995, Regents of the University of California * - * $Id: postgres.h,v 1.58 2002/06/20 20:29:42 momjian Exp $ + * $Id: postgres.h,v 1.59 2002/08/10 20:29:18 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -470,17 +470,6 @@ extern Datum Float8GetDatum(float8 X); * ---------------------------------------------------------------- */ -typedef char *ExcMessage; - -typedef struct Exception -{ - ExcMessage message; -} Exception; - -extern DLLIMPORT Exception FailedAssertion; -extern DLLIMPORT Exception BadArg; -extern DLLIMPORT Exception BadState; - extern DLLIMPORT bool assert_enabled; /* @@ -495,25 +484,24 @@ extern DLLIMPORT bool assert_enabled; * Generates an exception if the given condition is true. * */ -#define Trap(condition, exception) \ +#define Trap(condition, errorType) \ do { \ if ((assert_enabled) && (condition)) \ - ExceptionalCondition(CppAsString(condition), &(exception), \ - (char*)NULL, __FILE__, __LINE__); \ + ExceptionalCondition(CppAsString(condition), (errorType), \ + __FILE__, __LINE__); \ } while (0) /* * TrapMacro is the same as Trap but it's intended for use in macros: * - * #define foo(x) (AssertM(x != 0) && bar(x)) + * #define foo(x) (AssertMacro(x != 0) && bar(x)) * * Isn't CPP fun? */ -#define TrapMacro(condition, exception) \ +#define TrapMacro(condition, errorType) \ ((bool) ((! assert_enabled) || ! (condition) || \ - (ExceptionalCondition(CppAsString(condition), \ - &(exception), \ - (char*) NULL, __FILE__, __LINE__)))) + (ExceptionalCondition(CppAsString(condition), (errorType), \ + __FILE__, __LINE__)))) #ifndef USE_ASSERT_CHECKING #define Assert(condition) @@ -523,73 +511,21 @@ extern DLLIMPORT bool assert_enabled; #define assert_enabled 0 #else #define Assert(condition) \ - Trap(!(condition), FailedAssertion) + Trap(!(condition), "FailedAssertion") #define AssertMacro(condition) \ - ((void) TrapMacro(!(condition), FailedAssertion)) + ((void) TrapMacro(!(condition), "FailedAssertion")) #define AssertArg(condition) \ - Trap(!(condition), BadArg) + Trap(!(condition), "BadArgument") #define AssertState(condition) \ - Trap(!(condition), BadState) + Trap(!(condition), "BadState") #endif /* USE_ASSERT_CHECKING */ -/* - * LogTrap - * Generates an exception with a message if the given condition is true. - * - */ -#define LogTrap(condition, exception, printArgs) \ - do { \ - if ((assert_enabled) && (condition)) \ - ExceptionalCondition(CppAsString(condition), &(exception), \ - vararg_format printArgs, __FILE__, __LINE__); \ - } while (0) - -/* - * LogTrapMacro is the same as LogTrap but it's intended for use in macros: - * - * #define foo(x) (LogAssertMacro(x != 0, "yow!") && bar(x)) - */ -#define LogTrapMacro(condition, exception, printArgs) \ - ((bool) ((! assert_enabled) || ! (condition) || \ - (ExceptionalCondition(CppAsString(condition), \ - &(exception), \ - vararg_format printArgs, __FILE__, __LINE__)))) - -extern int ExceptionalCondition(char *conditionName, - Exception *exceptionP, char *details, +extern int ExceptionalCondition(char *conditionName, char *errorType, char *fileName, int lineNumber); -extern char * -vararg_format(const char *fmt,...) -/* This lets gcc check the format string for consistency. */ -__attribute__((format(printf, 1, 2))); - -#ifndef USE_ASSERT_CHECKING -#define LogAssert(condition, printArgs) -#define LogAssertMacro(condition, printArgs) true -#define LogAssertArg(condition, printArgs) -#define LogAssertState(condition, printArgs) -#else -#define LogAssert(condition, printArgs) \ - LogTrap(!(condition), FailedAssertion, printArgs) - -#define LogAssertMacro(condition, printArgs) \ - LogTrapMacro(!(condition), FailedAssertion, printArgs) - -#define LogAssertArg(condition, printArgs) \ - LogTrap(!(condition), BadArg, printArgs) - -#define LogAssertState(condition, printArgs) \ - LogTrap(!(condition), BadState, printArgs) - -#ifdef ASSERT_CHECKING_TEST -extern int assertTest(int val); -#endif -#endif /* USE_ASSERT_CHECKING */ - /* ---------------------------------------------------------------- * Section 4: genbki macros used by catalog/pg_xxx.h files * ----------------------------------------------------------------