Alvaro Herrera wrote: > Now, the obvious big problem I have with this patch is that I have to > pass plpgsql's locale path to bindtextdomain(), but I'm not seeing any > decent way to do that ... ideas?
I think the best way to do this is to stash the library path being loaded where _PG_init can find it. It is a bit ugly but not beyond belief. Would anybody object to this? -- Alvaro Herrera http://www.CommandPrompt.com/ The PostgreSQL Company - Command Prompt, Inc.
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 20:20:19 -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 *domain, const char *funcname) { ErrorData *edata; bool output_to_server; *************** errstart(int elevel, const char *filenam *** 290,295 **** --- 290,296 ---- edata->filename = filename; edata->lineno = lineno; edata->funcname = funcname; + edata->domain = domain; /* 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); \ --- 612,618 ---- 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 */ /* --- 983,989 ---- */ errordata_stack_depth--; errno = edata->saved_errno; ! if (!errstart(elevel, edata->filename, edata->lineno, NULL, edata->funcname)) return; /* nothing to do */ /* Index: src/backend/utils/fmgr/dfmgr.c =================================================================== RCS file: /home/alvherre/Code/cvs/pgsql/src/backend/utils/fmgr/dfmgr.c,v retrieving revision 1.97 diff -c -p -r1.97 dfmgr.c *** src/backend/utils/fmgr/dfmgr.c 3 Sep 2008 22:34:50 -0000 1.97 --- src/backend/utils/fmgr/dfmgr.c 8 Oct 2008 22:01:37 -0000 *************** static DynamicFileList *file_tail = NULL *** 71,76 **** --- 71,80 ---- char *Dynamic_library_path; + /* for _PG_init: the path of the library being loaded */ + char *loading_library_path; + + static void *internal_load_library(const char *libname); static void incompatible_module_error(const char *libname, const Pg_magic_struct *module_magic_data); *************** internal_load_library(const char *libnam *** 276,281 **** --- 280,288 ---- errhint("Extension libraries are required to use the PG_MODULE_MAGIC macro."))); } + /* make the library path available to _PG_init */ + loading_library_path = file_scanner->filename; + /* * If the library has a _PG_init() function, call it. */ *************** internal_load_library(const char *libnam *** 283,288 **** --- 290,297 ---- if (PG_init) (*PG_init) (); + loading_library_path = NULL; + /* OK to link it into list */ if (file_list == NULL) file_list = file_scanner; Index: src/include/miscadmin.h =================================================================== RCS file: /home/alvherre/Code/cvs/pgsql/src/include/miscadmin.h,v retrieving revision 1.202 diff -c -p -r1.202 miscadmin.h *** src/include/miscadmin.h 23 Apr 2008 13:44:59 -0000 1.202 --- src/include/miscadmin.h 8 Oct 2008 21:54:32 -0000 *************** extern void process_local_preload_librar *** 334,337 **** --- 334,340 ---- extern bool BackupInProgress(void); extern void CancelBackup(void); + /* utils/dfmgr.c */ + extern char *loading_library_path; + #endif /* MISCADMIN_H */ 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 21:57:31 -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,113 ---- * 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. Modules can + * either use ereport_domain() directly, or preferrably they can just override + * the ereport() macro definition with their own domain. *---------- */ ! #define ereport_domain(elevel, domain, rest) \ ! (errstart(elevel, __FILE__, __LINE__, domain, PG_FUNCNAME_MACRO) ? \ (errfinish rest) : (void) 0) + #define ereport(level, rest) \ + ereport_domain(level, "postgres", rest) + extern bool errstart(int elevel, const char *filename, int lineno, ! const char *domain, const char *funcname); extern void errfinish(int dummy,...); extern int errcode(int sqlerrcode); *************** typedef struct ErrorData *** 270,275 **** --- 278,284 ---- int lineno; /* __LINE__ of ereport() call */ const char *funcname; /* __func__ of ereport() call */ int sqlerrcode; /* encoded ERRSTATE */ + const char *domain; /* message domain, NULL if default */ char *message; /* primary error message */ char *detail; /* detail error message */ char *detail_log; /* detail error message for server log only */ Index: src/pl/plpgsql/src/gram.y =================================================================== RCS file: /home/alvherre/Code/cvs/pgsql/src/pl/plpgsql/src/gram.y,v retrieving revision 1.115 diff -c -p -r1.115 gram.y *** src/pl/plpgsql/src/gram.y 10 Sep 2008 01:09:45 -0000 1.115 --- src/pl/plpgsql/src/gram.y 8 Oct 2008 22:23:58 -0000 *************** *** 18,23 **** --- 18,25 ---- #include "parser/parser.h" + #include "plpgsql_i18n.h" + /* * Bison doesn't allocate anything that needs to live across parser calls, Index: src/pl/plpgsql/src/pl_comp.c =================================================================== RCS file: /home/alvherre/Code/cvs/pgsql/src/pl/plpgsql/src/pl_comp.c,v retrieving revision 1.130 diff -c -p -r1.130 pl_comp.c *** src/pl/plpgsql/src/pl_comp.c 1 Sep 2008 20:42:46 -0000 1.130 --- src/pl/plpgsql/src/pl_comp.c 8 Oct 2008 18:14:31 -0000 *************** *** 37,42 **** --- 37,43 ---- #include "utils/memutils.h" #include "utils/syscache.h" + #include "plpgsql_i18n.h" /* ---------- * Our own local and global variables Index: src/pl/plpgsql/src/pl_exec.c =================================================================== RCS file: /home/alvherre/Code/cvs/pgsql/src/pl/plpgsql/src/pl_exec.c,v retrieving revision 1.221 diff -c -p -r1.221 pl_exec.c *** src/pl/plpgsql/src/pl_exec.c 24 Sep 2008 14:40:00 -0000 1.221 --- src/pl/plpgsql/src/pl_exec.c 8 Oct 2008 17:44:31 -0000 *************** *** 32,37 **** --- 32,38 ---- #include "utils/snapmgr.h" #include "utils/typcache.h" + #include "plpgsql_i18n.h" /* must be last */ static const char *const raise_skip_msg = "RAISE"; Index: src/pl/plpgsql/src/pl_funcs.c =================================================================== RCS file: /home/alvherre/Code/cvs/pgsql/src/pl/plpgsql/src/pl_funcs.c,v retrieving revision 1.73 diff -c -p -r1.73 pl_funcs.c *** src/pl/plpgsql/src/pl_funcs.c 29 Aug 2008 13:02:33 -0000 1.73 --- src/pl/plpgsql/src/pl_funcs.c 8 Oct 2008 22:22:56 -0000 *************** *** 19,24 **** --- 19,25 ---- #include "parser/scansup.h" + #include "plpgsql_i18n.h" /* ---------- * Local variables for the namestack handling 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 21:56:16 -0000 *************** _PG_init(void) *** 42,47 **** --- 42,57 ---- if (inited) return; + #ifdef ENABLE_NLS + if (loading_library_path) + { + char locale_path[MAXPGPATH]; + + get_locale_path(loading_library_path, locale_path); + bindtextdomain("plpgsql", locale_path); + } + #endif + plpgsql_HashTableInit(); RegisterXactCallback(plpgsql_xact_cb, NULL); RegisterSubXactCallback(plpgsql_subxact_cb, NULL);
-- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers