Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iSohE-0007s5-Uf for pgsql-hackers@arkaria.postgresql.org; Thu, 07 Nov 2019 20:48:01 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iSohD-0005GG-E4 for pgsql-hackers@arkaria.postgresql.org; Thu, 07 Nov 2019 20:47:59 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iSohC-0005G9-Tt for pgsql-hackers@lists.postgresql.org; Thu, 07 Nov 2019 20:47:59 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1iSoh9-0007V6-W5; Thu, 07 Nov 2019 20:47:57 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id xA7Klq7f021018; Thu, 7 Nov 2019 15:47:52 -0500 From: Tom Lane To: Andrew Gierth cc: Amit Kapila , PostgreSQL Hackers , Michael Meskes Subject: Re: define bool in pgtypeslib_extern.h In-reply-to: <32373.1572110364@sss.pgh.pa.us> References: <16583.1572010913@sss.pgh.pa.us> <18578.1572020755@sss.pgh.pa.us> <32373.1572110364@sss.pgh.pa.us> Comments: In-reply-to Tom Lane message dated "Sat, 26 Oct 2019 13:19:24 -0400" MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0" Content-ID: <21001.1573159635.0@sss.pgh.pa.us> Date: Thu, 07 Nov 2019 15:47:52 -0500 Message-ID: <21017.1573159672@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk ------- =_aaaaaaaaaa0 Content-Type: text/plain; charset="us-ascii" Content-ID: <21001.1573159635.1@sss.pgh.pa.us> I wrote: > I'm inclined to think that we need to make ecpglib.h's bool-related > definitions exactly match c.h, which will mean that it has to pull in > on most platforms, which will mean adding a control symbol > for that to ecpg_config.h. I do not think we should export > HAVE_STDBOOL_H and SIZEOF_BOOL there though; probably better to have > configure make the choice and export something named like PG_USE_STDBOOL. Here's a proposed patch that does it like that. I'm of two minds about whether to back-patch or not. This shouldn't really change anything except on platforms where sizeof(_Bool) isn't one. We have some reason to think that nobody is actually using ecpg on such platforms :-(, because if they were, they'd likely have complained about breakage. So maybe we should just put this in HEAD and be done. regards, tom lane ------- =_aaaaaaaaaa0 Content-Type: text/x-diff; name="make-ecpgs-bool-definition-match-c-h.patch"; charset="us-ascii" Content-ID: <21001.1573159635.2@sss.pgh.pa.us> Content-Description: make-ecpgs-bool-definition-match-c-h.patch Content-Transfer-Encoding: quoted-printable diff --git a/configure b/configure index 7312bd7..21ee193 100755 --- a/configure +++ b/configure @@ -14729,6 +14729,12 @@ _ACEOF = = = +if test "$ac_cv_header_stdbool_h" =3D yes -a "$ac_cv_sizeof_bool" =3D 1; = then + +$as_echo "#define PG_USE_STDBOOL 1" >>confdefs.h + +fi + = ## ## Functions, global variables diff --git a/configure.in b/configure.in index ea83d92..d128e59 100644 --- a/configure.in +++ b/configure.in @@ -1590,6 +1590,13 @@ AC_CHECK_SIZEOF([bool], [], #include #endif]) = +dnl We use if we have it and it declares type bool as having +dnl size 1. Otherwise, c.h will fall back to declaring bool as unsigned = char. +if test "$ac_cv_header_stdbool_h" =3D yes -a "$ac_cv_sizeof_bool" =3D 1; = then + AC_DEFINE([PG_USE_STDBOOL], 1, + [Define to 1 to use to define type bool.]) +fi + = ## ## Functions, global variables diff --git a/src/backend/utils/fmgr/dfmgr.c b/src/backend/utils/fmgr/dfmgr= .c index be68478..c8d2cef 100644 --- a/src/backend/utils/fmgr/dfmgr.c +++ b/src/backend/utils/fmgr/dfmgr.c @@ -23,7 +23,7 @@ * On macOS, insists on including . If we're not * using stdbool, undef bool to undo the damage. */ -#ifndef USE_STDBOOL +#ifndef PG_USE_STDBOOL #ifdef bool #undef bool #endif diff --git a/src/include/c.h b/src/include/c.h index c95acd3..5f800a3 100644 --- a/src/include/c.h +++ b/src/include/c.h @@ -288,20 +288,21 @@ * bool * Boolean value, either true or false. * - * Use stdbool.h if available and its bool has size 1. That's useful for + * We use stdbool.h if available and its bool has size 1. That's useful = for * better compiler and debugger output and for compatibility with third-p= arty * libraries. But PostgreSQL currently cannot deal with bool of other si= zes; * there are static assertions around the code to prevent that. * * For C++ compilers, we assume the compiler has a compatible built-in * definition of bool. + * + * Note: this stanza also appears in src/interfaces/ecpg/include/ecpglib.= h. */ = #ifndef __cplusplus = -#if defined(HAVE_STDBOOL_H) && SIZEOF_BOOL =3D=3D 1 +#ifdef PG_USE_STDBOOL #include -#define USE_STDBOOL 1 #else = #ifndef bool diff --git a/src/include/pg_config.h.in b/src/include/pg_config.h.in index 2bf5060..249161c 100644 --- a/src/include/pg_config.h.in +++ b/src/include/pg_config.h.in @@ -823,6 +823,9 @@ /* Define to best printf format archetype, usually gnu_printf if availabl= e. */ #undef PG_PRINTF_ATTRIBUTE = +/* Define to 1 to use to define type bool. */ +#undef PG_USE_STDBOOL + /* PostgreSQL version as a string */ #undef PG_VERSION = diff --git a/src/include/pg_config.h.win32 b/src/include/pg_config.h.win32 index 6b67fb0..6c98ef4 100644 --- a/src/include/pg_config.h.win32 +++ b/src/include/pg_config.h.win32 @@ -624,6 +624,9 @@ (--with-krb-srvnam=3DNAME) */ #define PG_KRB_SRVNAM "postgres" = +/* Define to 1 to use to define type bool. */ +#define PG_USE_STDBOOL 1 + /* A string containing the version number, platform, and C compiler */ #define PG_VERSION_STR "Uninitialized version string (win32)" = diff --git a/src/interfaces/ecpg/include/ecpg_config.h.in b/src/interfaces= /ecpg/include/ecpg_config.h.in index c185561..17e93c4 100644 --- a/src/interfaces/ecpg/include/ecpg_config.h.in +++ b/src/interfaces/ecpg/include/ecpg_config.h.in @@ -10,6 +10,9 @@ /* Define to 1 if `long long int' works and is 64 bits. */ #undef HAVE_LONG_LONG_INT_64 = +/* Define to 1 to use to define type bool. */ +#undef PG_USE_STDBOOL + /* Define to 1 to build client libraries as thread-safe code. * (--enable-thread-safety) */ #undef ENABLE_THREAD_SAFETY diff --git a/src/interfaces/ecpg/include/ecpglib.h b/src/interfaces/ecpg/i= nclude/ecpglib.h index de9c76a..5cb31e2 100644 --- a/src/interfaces/ecpg/include/ecpglib.h +++ b/src/interfaces/ecpg/include/ecpglib.h @@ -1,6 +1,6 @@ /* - * this is a small part of c.h since we don't want to leak all postgres - * definitions into ecpg programs + * Client-visible declarations for ecpglib + * * src/interfaces/ecpg/include/ecpglib.h */ = @@ -8,30 +8,36 @@ #define _ECPGLIB_H = #include "libpq-fe.h" +#include "ecpg_config.h" #include "ecpgtype.h" #include "sqlca.h" #include = +/* + * this is a small extract from c.h since we don't want to leak all postg= res + * definitions into ecpg programs; but we need to know what bool is. + */ #ifndef __cplusplus + +#ifdef PG_USE_STDBOOL +#include +#else + #ifndef bool -#define bool char -#endif /* ndef bool */ +typedef unsigned char bool; +#endif = #ifndef true #define true ((bool) 1) -#endif /* ndef true */ +#endif + #ifndef false #define false ((bool) 0) -#endif /* ndef false */ -#endif /* not C++ */ +#endif = -#ifndef TRUE -#define TRUE 1 -#endif /* TRUE */ +#endif +#endif /* not C++ */ = -#ifndef FALSE -#define FALSE 0 -#endif /* FALSE */ = #ifdef __cplusplus extern "C" diff --git a/src/pl/plperl/plperl.h b/src/pl/plperl/plperl.h index 3748158..7ae3c69 100644 --- a/src/pl/plperl/plperl.h +++ b/src/pl/plperl/plperl.h @@ -64,7 +64,7 @@ * warnings. If PostgreSQL does not but Perl does, we need to undefine b= ool * after we include the Perl headers; see below. */ -#ifdef USE_STDBOOL +#ifdef PG_USE_STDBOOL #define HAS_BOOL 1 #endif = @@ -175,7 +175,7 @@ * makes bool a macro, but our own replacement is a typedef, so the undef * makes ours visible again). */ -#ifndef USE_STDBOOL +#ifndef PG_USE_STDBOOL #ifdef bool #undef bool #endif diff --git a/src/tools/msvc/Solution.pm b/src/tools/msvc/Solution.pm index a695827..7f179f1 100644 --- a/src/tools/msvc/Solution.pm +++ b/src/tools/msvc/Solution.pm @@ -513,6 +513,7 @@ sub GenerateFiles print $o <