Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 1a86e6e

Browse files
committed
On further consideration, there's another problem here: the existing
elog() emulation code always calls errstart with ERROR error level. This means that a recursive error call triggered by elog would do MemoryContextReset(ErrorContext), whether or not this was actually appropriate. I'm surprised we haven't seen this in the field...
1 parent cefb4b1 commit 1a86e6e

File tree

2 files changed

+40
-8
lines changed

2 files changed

+40
-8
lines changed

src/backend/utils/error/elog.c

+37-6
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
*
4343
*
4444
* IDENTIFICATION
45-
* $PostgreSQL: pgsql/src/backend/utils/error/elog.c,v 1.149 2004/09/05 02:01:41 tgl Exp $
45+
* $PostgreSQL: pgsql/src/backend/utils/error/elog.c,v 1.150 2004/09/05 03:42:11 tgl Exp $
4646
*
4747
*-------------------------------------------------------------------------
4848
*/
@@ -862,10 +862,42 @@ getinternalerrposition(void)
862862

863863

864864
/*
865-
* elog_finish --- finish up for old-style API
865+
* elog_start --- startup for old-style API
866+
*
867+
* All that we do here is stash the hidden filename/lineno/funcname
868+
* arguments into a stack entry.
866869
*
867-
* The elog() macro already called errstart, but with ERROR rather than
868-
* the true elevel.
870+
* We need this to be separate from elog_finish because there's no other
871+
* portable way to deal with inserting extra arguments into the elog call.
872+
* (If macros with variable numbers of arguments were portable, it'd be
873+
* easy, but they aren't.)
874+
*/
875+
void
876+
elog_start(const char *filename, int lineno, const char *funcname)
877+
{
878+
ErrorData *edata;
879+
880+
if (++errordata_stack_depth >= ERRORDATA_STACK_SIZE)
881+
{
882+
/*
883+
* Wups, stack not big enough. We treat this as a PANIC condition
884+
* because it suggests an infinite loop of errors during error
885+
* recovery.
886+
*/
887+
errordata_stack_depth = -1; /* make room on stack */
888+
ereport(PANIC, (errmsg_internal("ERRORDATA_STACK_SIZE exceeded")));
889+
}
890+
891+
edata = &errordata[errordata_stack_depth];
892+
edata->filename = filename;
893+
edata->lineno = lineno;
894+
edata->funcname = funcname;
895+
/* errno is saved now so that error parameter eval can't change it */
896+
edata->saved_errno = errno;
897+
}
898+
899+
/*
900+
* elog_finish --- finish up for old-style API
869901
*/
870902
void
871903
elog_finish(int elevel, const char *fmt,...)
@@ -876,8 +908,7 @@ elog_finish(int elevel, const char *fmt,...)
876908
CHECK_STACK_DEPTH();
877909

878910
/*
879-
* We need to redo errstart() because the elog macro had to call it
880-
* with bogus elevel.
911+
* Do errstart() to see if we actually want to report the message.
881912
*/
882913
errordata_stack_depth--;
883914
errno = edata->saved_errno;

src/include/utils/elog.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2004, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/utils/elog.h,v 1.75 2004/08/29 05:06:58 momjian Exp $
10+
* $PostgreSQL: pgsql/src/include/utils/elog.h,v 1.76 2004/09/05 03:42:13 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -153,8 +153,9 @@ extern int getinternalerrposition(void);
153153
* elog(ERROR, "portal \"%s\" not found", stmt->portalname);
154154
*----------
155155
*/
156-
#define elog errstart(ERROR, __FILE__, __LINE__, PG_FUNCNAME_MACRO), elog_finish
156+
#define elog elog_start(__FILE__, __LINE__, PG_FUNCNAME_MACRO), elog_finish
157157

158+
extern void elog_start(const char *filename, int lineno, const char *funcname);
158159
extern void
159160
elog_finish(int elevel, const char *fmt,...)
160161
/* This extension allows gcc to check the format string for consistency with

0 commit comments

Comments
 (0)