[PATCH] fix compilation with gnu89

Started by Rosen Penevover 5 years ago4 messageshackers
Jump to latest
#1Rosen Penev
rosenp@gmail.com

GCC 4.8.5 does not default to gnu99 or gnu11 like the newer versions.
---
src/common/logging.c | 3 ++-
src/common/unicode_norm.c | 3 ++-
2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/common/logging.c b/src/common/logging.c
index f3fc0b8..2ac502a 100644
--- a/src/common/logging.c
+++ b/src/common/logging.c
@@ -112,7 +112,8 @@ pg_logging_init(const char *argv0)
 			if (colors)
 			{
-				for (char *token = strtok(colors, ":"); token; token = strtok(NULL, ":"))
+				char *token;
+				for (token = strtok(colors, ":"); token; token = strtok(NULL, ":"))
 				{
 					char	   *e = strchr(token, '=');
diff --git a/src/common/unicode_norm.c b/src/common/unicode_norm.c
index ab5ce59..0de2e87 100644
--- a/src/common/unicode_norm.c
+++ b/src/common/unicode_norm.c
@@ -519,6 +519,7 @@ unicode_is_normalized_quickcheck(UnicodeNormalizationForm form, const pg_wchar *
 {
 	uint8		lastCanonicalClass = 0;
 	UnicodeNormalizationQC result = UNICODE_NORM_QC_YES;
+	const pg_wchar *p;

/*
* For the "D" forms, we don't run the quickcheck. We don't include the
@@ -530,7 +531,7 @@ unicode_is_normalized_quickcheck(UnicodeNormalizationForm form, const pg_wchar *
if (form == UNICODE_NFD || form == UNICODE_NFKD)
return UNICODE_NORM_QC_MAYBE;

-	for (const pg_wchar *p = input; *p; p++)
+	for (p = input; *p; p++)
 	{
 		pg_wchar	ch = *p;
 		uint8		canonicalClass;
-- 
1.8.3.1
#2Andres Freund
andres@anarazel.de
In reply to: Rosen Penev (#1)
Re: [PATCH] fix compilation with gnu89

Hi,

On 2020-11-29 20:33:41 -0800, Rosen Penev wrote:

GCC 4.8.5 does not default to gnu99 or gnu11 like the newer versions.

We require C99 support since postgres 12, and configure should end up
choosing flags to make the compiler support that if possible.

As far as I can tell the code you changed doesn't actually exist in <=
11, so I don't see what problem it'd fix. And for newer branches you'd
obviously need a lot more changes than just this...

Regards,

Andres

#3Tom Lane
tgl@sss.pgh.pa.us
In reply to: Rosen Penev (#1)
Re: [PATCH] fix compilation with gnu89

Rosen Penev <rosenp@gmail.com> writes:

GCC 4.8.5 does not default to gnu99 or gnu11 like the newer versions.

Project policy now is to require C99 support, so the correct solution
for using an older compiler is to do something like

./configure CC="gcc -std=gnu99" ...

We're not going to accept patches to remove declarations-in-for-loops,
as that feature was actually one of the primary arguments for requiring
C99 in the first place. (Also, I'm pretty sure that there are already
considerably more than two such uses.)

regards, tom lane

#4Tom Lane
tgl@sss.pgh.pa.us
In reply to: Andres Freund (#2)
Re: [PATCH] fix compilation with gnu89

Andres Freund <andres@anarazel.de> writes:

On 2020-11-29 20:33:41 -0800, Rosen Penev wrote:

GCC 4.8.5 does not default to gnu99 or gnu11 like the newer versions.

We require C99 support since postgres 12, and configure should end up
choosing flags to make the compiler support that if possible.

Hmm, yeah, that's a good point ... why didn't configure select
"-std=gnu99" for you? This might boil down to trying to use
CFLAGS selected for one compiler with a different compiler.

regards, tom lane