ugly-elog-fold.patch

text/x-patch

Patch

Format: unified
File+
src/backend/utils/error/elog.c 37 0
src/include/utils/elog.h 9 1
diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c
index e710f22..c1f3200 100644
--- a/src/backend/utils/error/elog.c
+++ b/src/backend/utils/error/elog.c
@@ -1151,6 +1151,43 @@ getinternalerrposition(void)
 	return edata->internalpos;
 }
 
+#if defined(HAVE__VA_ARGS) && defined(COMBINE_ELOG)
+void
+elog_all(const char *filename, int lineno, const char *funcname, int elevel, const char *fmt,...)
+{
+	elog_start(filename, lineno, funcname);
+	{
+		ErrorData  *edata = &errordata[errordata_stack_depth];
+		MemoryContext oldcontext;
+
+		CHECK_STACK_DEPTH();
+
+		/*
+		 * Do errstart() to see if we actually want to report the message.
+		 */
+		errordata_stack_depth--;
+		errno = edata->saved_errno;
+		if (!errstart(elevel, edata->filename, edata->lineno, edata->funcname, NULL))
+			return;					/* nothing to do */
+
+		/*
+		 * Format error message just like errmsg_internal().
+		 */
+		recursion_depth++;
+		oldcontext = MemoryContextSwitchTo(ErrorContext);
+
+		EVALUATE_MESSAGE(edata->domain, message, false, false);
+
+		MemoryContextSwitchTo(oldcontext);
+		recursion_depth--;
+
+		/*
+		 * And let errfinish() finish up.
+		 */
+		errfinish(0);
+	}
+}
+#endif
 
 /*
  * elog_start --- startup for old-style API
diff --git a/src/include/utils/elog.h b/src/include/utils/elog.h
index d6e1054..9af530f 100644
--- a/src/include/utils/elog.h
+++ b/src/include/utils/elog.h
@@ -216,7 +216,15 @@ extern int	getinternalerrposition(void);
  * generated.
  *----------
  */
-#ifdef HAVE__VA_ARGS
+#define COMBINE_ELOG
+#if defined(HAVE__VA_ARGS) && defined(COMBINE_ELOG)
+extern void elog_all(const char *filename, int lineno, const char *funcname, int elevel, const char *fmt,...)
+__attribute__((format(PG_PRINTF_ATTRIBUTE, 5, 6)));
+
+#define elog(elevel, ...)												\
+	elog_all(__FILE__, __LINE__, PG_FUNCNAME_MACRO, elevel, __VA_ARGS__), \
+		((elevel) >= ERROR ? pg_unreachable() : (void) 0)
+#elif defined(HAVE__VA_ARGS)
 #define elog(elevel, ...)												\
 	elog_start(__FILE__, __LINE__, PG_FUNCNAME_MACRO),					\
 		elog_finish(elevel, __VA_ARGS__),								\