diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2019-06-02 12:23:39 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2019-06-02 12:23:39 -0400 |
commit | 032627ee7837f0baa539df7247e003dbaded2c90 (patch) | |
tree | 94b4452d11d66927cea679ce97d02cc425261a3f /src | |
parent | 135063e6f6ee61c7243801e9f4d702921ed53e06 (diff) | |
download | postgresql-032627ee7837f0baa539df7247e003dbaded2c90.tar.gz postgresql-032627ee7837f0baa539df7247e003dbaded2c90.zip |
Clean up PL/Perl's handling of the _() macro.
Perl likes to redefine the _() macro:
#ifdef CAN_PROTOTYPE
#define _(args) args
#else ...
There was lots not to like about the way we dealt with this before:
1. Instead of taking care of the conflict centrally in plperl.h, we
expected every one of its ever-growing number of includers to do so.
This is duplicative and error-prone in itself, plus it means that
plperl.h fails to meet the expectation of being compilable standalone,
resulting in macro-redefinition warnings in cpluspluscheck.
2. We left _() with its Perl definition, meaning that if someone tried
to use it in any Perl-related extension, it would silently fail to
provide run-time translation. I don't see any live bugs of this ilk,
but it's clearly a hard-to-notice bug waiting to happen.
So fix that by centralizing the cleanup logic, making it match what
we're already doing for other macro conflicts with Perl. Since we only
expect plperl.h to be included by extensions not core code, we should
redefine _() as dgettext() not gettext().
Diffstat (limited to 'src')
-rw-r--r-- | src/pl/plperl/SPI.xs | 3 | ||||
-rw-r--r-- | src/pl/plperl/Util.xs | 4 | ||||
-rw-r--r-- | src/pl/plperl/plperl.c | 3 | ||||
-rw-r--r-- | src/pl/plperl/plperl.h | 15 |
4 files changed, 16 insertions, 9 deletions
diff --git a/src/pl/plperl/SPI.xs b/src/pl/plperl/SPI.xs index b98c547e8be..b2db3bd6949 100644 --- a/src/pl/plperl/SPI.xs +++ b/src/pl/plperl/SPI.xs @@ -10,9 +10,6 @@ /* this must be first: */ #include "postgres.h" -/* Defined by Perl */ -#undef _ - /* perl stuff */ #define PG_NEED_PERL_XSUB_H #include "plperl.h" diff --git a/src/pl/plperl/Util.xs b/src/pl/plperl/Util.xs index 686513d2e8d..47eba594155 100644 --- a/src/pl/plperl/Util.xs +++ b/src/pl/plperl/Util.xs @@ -12,13 +12,11 @@ /* this must be first: */ #include "postgres.h" + #include "fmgr.h" #include "utils/builtins.h" #include "utils/bytea.h" /* for byteain & byteaout */ -/* Defined by Perl */ -#undef _ - /* perl stuff */ #define PG_NEED_PERL_XSUB_H #include "plperl.h" diff --git a/src/pl/plperl/plperl.c b/src/pl/plperl/plperl.c index 5cb3a447291..2db13d30308 100644 --- a/src/pl/plperl/plperl.c +++ b/src/pl/plperl/plperl.c @@ -7,9 +7,6 @@ #include "postgres.h" -/* Defined by Perl */ -#undef _ - /* system stuff */ #include <ctype.h> #include <fcntl.h> diff --git a/src/pl/plperl/plperl.h b/src/pl/plperl/plperl.h index 09a77dc0b7b..e94a4c345bd 100644 --- a/src/pl/plperl/plperl.h +++ b/src/pl/plperl/plperl.h @@ -39,6 +39,11 @@ #undef printf /* + * Perl scribbles on the "_" macro too. + */ +#undef _ + +/* * ActivePerl 5.18 and later are MinGW-built, and their headers use GCC's * __inline__. Translate to something MSVC recognizes. Also, perl.h sometimes * defines isnan, so undefine it here and put back the definition later if @@ -140,6 +145,16 @@ #define vprintf pg_vprintf #define printf(...) pg_printf(__VA_ARGS__) +/* + * Put back "_" too; but rather than making it just gettext() as the core + * code does, make it dgettext() so that the right things will happen in + * loadable modules (if they've set up TEXTDOMAIN correctly). Note that + * we can't just set TEXTDOMAIN here, because this file is used by more + * extensions than just PL/Perl itself. + */ +#undef _ +#define _(x) dgettext(TEXTDOMAIN, x) + /* put back the definition of isnan if needed */ #ifdef _MSC_VER #ifndef isnan |