Tom Lane wrote: > Another way, which would save some amount of string constant space, > is to have both elog_finish and the ereport macro pass NULL, and let > errstart insert the default: > > > + edata->domain = domain ? domain : "postgres"; > > Otherwise we'll have at least one copy of "postgres" per backend .o > file ...
Hmm, true. I think this means we need to redefine ereport(), not just TEXTDOMAIN, in each module (in fact it makes TEXTDOMAIN goes away as a symbol). Same number of lines on each module though, so it's not a considerable difference. -- Alvaro Herrera http://www.CommandPrompt.com/ PostgreSQL Replication, Consulting, Custom Development, 24x7 support
Index: src/backend/utils/error/elog.c =================================================================== RCS file: /home/alvherre/Code/cvs/pgsql/src/backend/utils/error/elog.c,v retrieving revision 1.206 diff -c -p -r1.206 elog.c *** src/backend/utils/error/elog.c 1 Sep 2008 20:42:45 -0000 1.206 --- src/backend/utils/error/elog.c 8 Oct 2008 23:44:09 -0000 *************** static void write_csvlog(ErrorData *edat *** 160,166 **** */ bool errstart(int elevel, const char *filename, int lineno, ! const char *funcname) { ErrorData *edata; bool output_to_server; --- 160,166 ---- */ bool errstart(int elevel, const char *filename, int lineno, ! const char *funcname, const char *domain) { ErrorData *edata; bool output_to_server; *************** errstart(int elevel, const char *filenam *** 290,295 **** --- 290,297 ---- edata->filename = filename; edata->lineno = lineno; edata->funcname = funcname; + /* the default text domain is the backend's */ + edata->domain = domain ? domain : "postgres"; /* Select default errcode based on elevel */ if (elevel >= ERROR) edata->sqlerrcode = ERRCODE_INTERNAL_ERROR; *************** errcode_for_socket_access(void) *** 611,617 **** char *fmtbuf; \ StringInfoData buf; \ /* Internationalize the error format string */ \ ! fmt = _(fmt); \ /* Expand %m in format string */ \ fmtbuf = expand_fmt_string(fmt, edata); \ initStringInfo(&buf); \ --- 613,619 ---- char *fmtbuf; \ StringInfoData buf; \ /* Internationalize the error format string */ \ ! fmt = dgettext(edata->domain, fmt); \ /* Expand %m in format string */ \ fmtbuf = expand_fmt_string(fmt, edata); \ initStringInfo(&buf); \ *************** elog_finish(int elevel, const char *fmt, *** 982,988 **** */ errordata_stack_depth--; errno = edata->saved_errno; ! if (!errstart(elevel, edata->filename, edata->lineno, edata->funcname)) return; /* nothing to do */ /* --- 984,990 ---- */ errordata_stack_depth--; errno = edata->saved_errno; ! if (!errstart(elevel, edata->filename, edata->lineno, edata->funcname, NULL)) return; /* nothing to do */ /* Index: src/include/utils/elog.h =================================================================== RCS file: /home/alvherre/Code/cvs/pgsql/src/include/utils/elog.h,v retrieving revision 1.94 diff -c -p -r1.94 elog.h *** src/include/utils/elog.h 1 Sep 2008 20:42:45 -0000 1.94 --- src/include/utils/elog.h 8 Oct 2008 23:47:06 -0000 *************** *** 92,105 **** * ERRCODE_INTERNAL_ERROR if elevel is ERROR or more, ERRCODE_WARNING * if elevel is WARNING, or ERRCODE_SUCCESSFUL_COMPLETION if elevel is * NOTICE or below. *---------- */ ! #define ereport(elevel, rest) \ ! (errstart(elevel, __FILE__, __LINE__, PG_FUNCNAME_MACRO) ? \ (errfinish rest) : (void) 0) extern bool errstart(int elevel, const char *filename, int lineno, ! const char *funcname); extern void errfinish(int dummy,...); extern int errcode(int sqlerrcode); --- 92,115 ---- * ERRCODE_INTERNAL_ERROR if elevel is ERROR or more, ERRCODE_WARNING * if elevel is WARNING, or ERRCODE_SUCCESSFUL_COMPLETION if elevel is * NOTICE or below. + * + * ereport_domain() allows a message domain to be specified, for modules that + * wish to use a different message catalog from the backend's. To avoid having + * one copy of the default text domain per .o file, we define ereport() with a + * NULL domain here and have errstart insert the default text domain. Modules + * can either use ereport_domain() directly, or preferrably they can override + * the ereport() macro to pass their own text domain. *---------- */ ! #define ereport_domain(elevel, domain, rest) \ ! (errstart(elevel, __FILE__, __LINE__, PG_FUNCNAME_MACRO, domain) ? \ (errfinish rest) : (void) 0) + #define ereport(level, rest) \ + ereport_domain(level, NULL, rest) + extern bool errstart(int elevel, const char *filename, int lineno, ! const char *funcname, const char *domain); extern void errfinish(int dummy,...); extern int errcode(int sqlerrcode); *************** typedef struct ErrorData *** 269,274 **** --- 279,285 ---- const char *filename; /* __FILE__ of ereport() call */ int lineno; /* __LINE__ of ereport() call */ const char *funcname; /* __func__ of ereport() call */ + const char *domain; /* message domain, NULL if default */ int sqlerrcode; /* encoded ERRSTATE */ char *message; /* primary error message */ char *detail; /* detail error message */ Index: src/pl/plpgsql/src/pl_handler.c =================================================================== RCS file: /home/alvherre/Code/cvs/pgsql/src/pl/plpgsql/src/pl_handler.c,v retrieving revision 1.40 diff -c -p -r1.40 pl_handler.c *** src/pl/plpgsql/src/pl_handler.c 29 Aug 2008 13:02:33 -0000 1.40 --- src/pl/plpgsql/src/pl_handler.c 8 Oct 2008 23:49:16 -0000 *************** _PG_init(void) *** 42,47 **** --- 42,57 ---- if (inited) return; + #ifdef ENABLE_NLS + if (my_exec_path[0] != '\0') + { + char locale_path[MAXPGPATH]; + + get_locale_path(my_exec_path, locale_path); + bindtextdomain("plpgsql", locale_path); + } + #endif + plpgsql_HashTableInit(); RegisterXactCallback(plpgsql_xact_cb, NULL); RegisterSubXactCallback(plpgsql_subxact_cb, NULL); Index: src/pl/plpgsql/src/plpgsql.h =================================================================== RCS file: /home/alvherre/Code/cvs/pgsql/src/pl/plpgsql/src/plpgsql.h,v retrieving revision 1.100 diff -c -p -r1.100 plpgsql.h *** src/pl/plpgsql/src/plpgsql.h 15 May 2008 22:39:49 -0000 1.100 --- src/pl/plpgsql/src/plpgsql.h 8 Oct 2008 23:49:17 -0000 *************** *** 28,33 **** --- 28,38 ---- * Definitions **********************************************************************/ + /* redefine ereport() with our text domain */ + #undef ereport + #define ereport(level, rest) \ + ereport_domain(level, "plpgsql", rest) + /* ---------- * Compiler's namestack item types * ----------
-- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers