@@ -683,13 +683,13 @@ errcode_for_socket_access(void)
683
683
* to the edata field because the buffer might be considerably larger than
684
684
* really necessary.
685
685
*/
686
- #define EVALUATE_MESSAGE (targetfield , appendval , translateit ) \
686
+ #define EVALUATE_MESSAGE (domain , targetfield , appendval , translateit ) \
687
687
{ \
688
688
char *fmtbuf; \
689
689
StringInfoData buf; \
690
690
/* Internationalize the error format string */ \
691
691
if (translateit && !in_error_recursion_trouble ()) \
692
- fmt = dgettext (edata -> domain , fmt ); \
692
+ fmt = dgettext (( domain ) , fmt ); \
693
693
/* Expand %m in format string */ \
694
694
fmtbuf = expand_fmt_string (fmt , edata ); \
695
695
initStringInfo (& buf ); \
@@ -723,14 +723,14 @@ errcode_for_socket_access(void)
723
723
* must be declared like "const char *fmt_singular, const char *fmt_plural,
724
724
* unsigned long n, ...". Translation is assumed always wanted.
725
725
*/
726
- #define EVALUATE_MESSAGE_PLURAL (targetfield , appendval ) \
726
+ #define EVALUATE_MESSAGE_PLURAL (domain , targetfield , appendval ) \
727
727
{ \
728
728
const char *fmt; \
729
729
char *fmtbuf; \
730
730
StringInfoData buf; \
731
731
/* Internationalize the error format string */ \
732
732
if (!in_error_recursion_trouble ()) \
733
- fmt = dngettext (edata -> domain , fmt_singular , fmt_plural , n ); \
733
+ fmt = dngettext (( domain ) , fmt_singular , fmt_plural , n ); \
734
734
else \
735
735
fmt = (n == 1 ? fmt_singular : fmt_plural ); \
736
736
/* Expand %m in format string */ \
@@ -781,7 +781,7 @@ errmsg(const char *fmt,...)
781
781
CHECK_STACK_DEPTH ();
782
782
oldcontext = MemoryContextSwitchTo (ErrorContext );
783
783
784
- EVALUATE_MESSAGE (message , false, true);
784
+ EVALUATE_MESSAGE (edata -> domain , message , false, true);
785
785
786
786
MemoryContextSwitchTo (oldcontext );
787
787
recursion_depth -- ;
@@ -810,7 +810,7 @@ errmsg_internal(const char *fmt,...)
810
810
CHECK_STACK_DEPTH ();
811
811
oldcontext = MemoryContextSwitchTo (ErrorContext );
812
812
813
- EVALUATE_MESSAGE (message , false, false);
813
+ EVALUATE_MESSAGE (edata -> domain , message , false, false);
814
814
815
815
MemoryContextSwitchTo (oldcontext );
816
816
recursion_depth -- ;
@@ -833,7 +833,7 @@ errmsg_plural(const char *fmt_singular, const char *fmt_plural,
833
833
CHECK_STACK_DEPTH ();
834
834
oldcontext = MemoryContextSwitchTo (ErrorContext );
835
835
836
- EVALUATE_MESSAGE_PLURAL (message , false);
836
+ EVALUATE_MESSAGE_PLURAL (edata -> domain , message , false);
837
837
838
838
MemoryContextSwitchTo (oldcontext );
839
839
recursion_depth -- ;
@@ -854,7 +854,7 @@ errdetail(const char *fmt,...)
854
854
CHECK_STACK_DEPTH ();
855
855
oldcontext = MemoryContextSwitchTo (ErrorContext );
856
856
857
- EVALUATE_MESSAGE (detail , false, true);
857
+ EVALUATE_MESSAGE (edata -> domain , detail , false, true);
858
858
859
859
MemoryContextSwitchTo (oldcontext );
860
860
recursion_depth -- ;
@@ -881,7 +881,7 @@ errdetail_internal(const char *fmt,...)
881
881
CHECK_STACK_DEPTH ();
882
882
oldcontext = MemoryContextSwitchTo (ErrorContext );
883
883
884
- EVALUATE_MESSAGE (detail , false, false);
884
+ EVALUATE_MESSAGE (edata -> domain , detail , false, false);
885
885
886
886
MemoryContextSwitchTo (oldcontext );
887
887
recursion_depth -- ;
@@ -902,7 +902,7 @@ errdetail_log(const char *fmt,...)
902
902
CHECK_STACK_DEPTH ();
903
903
oldcontext = MemoryContextSwitchTo (ErrorContext );
904
904
905
- EVALUATE_MESSAGE (detail_log , false, true);
905
+ EVALUATE_MESSAGE (edata -> domain , detail_log , false, true);
906
906
907
907
MemoryContextSwitchTo (oldcontext );
908
908
recursion_depth -- ;
@@ -925,7 +925,7 @@ errdetail_plural(const char *fmt_singular, const char *fmt_plural,
925
925
CHECK_STACK_DEPTH ();
926
926
oldcontext = MemoryContextSwitchTo (ErrorContext );
927
927
928
- EVALUATE_MESSAGE_PLURAL (detail , false);
928
+ EVALUATE_MESSAGE_PLURAL (edata -> domain , detail , false);
929
929
930
930
MemoryContextSwitchTo (oldcontext );
931
931
recursion_depth -- ;
@@ -946,7 +946,7 @@ errhint(const char *fmt,...)
946
946
CHECK_STACK_DEPTH ();
947
947
oldcontext = MemoryContextSwitchTo (ErrorContext );
948
948
949
- EVALUATE_MESSAGE (hint , false, true);
949
+ EVALUATE_MESSAGE (edata -> domain , hint , false, true);
950
950
951
951
MemoryContextSwitchTo (oldcontext );
952
952
recursion_depth -- ;
@@ -955,14 +955,14 @@ errhint(const char *fmt,...)
955
955
956
956
957
957
/*
958
- * errcontext --- add a context error message text to the current error
958
+ * errcontext_msg --- add a context error message text to the current error
959
959
*
960
960
* Unlike other cases, multiple calls are allowed to build up a stack of
961
961
* context information. We assume earlier calls represent more-closely-nested
962
962
* states.
963
963
*/
964
964
int
965
- errcontext (const char * fmt ,...)
965
+ errcontext_msg (const char * fmt ,...)
966
966
{
967
967
ErrorData * edata = & errordata [errordata_stack_depth ];
968
968
MemoryContext oldcontext ;
@@ -971,13 +971,35 @@ errcontext(const char *fmt,...)
971
971
CHECK_STACK_DEPTH ();
972
972
oldcontext = MemoryContextSwitchTo (ErrorContext );
973
973
974
- EVALUATE_MESSAGE (context , true, true);
974
+ EVALUATE_MESSAGE (edata -> context_domain , context , true, true);
975
975
976
976
MemoryContextSwitchTo (oldcontext );
977
977
recursion_depth -- ;
978
978
return 0 ; /* return value does not matter */
979
979
}
980
980
981
+ /*
982
+ * set_errcontext_domain --- set message domain to be used by errcontext()
983
+ *
984
+ * errcontext_msg() can be called from a different module than the original
985
+ * ereport(), so we cannot use the message domain passed in errstart() to
986
+ * translate it. Instead, each errcontext_msg() call should be preceded by
987
+ * a set_errcontext_domain() call to specify the domain. This is usually
988
+ * done transparently by the errcontext() macro.
989
+ */
990
+ int
991
+ set_errcontext_domain (const char * domain )
992
+ {
993
+ ErrorData * edata = & errordata [errordata_stack_depth ];
994
+
995
+ /* we don't bother incrementing recursion_depth */
996
+ CHECK_STACK_DEPTH ();
997
+
998
+ edata -> context_domain = domain ;
999
+
1000
+ return 0 ; /* return value does not matter */
1001
+ }
1002
+
981
1003
982
1004
/*
983
1005
* errhidestmt --- optionally suppress STATEMENT: field of log entry
@@ -1201,7 +1223,7 @@ elog_finish(int elevel, const char *fmt,...)
1201
1223
recursion_depth ++ ;
1202
1224
oldcontext = MemoryContextSwitchTo (ErrorContext );
1203
1225
1204
- EVALUATE_MESSAGE (message , false, false);
1226
+ EVALUATE_MESSAGE (edata -> domain , message , false, false);
1205
1227
1206
1228
MemoryContextSwitchTo (oldcontext );
1207
1229
recursion_depth -- ;
@@ -1260,7 +1282,7 @@ format_elog_string(const char *fmt,...)
1260
1282
1261
1283
oldcontext = MemoryContextSwitchTo (ErrorContext );
1262
1284
1263
- EVALUATE_MESSAGE (message , false, true);
1285
+ EVALUATE_MESSAGE (edata -> domain , message , false, true);
1264
1286
1265
1287
MemoryContextSwitchTo (oldcontext );
1266
1288
0 commit comments