From dac18c2caeb8496987efa11c17d2c56e7d43e838 Mon Sep 17 00:00:00 2001 From: Tatsuo Ishii Date: Mon, 25 Mar 2024 16:15:50 +0900 Subject: [PATCH] Fix compile errors with certain CFLAGS. 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 | 2 +- src/include/utils/fe_ports.h | 18 +++++++++--------- src/include/utils/palloc.h | 4 ++-- src/tools/fe_memutils.c | 14 +++++++------- src/tools/fe_port.c | 7 +++---- 5 files changed, 22 insertions(+), 23 deletions(-) diff --git a/src/include/utils/elog.h b/src/include/utils/elog.h index c831662b1..92eb298fa 100644 --- a/src/include/utils/elog.h +++ b/src/include/utils/elog.h @@ -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 * diff --git a/src/include/utils/fe_ports.h b/src/include/utils/fe_ports.h index eff29a9fb..1eb6797ea 100644 --- a/src/include/utils/fe_ports.h +++ b/src/include/utils/fe_ports.h @@ -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 @@ -39,17 +39,17 @@ 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); \ diff --git a/src/include/utils/palloc.h b/src/include/utils/palloc.h index 2ed586ed0..bf6cdb2ef 100644 --- a/src/include/utils/palloc.h +++ b/src/include/utils/palloc.h @@ -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. diff --git a/src/tools/fe_memutils.c b/src/tools/fe_memutils.c index 0f6ccb314..0938f1755 100644 --- a/src/tools/fe_memutils.c +++ b/src/tools/fe_memutils.c @@ -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); } diff --git a/src/tools/fe_port.c b/src/tools/fe_port.c index 881cd1dbe..3704c2730 100644 --- a/src/tools/fe_port.c +++ b/src/tools/fe_port.c @@ -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;