Skip to content

Commit

Permalink
Fix compile errors with certain CFLAGS.
Browse files Browse the repository at this point in the history
#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
  • Loading branch information
tatsuo-ishii committed Mar 25, 2024
1 parent 38ee4ae commit f3dd0c1
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/include/utils/elog.h
Expand Up @@ -4,7 +4,7 @@
* POSTGRES error reporting/logging definitions.
*
*
* Portions Copyright (c) 2003-2014, 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
*
Expand Down
18 changes: 9 additions & 9 deletions src/include/utils/fe_ports.h
Expand Up @@ -5,7 +5,7 @@
* pgpool: a language independent connection pool server for PostgreSQL
* written by Tatsuo Ishii
*
* Copyright (c) 2003-2014 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
Expand Down Expand Up @@ -38,17 +38,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
Expand All @@ -68,8 +68,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,...);

/*
Expand Down Expand Up @@ -130,7 +130,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); \
Expand Down
4 changes: 2 additions & 2 deletions src/include/utils/palloc.h
Expand Up @@ -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
Expand Down Expand Up @@ -58,7 +58,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.
Expand Down
14 changes: 7 additions & 7 deletions src/tools/fe_memutils.c
Expand Up @@ -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
*
*
Expand All @@ -23,7 +23,7 @@
#include "utils/fe_ports.h"

void *
pg_malloc(size_t size)
pg_malloc(Size size)
{
void *tmp;

Expand All @@ -40,7 +40,7 @@ pg_malloc(size_t size)
}

void *
pg_malloc0(size_t size)
pg_malloc0(Size size)
{
void *tmp;

Expand All @@ -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;

Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
}
7 changes: 3 additions & 4 deletions src/tools/fe_port.c
Expand Up @@ -2,7 +2,7 @@
* pgpool: a language independent connection pool server for PostgreSQL
* written by Tatsuo Ishii
*
* Copyright (c) 2003-2014 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
Expand Down Expand Up @@ -160,9 +160,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;

Expand Down

0 comments on commit f3dd0c1

Please sign in to comment.