Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7a0574b

Browse files
committed
Fix ecpglib.h to declare bool consistently with c.h.
This completes the task begun in commit1408d5d, to synchronizeECPG's exported definitions with the definition of bool used byc.h (and, therefore, the one actually in use in the ECPG library).On practically all modern platforms, ecpglib.h will now justinclude <stdbool.h>, which should surprise nobody anymore.That removes a header-inclusion-order hazard for ECPG clients,who previously might get build failures or unexpected behaviordepending on whether they'd included <stdbool.h> themselves,and if so, whether before or after ecpglib.h.On platforms where sizeof(_Bool) is not 1 (only old PPC-basedMac systems, as far as I know), things are still messy, asinclusion of <stdbool.h> could still break ECPG client code.There doesn't seem to be any clean fix for that, and given theprobably-negligible population of users who would care anymore,it's not clear we should go far out of our way to cope with it.This change at least fixes some header-inclusion-order hazardsfor our own code, since c.h and ecpglib.h previously disagreedon whether bool should be char or unsigned char.To implement this with minimal invasion of ECPG client namespace,move the choice of whether to rely on <stdbool.h> into configure,and have it export a configuration symbol PG_USE_STDBOOL.ecpglib.h no longer exports definitions for TRUE and FALSE,only their lowercase brethren. We could undo that if we getpush-back about it.Ideally we'd back-patch this as far as v11, which is where c.hstarted to rely on <stdbool.h>. But the odds of creating problemsfor formerly-working ECPG client code seem about as large as theodds of fixing any non-working cases, so we'll just do this in HEAD.Discussion:https://postgr.es/m/CAA4eK1LmaKO7Du9M9Lo=kxGU8sB6aL8fa3sF6z6d5yYYVe3BuQ@mail.gmail.com
1 parentde7c2d3 commit7a0574b

File tree

10 files changed

+55
-21
lines changed

10 files changed

+55
-21
lines changed

‎configure

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14786,6 +14786,12 @@ _ACEOF
1478614786

1478714787

1478814788

14789+
if test "$ac_cv_header_stdbool_h" = yes -a "$ac_cv_sizeof_bool" = 1; then
14790+
14791+
$as_echo "#define PG_USE_STDBOOL 1" >>confdefs.h
14792+
14793+
fi
14794+
1478914795

1479014796
##
1479114797
## Functions, global variables

‎configure.in

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1593,6 +1593,13 @@ AC_CHECK_SIZEOF([bool], [],
15931593
#include <stdbool.h>
15941594
#endif])
15951595

1596+
dnl We use <stdbool.h> if we have it and it declares type bool as having
1597+
dnl size 1. Otherwise, c.h will fall back to declaring bool as unsigned char.
1598+
if test "$ac_cv_header_stdbool_h" = yes -a "$ac_cv_sizeof_bool" = 1; then
1599+
AC_DEFINE([PG_USE_STDBOOL], 1,
1600+
[Define to 1 to use <stdbool.h> to define type bool.])
1601+
fi
1602+
15961603

15971604
##
15981605
## Functions, global variables

‎src/backend/utils/fmgr/dfmgr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
* On macOS, <dlfcn.h> insists on including <stdbool.h>. If we're not
2424
* using stdbool, undef bool to undo the damage.
2525
*/
26-
#ifndefUSE_STDBOOL
26+
#ifndefPG_USE_STDBOOL
2727
#ifdefbool
2828
#undef bool
2929
#endif

‎src/include/c.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -288,20 +288,21 @@
288288
* bool
289289
*Boolean value, either true or false.
290290
*
291-
*Use stdbool.h if available and its bool has size 1. That's useful for
291+
*We use stdbool.h if available and its bool has size 1. That's useful for
292292
* better compiler and debugger output and for compatibility with third-party
293293
* libraries. But PostgreSQL currently cannot deal with bool of other sizes;
294294
* there are static assertions around the code to prevent that.
295295
*
296296
* For C++ compilers, we assume the compiler has a compatible built-in
297297
* definition of bool.
298+
*
299+
* See also the version of this code in src/interfaces/ecpg/include/ecpglib.h.
298300
*/
299301

300302
#ifndef__cplusplus
301303

302-
#if defined(HAVE_STDBOOL_H)&&SIZEOF_BOOL==1
304+
#ifdefPG_USE_STDBOOL
303305
#include<stdbool.h>
304-
#defineUSE_STDBOOL 1
305306
#else
306307

307308
#ifndefbool
@@ -316,7 +317,7 @@ typedef unsigned char bool;
316317
#definefalse((bool) 0)
317318
#endif
318319

319-
#endif
320+
#endif/* not PG_USE_STDBOOL */
320321
#endif/* not C++ */
321322

322323

‎src/include/pg_config.h.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -829,6 +829,9 @@
829829
/* Define to best printf format archetype, usually gnu_printf if available. */
830830
#undef PG_PRINTF_ATTRIBUTE
831831

832+
/* Define to 1 to use <stdbool.h> to define type bool. */
833+
#undef PG_USE_STDBOOL
834+
832835
/* PostgreSQL version as a string */
833836
#undef PG_VERSION
834837

‎src/include/pg_config.h.win32

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,9 @@
624624
(--with-krb-srvnam=NAME) */
625625
#define PG_KRB_SRVNAM "postgres"
626626

627+
/* Define to 1 to use <stdbool.h> to define type bool. */
628+
#define PG_USE_STDBOOL 1
629+
627630
/* A string containing the version number, platform, and C compiler */
628631
#define PG_VERSION_STR "Uninitialized version string (win32)"
629632

‎src/interfaces/ecpg/include/ecpg_config.h.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
/* Define to 1 if `long long int' works and is 64 bits. */
1111
#undef HAVE_LONG_LONG_INT_64
1212

13+
/* Define to 1 to use <stdbool.h> to define type bool. */
14+
#undef PG_USE_STDBOOL
15+
1316
/* Define to 1 to build client libraries as thread-safe code.
1417
* (--enable-thread-safety) */
1518
#undef ENABLE_THREAD_SAFETY

‎src/interfaces/ecpg/include/ecpglib.h

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,47 @@
11
/*
2-
*this is a small part of c.h since we don't want to leak all postgres
3-
* definitions into ecpg programs
2+
*Client-visible declarations for ecpglib
3+
*
44
* src/interfaces/ecpg/include/ecpglib.h
55
*/
66

77
#ifndef_ECPGLIB_H
88
#define_ECPGLIB_H
99

1010
#include"libpq-fe.h"
11+
#include"ecpg_config.h"
1112
#include"ecpgtype.h"
1213
#include"sqlca.h"
1314
#include<string.h>
1415

16+
/*
17+
* This is a small extract from c.h since we don't want to leak all postgres
18+
* definitions into ecpg programs; but we need to know what bool is.
19+
*/
1520
#ifndef__cplusplus
16-
#ifndefbool
17-
#definebool char
18-
#endif/* ndef bool */
21+
22+
#ifdefPG_USE_STDBOOL
23+
#include<stdbool.h>
24+
#else
25+
26+
/*
27+
* We assume bool has been defined if true and false are. This avoids
28+
* duplicate-typedef errors if this file is included after c.h.
29+
*/
30+
#if !(defined(true)&& defined(false))
31+
typedefunsignedcharbool;
32+
#endif
1933

2034
#ifndeftrue
2135
#definetrue((bool) 1)
22-
#endif/* ndef true */
36+
#endif
37+
2338
#ifndeffalse
2439
#definefalse((bool) 0)
25-
#endif/* ndef false */
26-
#endif/* not C++ */
40+
#endif
2741

28-
#ifndefTRUE
29-
#defineTRUE1
30-
#endif/* TRUE */
42+
#endif/* not PG_USE_STDBOOL */
43+
#endif/* not C++ */
3144

32-
#ifndefFALSE
33-
#defineFALSE0
34-
#endif/* FALSE */
3545

3646
#ifdef__cplusplus
3747
extern"C"

‎src/pl/plperl/plperl.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
* warnings. If PostgreSQL does not but Perl does, we need to undefine bool
6565
* after we include the Perl headers; see below.
6666
*/
67-
#ifdefUSE_STDBOOL
67+
#ifdefPG_USE_STDBOOL
6868
#defineHAS_BOOL 1
6969
#endif
7070

@@ -175,7 +175,7 @@
175175
* makes bool a macro, but our own replacement is a typedef, so the undef
176176
* makes ours visible again).
177177
*/
178-
#ifndefUSE_STDBOOL
178+
#ifndefPG_USE_STDBOOL
179179
#ifdefbool
180180
#undef bool
181181
#endif

‎src/tools/msvc/Solution.pm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,7 @@ sub GenerateFiles
513513
print$o<<EOF;
514514
#define HAVE_LONG_LONG_INT 1
515515
#define HAVE_LONG_LONG_INT_64 1
516+
#define PG_USE_STDBOOL 1
516517
#define ENABLE_THREAD_SAFETY 1
517518
EOF
518519
close($o);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp