Обсуждение: BUG #19062: PostgreSQL 12.22 does not compile because of conflicting types for CollationCreate

Поиск
Список
Период
Сортировка

BUG #19062: PostgreSQL 12.22 does not compile because of conflicting types for CollationCreate

От
PG Bug reporting form
Дата:
The following bug has been logged on the website:

Bug reference:      19062
Logged by:          Peter Dyballa
Email address:      peter_dyballa@web.de
PostgreSQL version: Unsupported/Unknown
Operating system:   Mac OS X 10.5.8, "Leopard", PowerPC
Description:

With default compiler /usr/bin/gcc-4.2 (powerpc-apple-darwin9-gcc-4.2.1
(GCC) 4.2.1 (Apple Inc. build 5577)) the error is:

pg_collation.c:55: error: conflicting types for ‘CollationCreate’
../../../src/include/catalog/pg_collation.h:70: error: previous declaration
of ‘CollationCreate’ was here
pg_collation.c: In function ‘CollationCreate’:
pg_collation.c:196: warning: passing argument 3 of ‘heap_form_tuple’ from
incompatible pointer type
gnumake[3]: *** [pg_collation.o] Error 1
gnumake[3]: Leaving directory
`/opt/local/var/macports/build/postgresql12-5f1ceb12/work/postgresql-12.22/src/backend/catalog'
gnumake[2]: *** [catalog-recursive] Error 2
gnumake[2]: Leaving directory
`/opt/local/var/macports/build/postgresql12-5f1ceb12/work/postgresql-12.22/src/backend'
gnumake[1]: *** [all-backend-recurse] Error 2
gnumake[1]: Leaving directory
`/opt/local/var/macports/build/postgresql12-5f1ceb12/work/postgresql-12.22/src'
gnumake: *** [world-src-recurse] Error 2
gnumake: Leaving directory
`/opt/local/var/macports/build/postgresql12-5f1ceb12/work/postgresql-12.22'
Command failed:  cd
"/opt/local/var/macports/build/postgresql12-5f1ceb12/work/postgresql-12.22"
&& /usr/bin/gnumake -w world

With more up-to-date compiler /opt/local/bin/gcc-mp-14 (gcc-mp-14 (MacPorts
gcc14 14.2.0_1)) it is:

/opt/local/bin/gcc-mp-14 -Wall -Wmissing-prototypes -Wpointer-arith
-Wdeclaration-after-statement -Werror=vla -Wendif-labels
-Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv
-fexcess-precision=standard -Wno-format-truncation -Wno-stringop-truncation
-pipe -I/opt/local/libexec/openssl3/include -Os -arch ppc
-I../../../src/include  -I/opt/local/libexec/openssl3/include
-isystem/opt/local/include -I/opt/local/include/libxml2
-I/opt/local/include  -c -o pg_collation.o pg_collation.c
pg_collation.c:46:1: error: conflicting types for 'CollationCreate'; have
'Oid(const char *, Oid,  Oid,  char,  _Bool,  int32,  const char *, const
char *, const char *, _Bool,  _Bool)' {aka 'unsigned int(const char *,
unsigned int,  unsigned int,  char,  _Bool,  int,  const char *, const char
*, const char *, _Bool,  _Bool)'}
   46 | CollationCreate(const char *collname, Oid collnamespace,
      | ^~~~~~~~~~~~~~~
In file included from pg_collation.c:25:
../../../src/include/catalog/pg_collation.h:62:17: note: previous
declaration of 'CollationCreate' with type 'Oid(const char *, Oid,  Oid,
char,  bool,  int32,  const char *, const char *, const char *, bool,
bool)' {aka 'unsigned int(const char *, unsigned int,  unsigned int,  char,
unsigned char,  int,  const char *, const char *, const char *, unsigned
char,  unsigned char)'}
   62 | extern Oid      CollationCreate(const char *collname, Oid
collnamespace,
      |                 ^~~~~~~~~~~~~~~
pg_collation.c: In function 'CollationCreate':
pg_collation.c:196:48: error: passing argument 3 of 'heap_form_tuple' from
incompatible pointer type [-Wincompatible-pointer-types]
  196 |         tup = heap_form_tuple(tupDesc, values, nulls);
      |                                                ^~~~~
      |                                                |
      |                                                _Bool *
In file included from pg_collation.c:18:
../../../src/include/access/htup_details.h:794:87: note: expected 'bool *'
{aka 'unsigned char *'} but argument is of type '_Bool *'
  794 |
Datum *values, bool *isnull);
      |
~~~~~~^~~~~~
gnumake[3]: *** [pg_collation.o] Error 1
gnumake[3]: Leaving directory
`/opt/local/var/macports/build/postgresql12-5f1ceb12/work/postgresql-12.22/src/backend/catalog'
gnumake[2]: *** [catalog-recursive] Error 2
gnumake[2]: Leaving directory
`/opt/local/var/macports/build/postgresql12-5f1ceb12/work/postgresql-12.22/src/backend'
gnumake[1]: *** [all-backend-recurse] Error 2
gnumake[1]: Leaving directory
`/opt/local/var/macports/build/postgresql12-5f1ceb12/work/postgresql-12.22/src'
gnumake: *** [world-src-recurse] Error 2
gnumake: Leaving directory
`/opt/local/var/macports/build/postgresql12-5f1ceb12/work/postgresql-12.22'
Command failed:  cd
"/opt/local/var/macports/build/postgresql12-5f1ceb12/work/postgresql-12.22"
&& /usr/bin/gnumake -w world

--

Pete


PG Bug reporting form <noreply@postgresql.org> writes:
> With default compiler /usr/bin/gcc-4.2 (powerpc-apple-darwin9-gcc-4.2.1
> (GCC) 4.2.1 (Apple Inc. build 5577)) the error is:
> pg_collation.c:55: error: conflicting types for ‘CollationCreate’

PG 12 is EOL, so we won't be doing anything about this.  However,
it's evident from your messages that the problem is something
about "bool" (probably our typedef as "char") versus "_Bool"
(C99 <stdbool.h>).  If you need a fix for PG 12, you might get
somewhere by trawling later branches' commit history for fixes
related to that.

            regards, tom lane



On Thu, Sep 25, 2025 at 2:41 AM Tom Lane <tgl@sss.pgh.pa.us> wrote:
> PG Bug reporting form <noreply@postgresql.org> writes:
> > With default compiler /usr/bin/gcc-4.2 (powerpc-apple-darwin9-gcc-4.2.1
> > (GCC) 4.2.1 (Apple Inc. build 5577)) the error is:
> > pg_collation.c:55: error: conflicting types for ‘CollationCreate’
>
> PG 12 is EOL, so we won't be doing anything about this.  However,
> it's evident from your messages that the problem is something
> about "bool" (probably our typedef as "char") versus "_Bool"
> (C99 <stdbool.h>).  If you need a fix for PG 12, you might get
> somewhere by trawling later branches' commit history for fixes
> related to that.

We didn't resolve that in a way that would work for (old) macOS/PPC,
where sizeof(_Bool) was 4 (it was the last known system to have a size
other than 1).  But if you want a hackish solution for archeological
purposes, let's see...

REL_12_STABLE's c.h says:

#if defined(HAVE_STDBOOL_H) && SIZEOF_BOOL == 1
#include <stdbool.h>
#define USE_STDBOOL 1
#else

#ifndef bool
typedef unsigned char bool;  <-- macOS/PPC would do this, not the thing above
#endif

I assume that <stdbool.h> is being included indirectly later by some
other system header, and that's defining bool to _Bool and thus hiding
our typedef.  I don't know what changed since we used to test on that
platform a few years ago, but perhaps you could try messing with
<stdbool.h>'s include guard by defining __STDBOOL_H?  Or something
along those lines, either with -D or in c.h.

Obviously it's not great that some libraries would use a different
size for "bool".  We don't do that any more, in recent releases.



Pre-processing with GCC 4.2 or GCC 14.2 I get both times the same definition from src/include/catalog/pg_collation.h:

    extern Oid CollationCreate(const char *collname, Oid collnamespace,
           Oid collowner,
           char collprovider,
           bool collisdeterministic,
           int32 collencoding,
           const char *collcollate, const char *collctype,
           const char *collversion,
           bool if_not_exists,
           bool quiet);
    extern void RemoveCollationById(Oid collationOid);

From src/backend/catalog/pg_collation.c I get (4.2 vs. 14.2)

    #define ReleaseSysCacheList(x) ReleaseCatCacheList(x)
    # 33 "pg_collation.c" 2
    # 45 "pg_collation.c"
    Oid
    CollationCreate(const char *collname, Oid collnamespace,
        Oid collowner,
        char collprovider,
        _Bool collisdeterministic,
        int32 collencoding,
        const char *collcollate, const char *collctype,
        const char *collversion,
        _Bool if_not_exists,
        _Bool quiet)
    {
     Relation rel;
     TupleDesc tupDesc;
     HeapTuple tup;
     Datum values[10];
     _Bool nulls[10];
     NameData name_name,
        name_collate,
        name_ctype;
     Oid oid;
     ObjectAddress myself,
        referenced;

vs.

    #define ReleaseSysCacheList(x) ReleaseCatCacheList(x)
    # 33 "pg_collation.c" 2
    # 45 "pg_collation.c"
    Oid
    CollationCreate(const char *collname, Oid collnamespace,
        Oid collowner,
        char collprovider,

    # 49 "pg_collation.c" 3 4
       _Bool
    # 49 "pg_collation.c"
            collisdeterministic,
        int32 collencoding,
        const char *collcollate, const char *collctype,
        const char *collversion,

    # 53 "pg_collation.c" 3 4
       _Bool
    # 53 "pg_collation.c"
            if_not_exists,

    # 54 "pg_collation.c" 3 4
       _Bool
    # 54 "pg_collation.c"
            quiet)
    {
     Relation rel;
     TupleDesc tupDesc;
     HeapTuple tup;
     Datum values[10];

    # 60 "pg_collation.c" 3 4
    _Bool
    # 60 "pg_collation.c"
          nulls[10];
     NameData name_name,
        name_collate,
        name_ctype;
     Oid oid;
     ObjectAddress myself,
        referenced;

which both are adequate. _Bool is #defined by the C compiler:

    # 32 "/usr/lib/gcc/powerpc-apple-darwin9/4.2.1/include/stdbool.h" 3 4
    #define _STDBOOL_H



    #define bool _Bool
    #define true 1
    #define false 0
    # 51 "/usr/lib/gcc/powerpc-apple-darwin9/4.2.1/include/stdbool.h" 3 4
    #define __bool_true_false_are_defined 1
    # 53 "/opt/local/include/libxml2/unicode/umachine.h" 2

vs.

    # 29 "/opt/local/lib/gcc14/gcc/powerpc-apple-darwin9/14.2.0/include/stdbool.h" 3 4
    #define _STDBOOL_H







    #define bool _Bool
    #define true 1
    #define false 0
    # 49 "/opt/local/lib/gcc14/gcc/powerpc-apple-darwin9/14.2.0/include/stdbool.h" 3 4
    #define __bool_true_false_are_defined 1
    # 53 "/opt/local/include/libxml2/unicode/umachine.h" 2

My understanding of C is too limited to see an error and find a solution. So let's leave it!


--

Greetings

  Pete

If the majority of cooking accidents happen in the kitchen, then why don't we just cook in other rooms?




On Wed, Oct 1, 2025 at 11:46 PM Peter Dyballa <Peter_Dyballa@web.de> wrote:
>         #define bool _Bool
>         #define true 1
>         #define false 0
>         # 49 "/opt/local/lib/gcc14/gcc/powerpc-apple-darwin9/14.2.0/include/stdbool.h" 3 4
>         #define __bool_true_false_are_defined 1
>         # 53 "/opt/local/include/libxml2/unicode/umachine.h" 2

OK, so now we see who is including <stdbool.h>.  If XML support isn't
important to you, perhaps another option would be to remove
--enable-libxml from your configure invocation?  Hmm, that appears to
be a vendored copy of ICU that you get if libxml2 was built with
--with-icu, rather than something coming from libxml's "own" headers.
I guess that means you'll have the same problem again if you also have
--with-icu in your PostgreSQL configure invocation, so you'd need to
take that out too.

> My understanding of C is too limited to see an error and find a solution. So let's leave it!

FTR what I was suggesting is something like CPPFLAGS="-D_STDBOOL_H"
(or append that to anything else you are already putting in CPPFLAGS
on the configure invocation), which should prevent <stdbool.h> from
having any effect, meaning it can't hide c.h's definition.  I don't
know what concrete ABI dangers lurk in this area, but it doesn't look
like ICU uses bool in public interfaces, preferring its own UBool, a
typedef for int8_t.  Hmm, so it's not immediately clear why it
includes it... but I'm too lazy to check.



Thomas Munro <thomas.munro@gmail.com> writes:
> FTR what I was suggesting is something like CPPFLAGS="-D_STDBOOL_H"
> (or append that to anything else you are already putting in CPPFLAGS
> on the configure invocation), which should prevent <stdbool.h> from
> having any effect, meaning it can't hide c.h's definition.  I don't
> know what concrete ABI dangers lurk in this area, but it doesn't look
> like ICU uses bool in public interfaces, preferring its own UBool, a
> typedef for int8_t.  Hmm, so it's not immediately clear why it
> includes it... but I'm too lazy to check.

Yeah, it's hard to get excited about putting effort into this.
As of PG 18 (97525bc5c) we've moved on permanently from
supporting machines where the native bool type is not of size 1.
Theoretically it should work in older branches as long as you
don't try to interact with any libraries that use bool in
their headers --- so taking out --with-libxml and perhaps
--with-icu is probably the minimum requirement for that.
But we haven't been testing such platforms since around 2022,
so who knows if it still works in recent minor releases.

Peter, perhaps an answer if you want to keep retrocomputing
on this hardware is to use NetBSD?  That does work for me
on an old G4 laptop, and it has sizeof(bool) == 1.  See
buildfarm member mamba ...

            regards, tom lane



From examining the pre-processed code I saw

    # 32 "/usr/lib/gcc/powerpc-apple-darwin9/4.2.1/include/stdbool.h" 3 4
    #define _STDBOOL_H

or

    # 29 "/opt/local/lib/gcc14/gcc/powerpc-apple-darwin9/14.2.0/include/stdbool.h" 3 4
    #define _STDBOOL_H

and thought "It's already there", but I let PostgreSQL 12.22 build with that explicit define:

    /usr/bin/gcc-4.2 -std=gnu99 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels
-Wmissing-format-attribute-Wformat-security -fno-strict-aliasing -fwrapv -pipe -I/opt/local/libexec/openssl3/include
-Os-arch ppc -I../../../src/include  -I/opt/local/libexec/openssl3/include -isystem/opt/local/include -D__STDBOOL_H
-I/opt/local/include/libxml2 -I/opt/local/include  -c -o pg_collation.o pg_collation.c 
    pg_collation.c:55: error: conflicting types for ‘CollationCreate’
    ../../../src/include/catalog/pg_collation.h:70: error: previous declaration of ‘CollationCreate’ was here
    pg_collation.c: In function ‘CollationCreate’:
    pg_collation.c:196: warning: passing argument 3 of ‘heap_form_tuple’ from incompatible pointer type

vs.

    /opt/local/bin/gcc-mp-14 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla
-Wendif-labels-Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard
-Wno-format-truncation-Wno-stringop-truncation -pipe -I/opt/local/libexec/openssl3/include -Os -arch ppc
-I../../../src/include -I/opt/local/libexec/openssl3/include -isystem/opt/local/include -D__STDBOOL_H
-I/opt/local/include/libxml2 -I/opt/local/include  -c -o pg_collation.o pg_collation.c 
    pg_collation.c:46:1: error: conflicting types for 'CollationCreate'; have 'Oid(const char *, Oid,  Oid,  char,
_Bool, int32,  const char *, const char *, const char *, _Bool,  _Bool)' {aka 'unsigned int(const char *, unsigned int,
unsigned int,  char,  _Bool,  int,  const char *, const char *, const char *, _Bool,  _Bool)'} 
       46 | CollationCreate(const char *collname, Oid collnamespace,
          | ^~~~~~~~~~~~~~~
    In file included from pg_collation.c:25:
    ../../../src/include/catalog/pg_collation.h:62:17: note: previous declaration of 'CollationCreate' with type
'Oid(constchar *, Oid,  Oid,  char,  bool,  int32,  const char *, const char *, const char *, bool,  bool)' {aka
'unsignedint(const char *, unsigned int,  unsigned int,  char,  unsigned char,  int,  const char *, const char *, const
char*, unsigned char,  unsigned char)'} 
       62 | extern Oid      CollationCreate(const char *collname, Oid collnamespace,
          |                 ^~~~~~~~~~~~~~~
    pg_collation.c: In function 'CollationCreate':
    pg_collation.c:196:48: error: passing argument 3 of 'heap_form_tuple' from incompatible pointer type
[-Wincompatible-pointer-types]
      196 |         tup = heap_form_tuple(tupDesc, values, nulls);
          |                                                ^~~~~
          |                                                |
          |                                                _Bool *
    In file included from pg_collation.c:18:
    ../../../src/include/access/htup_details.h:794:87: note: expected 'bool *' {aka 'unsigned char *'} but argument is
oftype '_Bool *' 
      794 |                                                                  Datum *values, bool *isnull);
          |                                                                                 ~~~~~~^~~~~~

So this additional flag brings indeed no change.

--------------------

When trying to remove XML support I found that XSLT support has to be cancelled explicitly (configure tests need
libxml/tree.h).I think this could be automated – XSLT support is not possible without libxml2, is it? 

Anyway, the builds fail with similar messages:

    /usr/bin/gcc-4.2 -std=gnu99 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels
-Wmissing-format-attribute-Wformat-security -fno-strict-aliasing -fwrapv -pipe -I/opt/local/libexec/openssl3/include
-Os-arch ppc -I../../../src/include  -I/opt/local/libexec/openssl3/include -isystem/opt/local/include
-I/opt/local/include -c -o pg_collation.o pg_collation.c 
    pg_collation.c:55: error: conflicting types for ‘CollationCreate’
    ../../../src/include/catalog/pg_collation.h:70: error: previous declaration of ‘CollationCreate’ was here
    pg_collation.c: In function ‘CollationCreate’:
    pg_collation.c:196: warning: passing argument 3 of ‘heap_form_tuple’ from incompatible pointer type
    gnumake[3]: *** [pg_collation.o] Error 1
    gnumake[3]: Leaving directory
`/opt/local/var/macports/build/postgresql12-5f1ceb12/work/postgresql-12.22/src/backend/catalog'

vs.

    /opt/local/bin/gcc-mp-14 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla
-Wendif-labels-Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard
-Wno-format-truncation-Wno-stringop-truncation -pipe -I/opt/local/libexec/openssl3/include -Os -arch ppc
-I../../../src/include -I/opt/local/libexec/openssl3/include -isystem/opt/local/include  -I/opt/local/include  -c -o
pg_collation.opg_collation.c 
    pg_collation.c:46:1: error: conflicting types for 'CollationCreate'; have 'Oid(const char *, Oid,  Oid,  char,
_Bool, int32,  const char *, const char *, const char *, _Bool,  _Bool)' {aka 'unsigned int(const char *, unsigned int,
unsigned int,  char,  _Bool,  int,  const char *, const char *, const char *, _Bool,  _Bool)'} 
       46 | CollationCreate(const char *collname, Oid collnamespace,
          | ^~~~~~~~~~~~~~~
    In file included from pg_collation.c:25:
    ../../../src/include/catalog/pg_collation.h:62:17: note: previous declaration of 'CollationCreate' with type
'Oid(constchar *, Oid,  Oid,  char,  bool,  int32,  const char *, const char *, const char *, bool,  bool)' {aka
'unsignedint(const char *, unsigned int,  unsigned int,  char,  unsigned char,  int,  const char *, const char *, const
char*, unsigned char,  unsigned char)'} 
       62 | extern Oid      CollationCreate(const char *collname, Oid collnamespace,
          |                 ^~~~~~~~~~~~~~~
    pg_collation.c: In function 'CollationCreate':
    pg_collation.c:196:48: error: passing argument 3 of 'heap_form_tuple' from incompatible pointer type
[-Wincompatible-pointer-types]
      196 |         tup = heap_form_tuple(tupDesc, values, nulls);
          |                                                ^~~~~
          |                                                |
          |                                                _Bool *
    In file included from pg_collation.c:18:
    ../../../src/include/access/htup_details.h:794:87: note: expected 'bool *' {aka 'unsigned char *'} but argument is
oftype '_Bool *' 
      794 |                                                                  Datum *values, bool *isnull);
          |                                                                                 ~~~~~~^~~~~~
    gnumake[3]: *** [pg_collation.o] Error 1
    gnumake[3]: Leaving directory
`/opt/local/var/macports/build/postgresql12-5f1ceb12/work/postgresql-12.22/src/backend/catalog'

Adding -D__STDBOOL_H brings no real change, so the culprit could be ICU. Configuring without ICU brings success. With
bothcompilers and with all tests. Solution #1. 

--------------------


I am building in a MacPorts environment, for convenience. So its own XML and ICU installations get used. With Mac OS X
10.5.8,Leopard, /usr/lib/libxml2.2.dylib is installed – and ICU only partially: /usr/lib/libicucore.dylib. OTOH
MacPortshas a patch file for building PostgreSQL versions 13…17 with ICU: 

    --- src/include/utils/pg_locale.h.orig 2022-08-09 04:44:29.000000000 +0800
    +++ src/include/utils/pg_locale.h 2022-10-25 01:49:09.000000000 +0800
    @@ -17,6 +17,9 @@
     #endif
     #ifdef USE_ICU
     #include <unicode/ucol.h>
    +#ifdef bool
    +#undef bool
    +#endif
     #endif
       #include "utils/guc.h"

    --- src/backend/utils/adt/formatting.c.orig 2022-10-25 02:07:10.000000000 +0800
    +++ src/backend/utils/adt/formatting.c 2022-10-25 02:07:21.000000000 +0800
    @@ -81,6 +81,9 @@
       #ifdef USE_ICU
     #include <unicode/ustring.h>
    +#ifdef bool
    +#undef bool
    +#endif
     #endif
       #include "catalog/pg_collation.h"

Quite simple… It removes the type _Bool from the pre-processed output. Applying it also for version 12.22 brings
successwhen configuring with XML, XSLT, and ICU support. The C header files <unicode/ucol.h> and <unicode/ustring.h>
areboth from MacPorts' ICU installation. Solution #2. 

It's time to upgrade anyway. Thanks for your support, encouraging me to dig a bit on the surface.


--
Greetings

  Pete                                           0
                                           %-/\_//
                                            (*)(*)