From 7ba7986fb4364e889a705c9973fefa138650091c Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Fri, 23 Mar 2018 10:31:10 -0400 Subject: [PATCH] Fix interaction of Perl and stdbool.h Revert the PL/Perl-specific change in 9a95a77d9d5d3003d2d67121f2731b6e5fc37336. We must not prevent Perl from using stdbool.h when it has been built to do so, even if it uses an incompatible size. Otherwise, we would be imposing our bool on Perl, which will lead to crashes because of the size mismatch. Instead, we undef bool after including the Perl headers, as we did previously, but now only if we are not using stdbool.h ourselves. Record that choice in c.h as USE_STDBOOL. This will also make it easier to apply that coding pattern elsewhere if necessary. --- src/include/c.h | 1 + src/pl/plperl/plperl.h | 18 +++++++++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/include/c.h b/src/include/c.h index 107f4f6bcd..95e9aeded9 100644 --- a/src/include/c.h +++ b/src/include/c.h @@ -268,6 +268,7 @@ #if defined(HAVE_STDBOOL_H) && SIZEOF_BOOL == 1 #include +#define USE_STDBOOL 1 #else #ifndef bool diff --git a/src/pl/plperl/plperl.h b/src/pl/plperl/plperl.h index a85aefea6c..05bdf7c115 100644 --- a/src/pl/plperl/plperl.h +++ b/src/pl/plperl/plperl.h @@ -50,11 +50,6 @@ #define __inline__ inline #endif -/* - * Prevent perl from redefining "bool". - */ -#define HAS_BOOL 1 - /* * Get the basic Perl API. We use PERL_NO_GET_CONTEXT mode so that our code @@ -96,6 +91,19 @@ #define NEED_sv_2pv_flags #include "ppport.h" +/* + * perl might have included stdbool.h. If we also did that earlier (see c.h), + * then that's fine. If not, we probably rejected it for some reason. In + * that case, undef bool and proceed with our own bool. (Note that stdbool.h + * makes bool a macro, but our own replacement is a typedef, so the undef + * makes ours visible again). + */ +#ifndef USE_STDBOOL +#ifdef bool +#undef bool +#endif +#endif + /* supply HeUTF8 if it's missing - ppport.h doesn't supply it, unfortunately */ #ifndef HeUTF8 #define HeUTF8(he) ((HeKLEN(he) == HEf_SVKEY) ? \