Fix compile errors with certain CFLAGS.
authorTatsuo Ishii <ishii@sraoss.co.jp>
Mon, 25 Mar 2024 07:15:50 +0000 (16:15 +0900)
committerTatsuo Ishii <ishii@sraoss.co.jp>
Mon, 25 Mar 2024 07:33:18 +0000 (16:33 +0900)
https://github.com/pgpool/pgpool2/issues/42 reported that with CFLAGS
-flto=4 -Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing
gcc emits errors. Some of them are mistakes when their sources were
brought in from PostgreSQL.  This commit fixes them. Note that I was
not able to suppress some errors at least with my gcc (9.4.0). This
may be because gcc bug (false positives) or just a bug with the old
gcc, I don't know at this point. Maybe someday revisit this.

Discussion:
[pgpool-hackers: 4442] Fixing GitHub issue 42
https://www.pgpool.net/pipermail/pgpool-hackers/2024-March/004443.html

../src/include/query_cache/pool_memqcache.h:251:20: warning: type of 'pool_fetch_from_memory_cache' does not match original declaration [-Wlto-type-mismatch]
  251 | extern POOL_STATUS pool_fetch_from_memory_cache(POOL_CONNECTION * frontend,
      |                    ^
query_cache/pool_memqcache.c:731:1: note: 'pool_fetch_from_memory_cache' was previously declared here
  731 | pool_fetch_from_memory_cache(POOL_CONNECTION * frontend,
      | ^
query_cache/pool_memqcache.c:731:1: note: code may be misoptimized unless '-fno-strict-aliasing' is used
../src/include/utils/palloc.h:64:22: warning: type of 'CurrentMemoryContext' does not match original declaration [-Wlto-type-mismatch]
   64 | extern MemoryContext CurrentMemoryContext;
      |                      ^
../../src/utils/mmgr/mcxt.c:40:15: note: 'CurrentMemoryContext' was previously declared here
../../src/utils/mmgr/mcxt.c:40:15: note: code may be misoptimized unless '-fno-strict-aliasing' is used
../src/include/utils/memutils.h:55:22: warning: type of 'TopMemoryContext' does not match original declaration [-Wlto-type-mismatch]
   55 | extern MemoryContext TopMemoryContext;
      |                      ^
../../src/utils/mmgr/mcxt.c:46:15: note: 'TopMemoryContext' was previously declared here
../../src/utils/mmgr/mcxt.c:46:15: note: code may be misoptimized unless '-fno-strict-aliasing' is used
../src/include/pool_config.h:646:22: warning: type of 'pool_config' does not match original declaration [-Wlto-type-mismatch]
  646 | extern POOL_CONFIG * pool_config;
      |                      ^
config/pool_config.l:46:14: note: 'pool_config' was previously declared here
   46 | POOL_CONFIG *pool_config = &g_pool_config; /* for legacy reason pointer to the above struct */
      |              ^
config/pool_config.l:46:14: note: code may be misoptimized unless '-fno-strict-aliasing' is used

src/include/utils/elog.h
src/include/utils/fe_ports.h
src/include/utils/palloc.h
src/tools/fe_memutils.c
src/tools/fe_port.c

index c831662b1a387ea35a1c8dcb12ce3d6a8a141150..92eb298faeb6e57b3ce8406041dc0438d8dc23b8 100644 (file)
@@ -4,7 +4,7 @@
  *       POSTGRES error reporting/logging definitions.
  *
  *
- * Portions Copyright (c) 2003-2023, PgPool Global Development Group
+ * Portions Copyright (c) 2003-2024, PgPool Global Development Group
  * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
index eff29a9fb43bab582c7c4684d93953b4c7a7cd9d..1eb6797ea67e4e553868facdb5c175c25a730969 100644 (file)
@@ -5,7 +5,7 @@
  * pgpool: a language independent connection pool server for PostgreSQL
  * written by Tatsuo Ishii
  *
- * Copyright (c) 2003-2023     PgPool Global Development Group
+ * Copyright (c) 2003-2024     PgPool Global Development Group
  *
  * Permission to use, copy, modify, and distribute this software and
  * its documentation for any purpose and without fee is hereby
 extern char *simple_prompt(const char *prompt, int maxlen, bool echo);
 extern int     _fe_error_level;
 
-void      *pg_malloc(size_t size);
+void      *pg_malloc(Size size);
 
 void      *pg_malloc0(size_t size);
-void      *pg_realloc(void *ptr, size_t size);
+void      *pg_realloc(void *ptr, Size size);
 char      *pg_strdup(const char *in);
 void           pg_free(void *ptr);
-void      *palloc(unsigned int size);
-void      *palloc0(unsigned int size);
+void      *palloc(Size size);
+void      *palloc0(Size size);
 void           pfree(void *pointer);
 char      *pstrdup(const char *in);
-void      *repalloc(void *pointer, unsigned int size);
+void      *repalloc(void *pointer, Size size);
 
 #ifdef __GNUC__
 extern int
@@ -69,8 +69,8 @@ extern int    errdetail(const char *fmt,...);
 extern void errmsg(const char *fmt,...);
 #endif
 
-extern int errstart(int elevel, const char *filename, int lineno,
-                const char *funcname);
+extern bool errstart(int elevel, const char *filename, int lineno,
+                                       const char *funcname, const char *domain);
 extern void errfinish(int dummy,...);
 
 /*
@@ -133,7 +133,7 @@ extern void errfinish(int dummy,...);
 do { \
        const int elevel_ = (elevel); \
        _fe_error_level = elevel_; \
-       if (errstart(elevel_, __FILE__, __LINE__, __FUNCTION__)) \
+       if (errstart(elevel_, __FILE__, __LINE__, __FUNCTION__, "")) \
                rest; \
        if (elevel_ >= ERROR  && elevel_ != FRONTEND_ONLY_ERROR) \
                exit(-1); \
index 2ed586ed0f714708069e60142bb4354966b201eb..bf6cdb2eff376b4f87dd06c2426962d2ed6b2b1e 100644 (file)
@@ -18,7 +18,7 @@
  * everything that should be freed.  See utils/mmgr/README for more info.
  *
  *
- * Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * src/include/utils/palloc.h
@@ -61,7 +61,7 @@ typedef struct MemoryContextCallback
  * Avoid accessing it directly!  Instead, use MemoryContextSwitchTo()
  * to change the setting.
  */
-extern PGDLLIMPORT MemoryContext CurrentMemoryContext;
+extern MemoryContext CurrentMemoryContext;
 
 /*
  * Flags for MemoryContextAllocExtended.
index 0f6ccb31476122fd16d220d9b0e7dbc90b947491..0938f17553ff0ee36623a467c2beb0b0bee74690 100644 (file)
@@ -3,7 +3,7 @@
  * fe_memutils.c
  *       memory management support for frontend code
  *
- * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  *
@@ -23,7 +23,7 @@
 #include "utils/fe_ports.h"
 
 void *
-pg_malloc(size_t size)
+pg_malloc(Size size)
 {
        void       *tmp;
 
@@ -40,7 +40,7 @@ pg_malloc(size_t size)
 }
 
 void *
-pg_malloc0(size_t size)
+pg_malloc0(Size size)
 {
        void       *tmp;
 
@@ -50,7 +50,7 @@ pg_malloc0(size_t size)
 }
 
 void *
-pg_realloc(void *ptr, size_t size)
+pg_realloc(void *ptr, Size size)
 {
        void       *tmp;
 
@@ -101,13 +101,13 @@ pg_free(void *ptr)
  * programs that compile backend files.
  */
 void *
-palloc(unsigned int size)
+palloc(Size size)
 {
        return pg_malloc(size);
 }
 
 void *
-palloc0(unsigned int size)
+palloc0(Size size)
 {
        return pg_malloc0(size);
 }
@@ -125,7 +125,7 @@ pstrdup(const char *in)
 }
 
 void *
-repalloc(void *pointer, unsigned int size)
+repalloc(void *pointer, Size size)
 {
        return pg_realloc(pointer, size);
 }
index 881cd1dbee40d7ce658afbf11a044948a3030709..3704c2730776bbabf1e26208718137fffa244090 100644 (file)
@@ -2,7 +2,7 @@
  * pgpool: a language independent connection pool server for PostgreSQL
  * written by Tatsuo Ishii
  *
- * Copyright (c) 2003-2023     PgPool Global Development Group
+ * Copyright (c) 2003-2024     PgPool Global Development Group
  *
  * Permission to use, copy, modify, and distribute this software and
  * its documentation for any purpose and without fee is hereby
@@ -162,9 +162,8 @@ nowsec(void)
        return strbuf;
 }
 
-int
-errstart(int elevel, const char *filename, int lineno,
-                const char *funcname)
+bool errstart(int elevel, const char *filename, int lineno,
+                const char *funcname, const char *domain)
 {
        _fe_error_level = elevel;